diff options
-rw-r--r-- | drumgizmo/audiooutputenginedl.cc | 12 | ||||
-rw-r--r-- | drumgizmo/audiooutputenginedl.h | 4 | ||||
-rw-r--r-- | drumgizmo/input/jackmidi/jackmidi.cc | 2 | ||||
-rw-r--r-- | drumgizmo/output/jackaudio/jackaudio.cc | 31 | ||||
-rw-r--r-- | src/audiooutputengine.h | 5 | ||||
-rw-r--r-- | src/drumgizmo.cc | 10 |
6 files changed, 47 insertions, 17 deletions
diff --git a/drumgizmo/audiooutputenginedl.cc b/drumgizmo/audiooutputenginedl.cc index ad8d815..513d21b 100644 --- a/drumgizmo/audiooutputenginedl.cc +++ b/drumgizmo/audiooutputenginedl.cc @@ -105,6 +105,12 @@ AudioOutputEngineDL::AudioOutputEngineDL(std::string name) return; } + o_bufsize = (output_bufsize_func_t) dlsym(lib, "bufsize"); + dlsym_error = dlerror(); + if(dlsym_error) { + o_bufsize = NULL; + } + ptr = o_create(); if(is_jack_plugin) { @@ -169,6 +175,12 @@ void AudioOutputEngineDL::post(size_t size) return o_post(ptr, size); } +size_t AudioOutputEngineDL::getBufferSize() +{ + if(o_bufsize) return o_bufsize(ptr); + return 1024; +} + #ifdef TEST_AUDIOOUTPUTENGINEDL //Additional dependency files //deps: diff --git a/drumgizmo/audiooutputenginedl.h b/drumgizmo/audiooutputenginedl.h index 4b22131..471247e 100644 --- a/drumgizmo/audiooutputenginedl.h +++ b/drumgizmo/audiooutputenginedl.h @@ -45,6 +45,7 @@ typedef void (*output_setparm_func_t)(void*,const char*,const char*); typedef void (*output_pre_func_t)(void*, size_t); typedef void (*output_run_func_t)(void*,int,sample_t*,size_t); typedef void (*output_post_func_t)(void*, size_t); +typedef size_t (*output_bufsize_func_t)(void*); class AudioOutputEngineDL : public AudioOutputEngine { public: @@ -62,6 +63,8 @@ public: void run(int ch, sample_t *samples, size_t nsamples); void post(size_t nsamples); + size_t getBufferSize(); + private: void *ptr; output_create_func_t o_create; @@ -73,6 +76,7 @@ private: output_pre_func_t o_pre; output_run_func_t o_run; output_post_func_t o_post; + output_bufsize_func_t o_bufsize; bool is_jack_plugin; JackClient *jackclient; diff --git a/drumgizmo/input/jackmidi/jackmidi.cc b/drumgizmo/input/jackmidi/jackmidi.cc index 89db418..5496195 100644 --- a/drumgizmo/input/jackmidi/jackmidi.cc +++ b/drumgizmo/input/jackmidi/jackmidi.cc @@ -137,7 +137,7 @@ event_t *JackMidi::run(size_t pos, size_t len, size_t *nevents) void JackMidi::jack_process(jack_nframes_t nframes) { - printf("i"); fflush(stdout); + // printf("i"); fflush(stdout); void *midibuffer = jack_port_get_buffer(midi_port, nframes); diff --git a/drumgizmo/output/jackaudio/jackaudio.cc b/drumgizmo/output/jackaudio/jackaudio.cc index 0fd985e..150c114 100644 --- a/drumgizmo/output/jackaudio/jackaudio.cc +++ b/drumgizmo/output/jackaudio/jackaudio.cc @@ -53,6 +53,8 @@ public: void jack_process(jack_nframes_t nframes); + size_t bufsize(); + private: JackClient *jackclient; jack_port_t *output_port[64]; @@ -61,7 +63,7 @@ private: Semaphore sem; }; -JackAudio::JackAudio() +JackAudio::JackAudio() : sem("jackaudio") { } @@ -85,7 +87,7 @@ bool JackAudio::init(int nchannels, char *cnames[]) name.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - channels[i] = (sample_t*)malloc(16 * sizeof(sample_t)); + channels[i] = (sample_t*)malloc(bufsize() * sizeof(sample_t)); } return true; } @@ -113,7 +115,7 @@ void JackAudio::pre(size_t size) } void JackAudio::run(int channel, sample_t* data, size_t size) -{ +{ // Copy engine data to ringbuffer. for(size_t i = 0; i < size; i++) { channels[channel][i] = data[i]; @@ -122,18 +124,12 @@ void JackAudio::run(int channel, sample_t* data, size_t size) void JackAudio::post(size_t size) { - sem.wait(); + //sem.wait(); } void JackAudio::jack_process(jack_nframes_t nframes) { - if(nframes != 128) { - fprintf(stderr, "jackaudio output module currently only works with a" - " buffersize of 64 samples!\n"); - exit(1); - } - - printf("o"); fflush(stdout); + //printf("o"); fflush(stdout); for(size_t c = 0; c < nchannels; c++) { jack_default_audio_sample_t *out = (jack_default_audio_sample_t *) jack_port_get_buffer(output_port[c], @@ -142,7 +138,12 @@ void JackAudio::jack_process(jack_nframes_t nframes) out[i] = channels[c][i]; } } - sem.post(); + // sem.post(); +} + +size_t JackAudio::bufsize() +{ + return jack_get_buffer_size(jackclient->jack_client); } extern "C" { @@ -198,6 +199,12 @@ extern "C" { JackAudio *jack = (JackAudio*)h; jack->post(s); } + + size_t bufsize(void *h) + { + JackAudio *jack = (JackAudio*)h; + return jack->bufsize(); + } } #ifdef TEST_AUDIOINPUTENGINEJACKAUDIO diff --git a/src/audiooutputengine.h b/src/audiooutputengine.h index 8b2b768..7f15e49 100644 --- a/src/audiooutputengine.h +++ b/src/audiooutputengine.h @@ -50,6 +50,11 @@ public: // Reimplement this if you wish to use internal buffer directly. virtual sample_t *getBuffer(int ch) { return NULL; } + + /* + * Overload this method to force engine to use different buffer size. + */ + virtual size_t getBufferSize() { return 1024; } }; #endif/*__DRUMGIZMO_AUDIOOUTPUTENGINE_H__*/ diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 4bd6a77..5d67c86 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -284,13 +284,13 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) void DrumGizmo::run(int endpos) { + size_t pos = 0; + size_t nsamples = oe->getBufferSize(); + sample_t *samples = (sample_t *)malloc(nsamples * sizeof(sample_t)); + ie->start(); oe->start(); - size_t pos = 0; - size_t nsamples = 128;//1024; - sample_t samples[nsamples]; - while(run(pos, samples, nsamples) == true) { pos += nsamples; if(endpos != -1 && pos >= (size_t)endpos) break; @@ -298,6 +298,8 @@ void DrumGizmo::run(int endpos) ie->stop(); oe->stop(); + + free(samples); } #ifdef SSE |