Loopp/src/jack.cxx

111 lines
2.5 KiB
C++
Raw Normal View History

2013-04-20 12:37:36 +02:00
#include "jack.hxx"
#include <sstream>
#include <cstring>
#include <iostream>
2013-04-20 12:54:16 +02:00
#include "eventhandler.hxx"
2013-04-20 12:37:36 +02:00
using namespace std;
extern int jackSamplerate;
Jack::Jack()
{
// open the client
client = jack_client_open ( "Luppp", JackNullOption , 0 , 0 );
nframes = jack_get_buffer_size( client );
samplerate = jack_get_sample_rate( client );
masterOutput = jack_port_register( client,
"master_out",
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsOutput,
0 );
masterInput = jack_port_register( client,
"master_in",
JACK_DEFAULT_AUDIO_TYPE,
JackPortIsInput,
0 );
if ( jack_set_process_callback( client,
static_process,
static_cast<void*>(this)) )
{
cerr << "Jack() error setting process callback" << endl;
}
loopers.push_back( new Looper() );
2013-04-20 12:37:36 +02:00
}
void Jack::activate()
{
jack_activate( client );
}
int Jack::process (jack_nframes_t nframes)
{
2013-04-20 12:54:16 +02:00
// do events from the ringbuffer
handleDspEvents();
2013-04-20 12:37:36 +02:00
// get buffers
buffers.audio[Buffers::MASTER_INPUT] = (float*)jack_port_get_buffer( masterInput , nframes);
buffers.audio[Buffers::MASTER_OUTPUT] = (float*)jack_port_get_buffer( masterOutput, nframes);
// pre-zero output buffers
memset( buffers.audio[Buffers::MASTER_OUTPUT], 0, sizeof(float) * nframes );
loopers.at(0)->process(nframes, &buffers );
/*
2013-04-20 12:37:36 +02:00
float* input = buffers.audio[Buffers::MASTER_INPUT];
float* output = buffers.audio[Buffers::MASTER_OUTPUT];
for(uint i = 0; i < nframes; i++)
{
2013-04-20 12:50:30 +02:00
*output++ = *input++;
2013-04-20 12:37:36 +02:00
}
*/
2013-04-20 12:37:36 +02:00
return false;
}
int Jack::getBuffersize()
{
return jack_get_buffer_size( client );
}
int Jack::getSamplerate()
{
return jack_get_sample_rate( client );
}
int Jack::timebase(jack_transport_state_t,
jack_nframes_t,
jack_position_t*,
int)
{
return 0;
}
int Jack::static_process(jack_nframes_t nframes, void *instance)
{
return static_cast<Jack*>(instance)->process(nframes);
}
int Jack::static_timebase(jack_transport_state_t state,
jack_nframes_t nframes,
jack_position_t* pos,
int newPos,
void* instance)
{
return static_cast<Jack*>(instance)->timebase(state,nframes, pos, newPos );
}