2016-10-03 19:43:13 +02:00
|
|
|
#include "jacksendreturn.hxx"
|
|
|
|
#include "jack.hxx"
|
2016-11-17 20:15:47 +01:00
|
|
|
#include <math.h>
|
|
|
|
#include <assert.h>
|
2016-10-03 19:43:13 +02:00
|
|
|
extern Jack* jack;
|
|
|
|
JackSendReturn::JackSendReturn(int trackid, AudioProcessor *prev, jack_client_t *client)
|
2016-12-27 13:47:19 +01:00
|
|
|
:m_trackid(trackid), m_previousProcessor(prev), m_sendvol(1.0f)
|
2016-10-03 19:43:13 +02:00
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
char name[50];
|
|
|
|
sprintf(name, "Send_track_%d\n",trackid);
|
|
|
|
m_sendport=jack_port_register(client,name,JACK_DEFAULT_AUDIO_TYPE,JackPortIsOutput,0);
|
|
|
|
sprintf(name, "Return_track_%d\n",trackid);
|
|
|
|
m_returnport=jack_port_register(client,name,JACK_DEFAULT_AUDIO_TYPE,JackPortIsInput,0);
|
|
|
|
m_active=false;
|
|
|
|
m_counter=0;
|
2016-10-03 19:43:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void JackSendReturn::process(unsigned int nframes, Buffers *buffers)
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
//Reset send buffer
|
|
|
|
int offset=m_counter%(buffers->nframes);
|
|
|
|
float* sendtrack=&(buffers->audio[Buffers::SEND_TRACK_0+m_trackid][0]);
|
2016-11-17 20:15:47 +01:00
|
|
|
|
|
|
|
|
2016-12-27 13:47:19 +01:00
|
|
|
float* rettrack=&(buffers->audio[Buffers::RETURN_TRACK_0+m_trackid][0]);
|
2016-11-17 20:15:47 +01:00
|
|
|
|
2016-12-27 13:47:19 +01:00
|
|
|
memset(sendtrack,0,nframes*sizeof(float));
|
2016-10-03 19:43:13 +02:00
|
|
|
|
2016-12-27 13:47:19 +01:00
|
|
|
//Process previous AudioProcessor
|
|
|
|
m_previousProcessor->process(nframes,buffers);
|
|
|
|
float* send=(float*)jack_port_get_buffer(m_sendport,(jack_nframes_t)(buffers->nframes));
|
|
|
|
float* ret=(float*)jack_port_get_buffer(m_returnport,(jack_nframes_t)(buffers->nframes));
|
|
|
|
if(offset) {
|
|
|
|
send+=offset;
|
|
|
|
ret+=offset;
|
|
|
|
}
|
2016-10-03 19:43:13 +02:00
|
|
|
|
2016-12-27 13:47:19 +01:00
|
|
|
for(int i=0; i<nframes; i++)
|
|
|
|
send[i]=m_sendvol*sendtrack[i];
|
2016-11-17 20:15:47 +01:00
|
|
|
// if(nframes!=buffers->nframes)
|
|
|
|
// {
|
|
|
|
// cout<<send<<endl;
|
|
|
|
// }
|
2016-11-15 18:11:28 +01:00
|
|
|
|
2016-12-27 13:47:19 +01:00
|
|
|
if(offset)
|
|
|
|
assert(offset+nframes==buffers->nframes);
|
2016-11-15 18:11:28 +01:00
|
|
|
|
2016-12-27 13:47:19 +01:00
|
|
|
if(m_active)
|
|
|
|
memcpy(rettrack,ret,nframes*sizeof(float));
|
|
|
|
else
|
|
|
|
memcpy(rettrack,
|
|
|
|
sendtrack,nframes*sizeof(float));
|
|
|
|
m_counter+=nframes;
|
2016-10-03 19:43:13 +02:00
|
|
|
|
|
|
|
}
|
2016-11-15 18:11:28 +01:00
|
|
|
|
|
|
|
void JackSendReturn::activate(bool act)
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
m_active=act;
|
2016-11-15 18:11:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void JackSendReturn::sendVolume(float vol)
|
|
|
|
{
|
2016-12-27 13:47:19 +01:00
|
|
|
m_sendvol=vol;
|
2016-11-15 18:11:28 +01:00
|
|
|
}
|