-Master bus now stereo

This commit is contained in:
Harry van Haaren 2013-07-31 11:34:28 +01:00
parent e472b4fcd4
commit 71677bad30
9 changed files with 115 additions and 37 deletions

View file

@ -24,29 +24,31 @@ class Buffers
enum BUFFER { enum BUFFER {
// AUDIO // AUDIO
MASTER_INPUT = 0, MASTER_INPUT = 0,
MASTER_OUTPUT = 1, MASTER_OUT_L = 1,
JACK_MASTER_OUTPUT = 2, MASTER_OUT_R = 2,
JACK_MASTER_OUT_L = 3,
JACK_MASTER_OUT_R = 4,
REVERB = 3, REVERB = 5,
SIDECHAIN = 4, SIDECHAIN = 6,
POST_SIDECHAIN = 5, POST_SIDECHAIN = 7,
// MIDI // MIDI
MASTER_MIDI_INPUT = 6, MASTER_MIDI_INPUT = 8,
APC_INPUT = 7, APC_INPUT = 9,
APC_OUTPUT = 8, APC_OUTPUT = 10,
// track buffers: they are the "working" buffers per track: // track buffers: they are the "working" buffers per track:
// the end result is mixed into the master output, while each // the end result is mixed into the master output, while each
// stage along the way the amplitude etc can be analysed // stage along the way the amplitude etc can be analysed
TRACK_0 = 9, TRACK_0 = 11,
TRACK_1 = 10, TRACK_1 = 12,
TRACK_2 = 11, TRACK_2 = 13,
TRACK_3 = 12, TRACK_3 = 14,
TRACK_4 = 13, TRACK_4 = 15,
TRACK_5 = 14, TRACK_5 = 16,
TRACK_6 = 15, TRACK_6 = 17,
TRACK_7 = 16, TRACK_7 = 18,
}; };
// Jack details // Jack details

View file

@ -24,6 +24,16 @@ class Reverb // : Effect
int getNumInputs() { return 2; } int getNumInputs() { return 2; }
int getNumOutputs(){ return 2; } int getNumOutputs(){ return 2; }
void setActive(bool a)
{
active = a;
}
bool getActive()
{
return active;
}
/// set HF damping, 0-1 /// set HF damping, 0-1
void damping(float d) void damping(float d)
{ {
@ -44,6 +54,9 @@ class Reverb // : Effect
void process(int count, float** input, float** output) void process(int count, float** input, float** output)
{ {
if ( !active )
return;
float fSlow0 = fslider0; float fSlow0 = fslider0;
float fSlow1 = expf((fConst2 / fSlow0)); float fSlow1 = expf((fConst2 / fSlow0));
float fSlow2 = faustpower<2>(fSlow1); float fSlow2 = faustpower<2>(fSlow1);
@ -237,6 +250,7 @@ class Reverb // : Effect
} }
private: private:
bool active;
float fslider0; float fslider0;
int iConst0; int iConst0;
float fConst1; float fConst1;
@ -338,6 +352,7 @@ class Reverb // : Effect
/// Long nasty function setting initial values /// Long nasty function setting initial values
void init(int samplingFreq) void init(int samplingFreq)
{ {
active = 0;
fslider0 = 3.0f; fslider0 = 3.0f;
iConst0 = min(192000, max(1, samplingFreq)); iConst0 = min(192000, max(1, samplingFreq));
fConst1 = floorf((0.5f + (0.174713f * iConst0))); fConst1 = floorf((0.5f + (0.174713f * iConst0)));

View file

@ -26,11 +26,12 @@ namespace Event
MASTER_VOL, MASTER_VOL,
RECORD, RECORD,
TRACK_SEND, TRACK_SEND,
TRACK_SIGNAL_LEVEL, TRACK_SIGNAL_LEVEL,
TRACK_VOLUME, TRACK_VOLUME,
FX_REVERB,
LOOPER_LOAD, LOOPER_LOAD,
LOOPER_STATE, LOOPER_STATE,
LOOPER_PROGRESS, LOOPER_PROGRESS,
@ -89,6 +90,21 @@ class EventTrackVol : public EventBase
} }
}; };
class EventFxReverb : public EventBase
{
public:
int type() { return int(FX_REVERB); }
uint32_t size() { return sizeof(EventFxReverb); }
int track;
bool enable;
float damping;
float rtSize;
EventFxReverb(){};
EventFxReverb(int t, bool e, float d, float s): track(t), enable(e), damping(d), rtSize(s) {}
};
class EventTrackSend : public EventBase class EventTrackSend : public EventBase
{ {
public: public:

View file

@ -76,6 +76,15 @@ void handleDspEvents()
jack->getTimeManager()->tap(); jack->getTimeManager()->tap();
} break; } } break; }
// ======== FX ===========
case Event::FX_REVERB: {
if ( availableRead >= sizeof(EventFxReverb) ) {
EventFxReverb ev;
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventFxReverb) );
jack->setReverb( ev.enable, ev.damping, ev.rtSize );
break; }
}
case Event::TRACK_VOLUME: { case Event::TRACK_VOLUME: {
if ( availableRead >= sizeof(EventTrackVol) ) { if ( availableRead >= sizeof(EventTrackVol) ) {
EventTrackVol ev; EventTrackVol ev;

View file

@ -22,6 +22,14 @@
using namespace std; using namespace std;
static void gmastertrack_reverb_cb(Fl_Widget *w, void *data)
{
int enable = ((Avtk::Reverb*)w)->getActive();
printf("reverb enable %i\n",enable);
EventFxReverb e = EventFxReverb( -1, enable, 0.5, 0.5 );
writeToDspRingbuffer( &e );
}
static void gmastertrack_button_callback(Fl_Widget *w, void *data) { static void gmastertrack_button_callback(Fl_Widget *w, void *data) {
if ( strcmp( w->label(), "Metro" ) == 0 ) if ( strcmp( w->label(), "Metro" ) == 0 )
{ {
@ -79,6 +87,8 @@ class GMasterTrack : public Fl_Group
tapTempo.callback( gmastertrack_button_callback, &ID ); tapTempo.callback( gmastertrack_button_callback, &ID );
metronomeButton.callback( gmastertrack_button_callback, 0 ); metronomeButton.callback( gmastertrack_button_callback, 0 );
reverb.callback( gmastertrack_reverb_cb, 0 );
tapTempo.setBgColor( 0, 0, 0 ); tapTempo.setBgColor( 0, 0, 0 );
//metronomeButton.setBgColor( 0, 0, 0 ); //metronomeButton.setBgColor( 0, 0, 0 );
metronomeButton.setColor( 0.4, 0.4, 0.4 ); metronomeButton.setColor( 0.4, 0.4, 0.4 );

View file

@ -22,8 +22,13 @@ Jack::Jack()
uiUpdateCounter = buffers.samplerate / 30; uiUpdateCounter = buffers.samplerate / 30;
uiUpdateConstant = buffers.samplerate / 30; uiUpdateConstant = buffers.samplerate / 30;
masterOutput = jack_port_register( client, masterOutputL = jack_port_register( client,
"master_out", "master_left",
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsOutput,
0 );
masterOutputR = jack_port_register( client,
"master_right",
JACK_DEFAULT_AUDIO_TYPE, JACK_DEFAULT_AUDIO_TYPE,
JackPortIsOutput, JackPortIsOutput,
0 ); 0 );
@ -57,7 +62,8 @@ Jack::Jack()
buffers.audio[Buffers::REVERB] = new float( nframes ); buffers.audio[Buffers::REVERB] = new float( nframes );
buffers.audio[Buffers::SIDECHAIN] = new float( nframes ); buffers.audio[Buffers::SIDECHAIN] = new float( nframes );
buffers.audio[Buffers::POST_SIDECHAIN] = new float( nframes ); buffers.audio[Buffers::POST_SIDECHAIN] = new float( nframes );
buffers.audio[Buffers::MASTER_OUTPUT] = new float( nframes ); buffers.audio[Buffers::MASTER_OUT_L] = new float( nframes );
buffers.audio[Buffers::MASTER_OUT_R] = new float( nframes );
for(int i = 0; i < NTRACKS; i++) for(int i = 0; i < NTRACKS; i++)
{ {
@ -103,7 +109,8 @@ int Jack::process (jack_nframes_t nframes)
{ {
// get buffers // get buffers
buffers.audio[Buffers::MASTER_INPUT] = (float*)jack_port_get_buffer( masterInput , nframes ); buffers.audio[Buffers::MASTER_INPUT] = (float*)jack_port_get_buffer( masterInput , nframes );
buffers.audio[Buffers::JACK_MASTER_OUTPUT] = (float*)jack_port_get_buffer( masterOutput , nframes ); buffers.audio[Buffers::JACK_MASTER_OUT_L] = (float*)jack_port_get_buffer( masterOutputL , nframes );
buffers.audio[Buffers::JACK_MASTER_OUT_R] = (float*)jack_port_get_buffer( masterOutputR , nframes );
buffers.midi [Buffers::MASTER_MIDI_INPUT] = (void*) jack_port_get_buffer( masterMidiInput, nframes ); buffers.midi [Buffers::MASTER_MIDI_INPUT] = (void*) jack_port_get_buffer( masterMidiInput, nframes );
buffers.midi [Buffers::APC_INPUT] = (void*) jack_port_get_buffer( apcMidiInput , nframes ); buffers.midi [Buffers::APC_INPUT] = (void*) jack_port_get_buffer( apcMidiInput , nframes );
buffers.midi [Buffers::APC_OUTPUT] = (void*) jack_port_get_buffer( apcMidiOutput , nframes ); buffers.midi [Buffers::APC_OUTPUT] = (void*) jack_port_get_buffer( apcMidiOutput , nframes );
@ -111,7 +118,8 @@ int Jack::process (jack_nframes_t nframes)
// pre-zero output buffers // pre-zero output buffers
for(uint i = 0; i < nframes; i++) for(uint i = 0; i < nframes; i++)
{ {
buffers.audio[Buffers::MASTER_OUTPUT] [i] = 0.f; buffers.audio[Buffers::MASTER_OUT_L] [i] = 0.f;
buffers.audio[Buffers::MASTER_OUT_R] [i] = 0.f;
buffers.audio[Buffers::REVERB] [i] = 0.f; buffers.audio[Buffers::REVERB] [i] = 0.f;
buffers.audio[Buffers::SIDECHAIN] [i] = 0.f; buffers.audio[Buffers::SIDECHAIN] [i] = 0.f;
buffers.audio[Buffers::POST_SIDECHAIN] [i] = 0.f; buffers.audio[Buffers::POST_SIDECHAIN] [i] = 0.f;
@ -170,17 +178,18 @@ int Jack::process (jack_nframes_t nframes)
buffers.audio[Buffers::REVERB], buffers.audio[Buffers::REVERB],
}; };
if ( reverb->getActive() )
reverbMeter->process(nframes, buffers.audio[Buffers::REVERB], buffers.audio[Buffers::REVERB] ); {
reverb->process( nframes, &buf[0], &buf[2] ); reverbMeter->process(nframes, buffers.audio[Buffers::REVERB], buffers.audio[Buffers::REVERB] );
reverb->process( nframes, &buf[0], &buf[2] );
}
// db meter on master output, then memcpy to JACK // db meter on master output, then memcpy to JACK
masterMeter->process(nframes, buffers.audio[Buffers::MASTER_OUTPUT], buffers.audio[Buffers::MASTER_OUTPUT] ); masterMeter->process(nframes, buffers.audio[Buffers::MASTER_OUT_L], buffers.audio[Buffers::MASTER_OUT_R] );
if ( uiUpdateCounter > uiUpdateConstant ) if ( uiUpdateCounter > uiUpdateConstant )
{ {
float peak = masterMeter->getLeftDB(); EventTrackSignalLevel e(-1, masterMeter->getLeftDB(), masterMeter->getRightDB() );
EventTrackSignalLevel e(-1, peak, masterMeter->getRightDB() );
writeToGuiRingbuffer( &e ); writeToGuiRingbuffer( &e );
/* /*
@ -197,14 +206,25 @@ int Jack::process (jack_nframes_t nframes)
// memcpy the internal MASTER_OUTPUT buffer to the JACK_MASTER_OUTPUT // memcpy the internal MASTER_OUTPUT buffer to the JACK_MASTER_OUTPUT
memcpy( buffers.audio[Buffers::JACK_MASTER_OUTPUT], memcpy( buffers.audio[Buffers::JACK_MASTER_OUT_L],
buffers.audio[Buffers::MASTER_OUTPUT], buffers.audio[Buffers::MASTER_OUT_L],
sizeof(float)*nframes);
memcpy( buffers.audio[Buffers::JACK_MASTER_OUT_R],
buffers.audio[Buffers::MASTER_OUT_R],
//buffers.audio[Buffers::REVERB], // uncomment to listen to reverb send only //buffers.audio[Buffers::REVERB], // uncomment to listen to reverb send only
sizeof(float)*nframes); sizeof(float)*nframes);
return false; return false;
} }
void Jack::setReverb( bool a, float d, float s )
{
reverb->setActive( a );
reverb->damping( d );
reverb->rt60( d );
}
int Jack::getBuffersize() int Jack::getBuffersize()
{ {
return jack_get_buffer_size( client ); return jack_get_buffer_size( client );

View file

@ -59,6 +59,8 @@ class Jack
return trackOutputs.at(t); return trackOutputs.at(t);
} }
void setReverb( bool e, float d, float s );
Metronome* getMetronome(){return &metronome;} Metronome* getMetronome(){return &metronome;}
TimeManager* getTimeManager(){return &timeManager;} TimeManager* getTimeManager(){return &timeManager;}
ControllerUpdater* getControllerUpdater(){return &controllerUpdater;} ControllerUpdater* getControllerUpdater(){return &controllerUpdater;}
@ -88,7 +90,8 @@ class Jack
jack_client_t* client; jack_client_t* client;
jack_port_t* masterInput; jack_port_t* masterInput;
jack_port_t* masterOutput; jack_port_t* masterOutputL;
jack_port_t* masterOutputR;
jack_port_t* apcMidiInput; jack_port_t* apcMidiInput;
jack_port_t* apcMidiOutput; jack_port_t* apcMidiOutput;

View file

@ -68,7 +68,7 @@ class Metronome : public TimeObserver
if ( not active ) if ( not active )
return; return;
float* out = buffers->audio[Buffers::MASTER_OUTPUT]; float* out = buffers->audio[Buffers::MASTER_OUT_L];
float* sample = &beatSample[0]; float* sample = &beatSample[0];
if( playBar ) { sample = &barSample[0]; playBar = false; } if( playBar ) { sample = &barSample[0]; playBar = false; }

View file

@ -86,15 +86,18 @@ class TrackOutput : public AudioProcessor
float* sidechain = buffers->audio[Buffers::SIDECHAIN]; float* sidechain = buffers->audio[Buffers::SIDECHAIN];
float* postSidechain = buffers->audio[Buffers::POST_SIDECHAIN]; float* postSidechain = buffers->audio[Buffers::POST_SIDECHAIN];
float* master = buffers->audio[Buffers::MASTER_OUTPUT]; float* master = buffers->audio[Buffers::MASTER_OUT_L];
for(int i = 0; i < nframes; i++) for(int i = 0; i < nframes; i++)
{ {
*reverb++ += *trackBuf * _toReverb; float tmp = *trackBuf;
//*sidechain++ += *trackBuf * _toSidechain;
//*postSidechain++ += *trackBuf * _toPostSidechain; *master++ += tmp * _toMaster;
*reverb++ += tmp * _toReverb;
//*sidechain++ += tmp * _toSidechain;
//*postSidechain++ += tmp * _toPostSidechain;
*master++ += *trackBuf * _toMaster;
trackBuf++; trackBuf++;
} }