From aa8599e808008a14ac0f7d40f91dc2e05bd3bd0a Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 12 Apr 2014 19:59:17 +0200 Subject: Make engine ask output module for buffer size. Use this new feature to adapt internal buffers to buffer size reported by jack. --- drumgizmo/audiooutputenginedl.cc | 12 ++++++++++++ drumgizmo/audiooutputenginedl.h | 4 ++++ drumgizmo/input/jackmidi/jackmidi.cc | 2 +- drumgizmo/output/jackaudio/jackaudio.cc | 31 +++++++++++++++++++------------ 4 files changed, 36 insertions(+), 13 deletions(-) (limited to 'drumgizmo') 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 -- cgit v1.2.3