Loopp/src/trackoutput.hxx

141 lines
3.3 KiB
C++
Raw Normal View History

#ifndef LUPPP_TRACK_OUTPUT_H
#define LUPPP_TRACK_OUTPUT_H
#include <stdio.h>
2013-08-06 22:55:57 +02:00
#include "config.hxx"
#include "audioprocessor.hxx"
2013-07-28 14:31:07 +02:00
#include "eventhandler.hxx"
#include "dsp/dsp_dbmeter.hxx"
class TrackOutput : public AudioProcessor
{
public:
TrackOutput(int t, AudioProcessor* ap) :
2013-07-31 02:28:18 +02:00
AudioProcessor(),
track(t),
2013-08-06 22:55:57 +02:00
_trackBuffer( MAX_BUFFER_SIZE, 0.f ),
2013-07-28 14:31:07 +02:00
previousInChain(ap),
dbMeter(44100)
{
printf("trackOutput ID: %i\n", track);
2013-08-06 22:55:57 +02:00
2013-07-28 14:31:07 +02:00
// UI update
uiUpdateConstant = 44100 / 30;
2013-07-28 14:31:07 +02:00
uiUpdateCounter = 44100 / 30;
_toReverb = 0.0;
_toMaster = 0.8;
_toSidechain = 0.0;
_toPostSidechain = 0.0;
2013-07-28 14:31:07 +02:00
}
/// set main mix, 0-1
void setMaster(float value)
{
_toMaster = value;
2013-07-28 14:31:07 +02:00
}
/// set send
void setSend( int send, float value )
2013-07-28 14:31:07 +02:00
{
switch( send )
{
case SEND_REV:
_toReverb = value;
break;
case SEND_SIDE:
_toSidechain = value;
break;
case SEND_POST:
_toPostSidechain = value;
break;
}
}
/// copies the track output to master buffer, sidechain & post-side buffer
void process(int nframes, Buffers* buffers)
{
// zero track buffer
2013-08-06 22:55:57 +02:00
memset( &_trackBuffer[0], 0, nframes );
if ( previousInChain )
{
2013-08-06 22:55:57 +02:00
buffers->audio[Buffers::TRACK_0 + track] = &_trackBuffer[0];
previousInChain->process( nframes, buffers );
}
// run the meter
float* buf = &_trackBuffer[0];
2013-07-28 14:31:07 +02:00
dbMeter.process( nframes, buf, buf );
if (uiUpdateCounter > uiUpdateConstant )
{
2013-08-06 22:55:57 +02:00
// FIXME: should be using ControllerUpdater
EventTrackSignalLevel e( track, dbMeter.getLeftDB() * _toMaster, dbMeter.getRightDB() * _toMaster );
writeToGuiRingbuffer( &e );
2013-07-28 14:31:07 +02:00
uiUpdateCounter = 0;
}
uiUpdateCounter += nframes;
/// copy audio data into reverb / sidechain / master buffers
float* trackBuf = buffers->audio[Buffers::TRACK_0 + track];
float* reverb = buffers->audio[Buffers::REVERB];
float* sidechain = buffers->audio[Buffers::SIDECHAIN];
float* postSidechain = buffers->audio[Buffers::POST_SIDECHAIN];
2013-08-06 22:55:57 +02:00
float* masterL = buffers->audio[Buffers::MASTER_OUT_L];
float* masterR = buffers->audio[Buffers::MASTER_OUT_R];
for(int i = 0; i < nframes; i++)
{
2013-08-06 22:55:57 +02:00
float tmp = _trackBuffer[i];
2013-07-31 12:34:28 +02:00
*masterL++ += tmp * _toMaster;
*masterR++ += tmp * _toMaster;
2013-07-31 12:34:28 +02:00
2013-08-06 22:55:57 +02:00
//*reverb++ += tmp * _toReverb;
2013-07-31 12:34:28 +02:00
//*sidechain++ += tmp * _toSidechain;
//*postSidechain++ += tmp * _toPostSidechain;
2013-07-28 14:31:07 +02:00
trackBuf++;
}
}
~TrackOutput()
{
}
private:
int track;
2013-08-06 22:55:57 +02:00
std::vector<float> _trackBuffer;
float _toMaster;
float _toReverb;
float _toSidechain;
float _toPostSidechain;
/// Pointer to "previous" processor: the graph is backwards
AudioProcessor* previousInChain;
2013-07-28 14:31:07 +02:00
// Metering variables
long uiUpdateCounter;
long uiUpdateConstant;
DBMeter dbMeter;
};
#endif // LUPPP_TRACK_OUTPUT_H