zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

commit d7ad608525dbfcfb3244eaa48e03529dfb048873
parent 2f092173e9576326afb7080d0c2a28426a9cf610
Author: fundamental <mark.d.mccurry@gmail.com>
Date:   Sun, 17 Nov 2019 11:51:45 -0500

Merge remote-tracking branch 'origin/master'

Diffstat:
Msrc/Nio/OssEngine.cpp | 9+++++++--
Msrc/Nio/OssMultiEngine.cpp | 5++++-
Msrc/Synth/OscilGen.cpp | 43+++++++++++++++++++++----------------------
Msrc/Synth/OscilGen.h | 8++++----
4 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/src/Nio/OssEngine.cpp b/src/Nio/OssEngine.cpp @@ -36,6 +36,8 @@ using namespace std; namespace zyn { +static const int OssNonBlocking = 0; + /* * The following statemachine converts MIDI commands to USB MIDI * packets, derived from Linux's usbmidi.c, which was written by @@ -216,12 +218,13 @@ bool OssEngine::openAudio() device = linux_oss_wave_out_dev; /* NOTE: PIPEs and FIFOs can block when opening them */ - audio.handle = open(device, O_WRONLY, O_NONBLOCK); + audio.handle = open(device, O_WRONLY | O_NONBLOCK); if(audio.handle == -1) { cerr << "ERROR - I can't open the " << device << '.' << endl; return false; } + ioctl(audio.handle, FIONBIO, &OssNonBlocking); ioctl(audio.handle, SNDCTL_DSP_RESET, NULL); /* Figure out the correct format first */ @@ -354,12 +357,14 @@ bool OssEngine::openMidi() device = linux_oss_seq_in_dev; /* NOTE: PIPEs and FIFOs can block when opening them */ - handle = open(device, O_RDONLY, O_NONBLOCK); + handle = open(device, O_RDONLY | O_NONBLOCK); if(-1 == handle) return false; midi.handle = handle; + ioctl(midi.handle, FIONBIO, &OssNonBlocking); + pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); diff --git a/src/Nio/OssMultiEngine.cpp b/src/Nio/OssMultiEngine.cpp @@ -37,6 +37,8 @@ extern zyn::MiddleWare *middleware; namespace zyn { +static const int OssNonBlocking = 0; + OssMultiEngine :: OssMultiEngine(const SYNTH_T &synth, const oss_devs_t &oss_devs) :AudioOut(synth), @@ -86,12 +88,13 @@ OssMultiEngine :: openAudio() device = linux_oss_wave_out_dev; /* NOTE: PIPEs and FIFOs can block when opening them */ - handle = open(device, O_WRONLY, O_NONBLOCK); + handle = open(device, O_WRONLY | O_NONBLOCK); if (handle == -1) { cerr << "ERROR - I can't open the " << device << '.' << endl; return (false); } + ioctl(handle, FIONBIO, &OssNonBlocking); ioctl(handle, SNDCTL_DSP_RESET, 0); /* Figure out the correct format first */ diff --git a/src/Synth/OscilGen.cpp b/src/Synth/OscilGen.cpp @@ -524,7 +524,7 @@ void OscilGen::getbasefunction(float *smps) break; } - base_func func = getBaseFunction(Pcurrentbasefunc); + base_func_t *func = getBaseFunction(Pcurrentbasefunc); for(int i = 0; i < synth.oscilsize; ++i) { float t = i * 1.0f / synth.oscilsize; @@ -566,7 +566,7 @@ void OscilGen::oscilfilter(fft_t *freqs) const float par = 1.0f - Pfilterpar1 / 128.0f; const float par2 = Pfilterpar2 / 127.0f; - filter_func filter = getFilter(Pfiltertype); + filter_func_t *filter = getFilter(Pfiltertype); for(int i = 1; i < synth.oscilsize / 2; ++i) freqs[i] *= filter(i, par, par2); @@ -1630,19 +1630,9 @@ FUNC(circle) return y; } -typedef float (*base_func)(float, float); - -base_func getBaseFunction(unsigned char func) +base_func_t *getBaseFunction(unsigned char func) { - if(!func) - return NULL; - - if(func == 127) //should be the custom wave - return NULL; - - func--; - assert(func < 15); - base_func functions[] = { + static const base_func_t *functions[] = { basefunc_triangle, basefunc_pulse, basefunc_saw, @@ -1659,6 +1649,15 @@ base_func getBaseFunction(unsigned char func) basefunc_spike, basefunc_circle, }; + + if(!func) + return NULL; + + if(func == 127) //should be the custom wave + return NULL; + + func--; + assert(func < (sizeof(functions)/sizeof(functions[0]))); return functions[func]; } @@ -1791,15 +1790,9 @@ FILTER(s) } #undef FILTER -typedef float (*filter_func)(unsigned int, float, float); -filter_func getFilter(unsigned char func) +filter_func_t *getFilter(unsigned char func) { - if(!func) - return NULL; - - func--; - assert(func < 13); - filter_func functions[] = { + static const filter_func_t *functions[] = { osc_lp, osc_hp1, osc_hp1b, @@ -1814,6 +1807,12 @@ filter_func getFilter(unsigned char func) osc_low_shelf, osc_s }; + + if(!func) + return NULL; + + func--; + assert(func < (sizeof(functions)/sizeof(functions[0]))); return functions[func]; } diff --git a/src/Synth/OscilGen.h b/src/Synth/OscilGen.h @@ -180,10 +180,10 @@ class OscilGen:public Presets const SYNTH_T &synth; }; -typedef float (*filter_func)(unsigned int, float, float); -filter_func getFilter(unsigned char func); -typedef float (*base_func)(float, float); -base_func getBaseFunction(unsigned char func); +typedef float filter_func_t(unsigned int, float, float); +filter_func_t *getFilter(unsigned char func); +typedef float base_func_t(float, float); +base_func_t *getBaseFunction(unsigned char func); }