From d2c9a44b870679f3c2660278424a309bb1917aca Mon Sep 17 00:00:00 2001 From: fundamental Date: Wed, 14 Sep 2011 16:19:03 -0400 Subject: [PATCH] Style: Restyling codebase - Style shall now be defined in style.cfg and inforced with uncrustify --- ExternalPrograms/Controller/Controller.h | 1 - ExternalPrograms/Spliter/Spliter.h | 1 - src/DSP/AnalogFilter.cpp | 393 ++++--- src/DSP/AnalogFilter.h | 19 +- src/DSP/FFTwrapper.cpp | 9 +- src/DSP/FFTwrapper.h | 7 +- src/DSP/Filter.cpp | 31 +- src/DSP/Filter.h | 3 +- src/DSP/FormantFilter.cpp | 29 +- src/DSP/FormantFilter.h | 5 +- src/DSP/SVFilter.cpp | 51 +- src/DSP/SVFilter.h | 5 +- src/DSP/Unison.cpp | 23 +- src/DSP/Unison.h | 19 +- src/Effects/Alienwah.cpp | 14 +- src/Effects/Alienwah.h | 1 - src/Effects/Chorus.cpp | 24 +- src/Effects/Chorus.h | 3 +- src/Effects/Distorsion.cpp | 35 +- src/Effects/Distorsion.h | 3 +- src/Effects/DynamicFilter.cpp | 171 ++- src/Effects/DynamicFilter.h | 3 +- src/Effects/EQ.cpp | 113 +- src/Effects/EQ.h | 1 - src/Effects/Echo.cpp | 50 +- src/Effects/Echo.h | 17 +- src/Effects/Effect.cpp | 6 +- src/Effects/Effect.h | 9 +- src/Effects/EffectLFO.cpp | 37 +- src/Effects/EffectLFO.h | 3 +- src/Effects/EffectMgr.cpp | 69 +- src/Effects/EffectMgr.h | 3 +- src/Effects/Phaser.cpp | 142 +-- src/Effects/Phaser.h | 11 +- src/Effects/Reverb.cpp | 49 +- src/Effects/Reverb.h | 21 +- src/Misc/Atomic.cpp | 2 +- src/Misc/Atomic.h | 1 - src/Misc/Bank.cpp | 40 +- src/Misc/Bank.h | 7 +- src/Misc/Config.cpp | 133 ++- src/Misc/Config.h | 7 +- src/Misc/Control.h | 1 - src/Misc/Dump.cpp | 13 +- src/Misc/Dump.h | 1 - src/Misc/LASHClient.cpp | 1 - src/Misc/LASHClient.h | 1 - src/Misc/Master.cpp | 83 +- src/Misc/Master.h | 23 +- src/Misc/Microtonal.cpp | 59 +- src/Misc/Microtonal.h | 1 - src/Misc/Part.cpp | 370 ++++--- src/Misc/Part.h | 13 +- src/Misc/Recorder.cpp | 11 +- src/Misc/Recorder.h | 1 - src/Misc/Stereo.cpp | 1 - src/Misc/Stereo.h | 4 +- src/Misc/Util.cpp | 75 +- src/Misc/Util.h | 41 +- src/Misc/WavFile.cpp | 15 +- src/Misc/WavFile.h | 1 - src/Misc/WaveShapeSmps.cpp | 288 ++--- src/Misc/XMLwrapper.cpp | 17 +- src/Misc/XMLwrapper.h | 7 +- src/Nio/AlsaEngine.cpp | 77 +- src/Nio/AlsaEngine.h | 24 +- src/Nio/AudioOut.cpp | 5 +- src/Nio/AudioOut.h | 7 +- src/Nio/Engine.cpp | 5 +- src/Nio/Engine.h | 4 +- src/Nio/EngineMgr.cpp | 72 +- src/Nio/EngineMgr.h | 1 - src/Nio/InMgr.cpp | 17 +- src/Nio/InMgr.h | 10 +- src/Nio/JackEngine.cpp | 136 +-- src/Nio/JackEngine.h | 22 +- src/Nio/MidiIn.cpp | 9 +- src/Nio/MidiIn.h | 11 +- src/Nio/Nio.cpp | 36 +- src/Nio/Nio.h | 11 +- src/Nio/NulEngine.cpp | 25 +- src/Nio/NulEngine.h | 9 +- src/Nio/OssEngine.cpp | 63 +- src/Nio/OssEngine.h | 9 +- src/Nio/OutMgr.cpp | 41 +- src/Nio/OutMgr.h | 11 +- src/Nio/PaEngine.cpp | 17 +- src/Nio/PaEngine.h | 13 +- src/Nio/SafeQueue.cpp | 12 +- src/Nio/SafeQueue.h | 2 +- src/Nio/WavEngine.cpp | 24 +- src/Nio/WavEngine.h | 9 +- src/Output/DSSIaudiooutput.cpp | 263 ++--- src/Output/DSSIaudiooutput.h | 158 +-- src/Params/ADnoteParameters.cpp | 133 +-- src/Params/ADnoteParameters.h | 25 +- src/Params/Controller.cpp | 116 ++- src/Params/Controller.h | 47 +- src/Params/EnvelopeParams.cpp | 110 +- src/Params/EnvelopeParams.h | 1 - src/Params/FilterParams.cpp | 69 +- src/Params/FilterParams.h | 3 +- src/Params/LFOParams.cpp | 27 +- src/Params/LFOParams.h | 3 +- src/Params/PADnoteParameters.cpp | 349 ++++--- src/Params/PADnoteParameters.h | 7 +- src/Params/Presets.cpp | 15 +- src/Params/Presets.h | 1 - src/Params/PresetsArray.cpp | 12 +- src/Params/PresetsArray.h | 5 +- src/Params/PresetsStore.cpp | 7 +- src/Params/PresetsStore.h | 3 +- src/Params/SUBnoteParameters.cpp | 31 +- src/Params/SUBnoteParameters.h | 1 - src/Samples/Sample.cpp | 29 +- src/Samples/Sample.h | 1 - src/Synth/ADnote.cpp | 548 +++++----- src/Synth/ADnote.h | 57 +- src/Synth/Envelope.cpp | 56 +- src/Synth/Envelope.h | 15 +- src/Synth/LFO.cpp | 83 +- src/Synth/LFO.h | 1 - src/Synth/OscilGen.cpp | 524 +++++----- src/Synth/OscilGen.h | 11 +- src/Synth/PADnote.cpp | 77 +- src/Synth/PADnote.h | 31 +- src/Synth/Resonance.cpp | 32 +- src/Synth/Resonance.h | 1 - src/Synth/SUBnote.cpp | 99 +- src/Synth/SUBnote.h | 29 +- src/Synth/SynthNote.cpp | 133 ++- src/Synth/SynthNote.h | 19 +- src/Tests/AdNoteTest.h | 7 +- src/Tests/ControllerTest.h | 1 - src/Tests/EchoTest.h | 5 +- src/Tests/MicrotonalTest.h | 5 +- src/Tests/OscilGenTest.h | 12 +- src/Tests/RandTest.h | 2 - src/Tests/SampleTest.h | 19 +- src/Tests/SubNoteTest.h | 1 - src/Tests/XMLwrapperTest.h | 7 +- src/UI/NioUI.cpp | 39 +- src/UI/NioUI.h | 7 +- src/UI/WidgetPDial.cpp | 134 +-- src/UI/WidgetPDial.h | 17 +- src/globals.h | 15 +- src/main.cpp | 230 ++-- style.cfg | 1218 ++++++++++++++++++++++ style.sh | 3 + 149 files changed, 4723 insertions(+), 3411 deletions(-) create mode 100644 style.cfg create mode 100755 style.sh diff --git a/ExternalPrograms/Controller/Controller.h b/ExternalPrograms/Controller/Controller.h index cfa77b71..5b83744f 100644 --- a/ExternalPrograms/Controller/Controller.h +++ b/ExternalPrograms/Controller/Controller.h @@ -31,4 +31,3 @@ class Controller }; #endif - diff --git a/ExternalPrograms/Spliter/Spliter.h b/ExternalPrograms/Spliter/Spliter.h index dd1333f1..9b5b83b1 100644 --- a/ExternalPrograms/Spliter/Spliter.h +++ b/ExternalPrograms/Spliter/Spliter.h @@ -25,4 +25,3 @@ class Spliter }; #endif - diff --git a/src/DSP/AnalogFilter.cpp b/src/DSP/AnalogFilter.cpp index b603a47f..63bbd77f 100644 --- a/src/DSP/AnalogFilter.cpp +++ b/src/DSP/AnalogFilter.cpp @@ -74,7 +74,7 @@ void AnalogFilter::cleanup() void AnalogFilter::computefiltercoefs() { float tmp; - bool zerocoefs = false; //this is used if the freq is too high + bool zerocoefs = false; //this is used if the freq is too high //do not allow frequencies bigger than samplerate/2 float freq = this->freq; @@ -103,196 +103,198 @@ void AnalogFilter::computefiltercoefs() //General Constants const float omega = 2 * PI * freq / SAMPLE_RATE; - const float sn = sinf(omega), cs = cosf(omega); - float alpha, beta; + const float sn = sinf(omega), cs = cosf(omega); + float alpha, beta; //most of theese are implementations of //the "Cookbook formulae for audio EQ" by Robert Bristow-Johnson //The original location of the Cookbook is: //http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt switch(type) { - case 0: //LPF 1 pole - if(!zerocoefs) - tmp = expf(-2.0f * PI * freq / SAMPLE_RATE); - else - tmp = 0.0f; - c[0] = 1.0f - tmp; - c[1] = 0.0f; - c[2] = 0.0f; - d[1] = tmp; - d[2] = 0.0f; - order = 1; - break; - case 1: //HPF 1 pole - if(!zerocoefs) - tmp = expf(-2.0f * PI * freq / SAMPLE_RATE); - else - tmp = 0.0f; - c[0] = (1.0f + tmp) / 2.0f; - c[1] = -(1.0f + tmp) / 2.0f; - c[2] = 0.0f; - d[1] = tmp; - d[2] = 0.0f; - order = 1; - break; - case 2: //LPF 2 poles - if(!zerocoefs) { - alpha = sn / (2 * tmpq); - tmp = 1 + alpha; - c[0] = (1.0f - cs) / 2.0f / tmp; - c[1] = (1.0f - cs) / tmp; - c[2] = (1.0f - cs) / 2.0f / tmp; - d[1] = -2 * cs / tmp * (-1); - d[2] = (1 - alpha) / tmp * (-1); - } - else { - c[0] = 1.0f; - c[1] = 0.0f; - c[2] = 0.0f; - d[1] = 0.0f; - d[2] = 0.0f; - } - order = 2; - break; - case 3: //HPF 2 poles - if(!zerocoefs) { - alpha = sn / (2 * tmpq); - tmp = 1 + alpha; - c[0] = (1.0f + cs) / 2.0f / tmp; - c[1] = -(1.0f + cs) / tmp; - c[2] = (1.0f + cs) / 2.0f / tmp; - d[1] = -2 * cs / tmp * (-1); - d[2] = (1 - alpha) / tmp * (-1); - } - else { - c[0] = 0.0f; - c[1] = 0.0f; - c[2] = 0.0f; - d[1] = 0.0f; - d[2] = 0.0f; - } - order = 2; - break; - case 4: //BPF 2 poles - if(!zerocoefs) { - alpha = sn / (2 * tmpq); - tmp = 1 + alpha; - c[0] = alpha / tmp *sqrt(tmpq + 1); - c[1] = 0; - c[2] = -alpha / tmp *sqrt(tmpq + 1); - d[1] = -2 * cs / tmp * (-1); - d[2] = (1 - alpha) / tmp * (-1); - } - else { - c[0] = 0.0f; - c[1] = 0.0f; - c[2] = 0.0f; - d[1] = 0.0f; - d[2] = 0.0f; - } - order = 2; - break; - case 5: //NOTCH 2 poles - if(!zerocoefs) { - alpha = sn / (2 * sqrt(tmpq)); - tmp = 1 + alpha; - c[0] = 1 / tmp; - c[1] = -2 * cs / tmp; - c[2] = 1 / tmp; - d[1] = -2 * cs / tmp * (-1); - d[2] = (1 - alpha) / tmp * (-1); - } - else { - c[0] = 1.0f; - c[1] = 0.0f; - c[2] = 0.0f; - d[1] = 0.0f; - d[2] = 0.0f; - } - order = 2; - break; - case 6: //PEAK (2 poles) - if(!zerocoefs) { - tmpq *= 3.0f; - alpha = sn / (2 * tmpq); - tmp = 1 + alpha / tmpgain; - c[0] = (1.0f + alpha * tmpgain) / tmp; - c[1] = (-2.0f * cs) / tmp; - c[2] = (1.0f - alpha * tmpgain) / tmp; - d[1] = -2 * cs / tmp * (-1); - d[2] = (1 - alpha / tmpgain) / tmp * (-1); - } - else { - c[0] = 1.0f; - c[1] = 0.0f; - c[2] = 0.0f; - d[1] = 0.0f; - d[2] = 0.0f; - } - order = 2; - break; - case 7: //Low Shelf - 2 poles - if(!zerocoefs) { - tmpq = sqrt(tmpq); - alpha = sn / (2 * tmpq); - beta = sqrt(tmpgain) / tmpq; - tmp = (tmpgain + 1.0f) + (tmpgain - 1.0f) * cs + beta * sn; - - c[0] = tmpgain - * ((tmpgain - + 1.0f) - (tmpgain - 1.0f) * cs + beta * sn) / tmp; - c[1] = 2.0f * tmpgain - * ((tmpgain - 1.0f) - (tmpgain + 1.0f) * cs) / tmp; - c[2] = tmpgain - * ((tmpgain - + 1.0f) - (tmpgain - 1.0f) * cs - beta * sn) / tmp; - d[1] = -2.0f * ((tmpgain - 1.0f) + (tmpgain + 1.0f) * cs) / tmp * (-1); - d[2] = - ((tmpgain - + 1.0f) + (tmpgain - 1.0f) * cs - beta * sn) / tmp * (-1); - } - else { - c[0] = tmpgain; - c[1] = 0.0f; - c[2] = 0.0f; - d[1] = 0.0f; - d[2] = 0.0f; - } - order = 2; - break; - case 8: //High Shelf - 2 poles - if(!zerocoefs) { - tmpq = sqrt(tmpq); - alpha = sn / (2 * tmpq); - beta = sqrt(tmpgain) / tmpq; - tmp = (tmpgain + 1.0f) - (tmpgain - 1.0f) * cs + beta * sn; - - c[0] = tmpgain - * ((tmpgain - + 1.0f) + (tmpgain - 1.0f) * cs + beta * sn) / tmp; - c[1] = -2.0f * tmpgain - * ((tmpgain - 1.0f) + (tmpgain + 1.0f) * cs) / tmp; - c[2] = tmpgain - * ((tmpgain - + 1.0f) + (tmpgain - 1.0f) * cs - beta * sn) / tmp; - d[1] = 2.0f * ((tmpgain - 1.0f) - (tmpgain + 1.0f) * cs) / tmp * (-1); - d[2] = - ((tmpgain - + 1.0f) - (tmpgain - 1.0f) * cs - beta * sn) / tmp * (-1); - } - else { - c[0] = 1.0f; - c[1] = 0.0f; - c[2] = 0.0f; - d[1] = 0.0f; - d[2] = 0.0f; - } - order = 2; - break; - default: //wrong type - type = 0; - computefiltercoefs(); - break; + case 0: //LPF 1 pole + if(!zerocoefs) + tmp = expf(-2.0f * PI * freq / SAMPLE_RATE); + else + tmp = 0.0f; + c[0] = 1.0f - tmp; + c[1] = 0.0f; + c[2] = 0.0f; + d[1] = tmp; + d[2] = 0.0f; + order = 1; + break; + case 1: //HPF 1 pole + if(!zerocoefs) + tmp = expf(-2.0f * PI * freq / SAMPLE_RATE); + else + tmp = 0.0f; + c[0] = (1.0f + tmp) / 2.0f; + c[1] = -(1.0f + tmp) / 2.0f; + c[2] = 0.0f; + d[1] = tmp; + d[2] = 0.0f; + order = 1; + break; + case 2: //LPF 2 poles + if(!zerocoefs) { + alpha = sn / (2 * tmpq); + tmp = 1 + alpha; + c[0] = (1.0f - cs) / 2.0f / tmp; + c[1] = (1.0f - cs) / tmp; + c[2] = (1.0f - cs) / 2.0f / tmp; + d[1] = -2 * cs / tmp * (-1); + d[2] = (1 - alpha) / tmp * (-1); + } + else { + c[0] = 1.0f; + c[1] = 0.0f; + c[2] = 0.0f; + d[1] = 0.0f; + d[2] = 0.0f; + } + order = 2; + break; + case 3: //HPF 2 poles + if(!zerocoefs) { + alpha = sn / (2 * tmpq); + tmp = 1 + alpha; + c[0] = (1.0f + cs) / 2.0f / tmp; + c[1] = -(1.0f + cs) / tmp; + c[2] = (1.0f + cs) / 2.0f / tmp; + d[1] = -2 * cs / tmp * (-1); + d[2] = (1 - alpha) / tmp * (-1); + } + else { + c[0] = 0.0f; + c[1] = 0.0f; + c[2] = 0.0f; + d[1] = 0.0f; + d[2] = 0.0f; + } + order = 2; + break; + case 4: //BPF 2 poles + if(!zerocoefs) { + alpha = sn / (2 * tmpq); + tmp = 1 + alpha; + c[0] = alpha / tmp *sqrt(tmpq + 1); + c[1] = 0; + c[2] = -alpha / tmp *sqrt(tmpq + 1); + d[1] = -2 * cs / tmp * (-1); + d[2] = (1 - alpha) / tmp * (-1); + } + else { + c[0] = 0.0f; + c[1] = 0.0f; + c[2] = 0.0f; + d[1] = 0.0f; + d[2] = 0.0f; + } + order = 2; + break; + case 5: //NOTCH 2 poles + if(!zerocoefs) { + alpha = sn / (2 * sqrt(tmpq)); + tmp = 1 + alpha; + c[0] = 1 / tmp; + c[1] = -2 * cs / tmp; + c[2] = 1 / tmp; + d[1] = -2 * cs / tmp * (-1); + d[2] = (1 - alpha) / tmp * (-1); + } + else { + c[0] = 1.0f; + c[1] = 0.0f; + c[2] = 0.0f; + d[1] = 0.0f; + d[2] = 0.0f; + } + order = 2; + break; + case 6: //PEAK (2 poles) + if(!zerocoefs) { + tmpq *= 3.0f; + alpha = sn / (2 * tmpq); + tmp = 1 + alpha / tmpgain; + c[0] = (1.0f + alpha * tmpgain) / tmp; + c[1] = (-2.0f * cs) / tmp; + c[2] = (1.0f - alpha * tmpgain) / tmp; + d[1] = -2 * cs / tmp * (-1); + d[2] = (1 - alpha / tmpgain) / tmp * (-1); + } + else { + c[0] = 1.0f; + c[1] = 0.0f; + c[2] = 0.0f; + d[1] = 0.0f; + d[2] = 0.0f; + } + order = 2; + break; + case 7: //Low Shelf - 2 poles + if(!zerocoefs) { + tmpq = sqrt(tmpq); + alpha = sn / (2 * tmpq); + beta = sqrt(tmpgain) / tmpq; + tmp = (tmpgain + 1.0f) + (tmpgain - 1.0f) * cs + beta * sn; + + c[0] = tmpgain + * ((tmpgain + + 1.0f) - (tmpgain - 1.0f) * cs + beta * sn) / tmp; + c[1] = 2.0f * tmpgain + * ((tmpgain - 1.0f) - (tmpgain + 1.0f) * cs) / tmp; + c[2] = tmpgain + * ((tmpgain + + 1.0f) - (tmpgain - 1.0f) * cs - beta * sn) / tmp; + d[1] = -2.0f + * ((tmpgain - 1.0f) + (tmpgain + 1.0f) * cs) / tmp * (-1); + d[2] = + ((tmpgain + + 1.0f) + (tmpgain - 1.0f) * cs - beta * sn) / tmp * (-1); + } + else { + c[0] = tmpgain; + c[1] = 0.0f; + c[2] = 0.0f; + d[1] = 0.0f; + d[2] = 0.0f; + } + order = 2; + break; + case 8: //High Shelf - 2 poles + if(!zerocoefs) { + tmpq = sqrt(tmpq); + alpha = sn / (2 * tmpq); + beta = sqrt(tmpgain) / tmpq; + tmp = (tmpgain + 1.0f) - (tmpgain - 1.0f) * cs + beta * sn; + + c[0] = tmpgain + * ((tmpgain + + 1.0f) + (tmpgain - 1.0f) * cs + beta * sn) / tmp; + c[1] = -2.0f * tmpgain + * ((tmpgain - 1.0f) + (tmpgain + 1.0f) * cs) / tmp; + c[2] = tmpgain + * ((tmpgain + + 1.0f) + (tmpgain - 1.0f) * cs - beta * sn) / tmp; + d[1] = 2.0f + * ((tmpgain - 1.0f) - (tmpgain + 1.0f) * cs) / tmp * (-1); + d[2] = + ((tmpgain + + 1.0f) - (tmpgain - 1.0f) * cs - beta * sn) / tmp * (-1); + } + else { + c[0] = 1.0f; + c[1] = 0.0f; + c[2] = 0.0f; + d[1] = 0.0f; + d[2] = 0.0f; + } + order = 2; + break; + default: //wrong type + type = 0; + computefiltercoefs(); + break; } } @@ -313,13 +315,13 @@ void AnalogFilter::setfreq(float frequency) //if the frequency is changed fast, it needs interpolation if((rap > 3.0f) || nyquistthresh) { //(now, filter and coeficients backup) - oldCoeff = coeff; + oldCoeff = coeff; for(int i = 0; i < MAX_FILTER_STAGES + 1; ++i) oldHistory[i] = history[i]; if(!firsttime) needsinterpolation = true; } - freq = frequency; + freq = frequency; computefiltercoefs(); firsttime = false; } @@ -360,27 +362,25 @@ void AnalogFilter::setstages(int stages_) void AnalogFilter::singlefilterout(float *smp, fstage &hist, const Coeff &coeff) { - if(order == 1) { //First order filter + if(order == 1) //First order filter for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { - float y0 = smp[i]*coeff.c[0] + hist.x1*coeff.c[1] - + hist.y1*coeff.d[1]; + float y0 = smp[i] * coeff.c[0] + hist.x1 * coeff.c[1] + + hist.y1 * coeff.d[1]; hist.y1 = y0; hist.x1 = smp[i]; smp[i] = y0; } - } - if(order == 2) { //Second order filter + if(order == 2) //Second order filter for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { - float y0 = smp[i]*coeff.c[0] + hist.x1*coeff.c[1] - + hist.x2*coeff.c[2] + hist.y1*coeff.d[1] - + hist.y2*coeff.d[2]; + float y0 = smp[i] * coeff.c[0] + hist.x1 * coeff.c[1] + + hist.x2 * coeff.c[2] + hist.y1 * coeff.d[1] + + hist.y2 * coeff.d[2]; hist.y2 = hist.y1; hist.y1 = y0; hist.x2 = hist.x1; hist.x1 = smp[i]; smp[i] = y0; } - } } void AnalogFilter::filterout(float *smp) { @@ -425,4 +425,3 @@ float AnalogFilter::H(float freq) h = h / (x * x + y * y); return powf(h, (stages + 1.0f) / 2.0f); } - diff --git a/src/DSP/AnalogFilter.h b/src/DSP/AnalogFilter.h index 156df501..749605f9 100644 --- a/src/DSP/AnalogFilter.h +++ b/src/DSP/AnalogFilter.h @@ -53,13 +53,13 @@ class AnalogFilter:public Filter private: struct fstage { - float x1, x2;//Input History - float y1, y2;//Output History + float x1, x2; //Input History + float y1, y2; //Output History } history[MAX_FILTER_STAGES + 1], oldHistory[MAX_FILTER_STAGES + 1]; struct Coeff { float c[3], //Feed Forward - d[3]; //Feed Back + d[3]; //Feed Back } coeff, oldCoeff; //old coeffs are used for interpolation when paremeters change quickly @@ -68,21 +68,20 @@ class AnalogFilter:public Filter //Update coeff and order void computefiltercoefs(); - int type; //The type of the filter (LPF1,HPF1,LPF2,HPF2...) - int stages; //how many times the filter is applied (0->1,1->2,etc.) + int type; //The type of the filter (LPF1,HPF1,LPF2,HPF2...) + int stages; //how many times the filter is applied (0->1,1->2,etc.) float freq; //Frequency given in Hz float q; //Q factor (resonance or Q factor) float gain; //the gain of the filter (if are shelf/peak) filters int order; //the order of the filter (number of poles) - bool needsinterpolation, //Interpolation between coeff changes - firsttime; //First Iteration of filter - bool abovenq, //if the frequency is above the nyquist - oldabovenq; //if the last time was above nyquist + bool needsinterpolation, //Interpolation between coeff changes + firsttime; //First Iteration of filter + bool abovenq, //if the frequency is above the nyquist + oldabovenq; //if the last time was above nyquist //(used to see if it needs interpolation) }; #endif - diff --git a/src/DSP/FFTwrapper.cpp b/src/DSP/FFTwrapper.cpp index 675244d4..65fcebb8 100644 --- a/src/DSP/FFTwrapper.cpp +++ b/src/DSP/FFTwrapper.cpp @@ -59,17 +59,17 @@ void FFTwrapper::smps2freqs(const float *smps, fft_t *freqs) fftw_execute(planfftw); //Grab data - memcpy((void*)freqs, (const void*)fft, fftsize*sizeof(double)); + memcpy((void *)freqs, (const void *)fft, fftsize * sizeof(double)); } void FFTwrapper::freqs2smps(const fft_t *freqs, float *smps) { //Load data - memcpy( (void*)fft, (const void*)freqs, fftsize*sizeof(double)); + memcpy((void *)fft, (const void *)freqs, fftsize * sizeof(double)); //clear unused freq channel - fft[fftsize/2][0] = 0.0f; - fft[fftsize/2][1] = 0.0f; + fft[fftsize / 2][0] = 0.0f; + fft[fftsize / 2][1] = 0.0f; //IDFT fftw_execute(planfftw_inv); @@ -83,4 +83,3 @@ void FFT_cleanup() { fftw_cleanup(); } - diff --git a/src/DSP/FFTwrapper.h b/src/DSP/FFTwrapper.h index d86dacb7..77941b39 100644 --- a/src/DSP/FFTwrapper.h +++ b/src/DSP/FFTwrapper.h @@ -24,7 +24,7 @@ #define FFT_WRAPPER_H #include #include -typedef double fftw_real; +typedef double fftw_real; typedef std::complex fft_t; /**A wrapper for the FFTW library (Fast Fourier Transforms)*/ @@ -42,12 +42,11 @@ class FFTwrapper void smps2freqs(const float *smps, fft_t *freqs); void freqs2smps(const fft_t *freqs, float *smps); private: - int fftsize; + int fftsize; fftw_real *time; fftw_complex *fft; - fftw_plan planfftw, planfftw_inv; + fftw_plan planfftw, planfftw_inv; }; void FFT_cleanup(); #endif - diff --git a/src/DSP/Filter.cpp b/src/DSP/Filter.cpp index b06e824f..7c7e92c8 100644 --- a/src/DSP/Filter.cpp +++ b/src/DSP/Filter.cpp @@ -36,22 +36,22 @@ Filter *Filter::generate(FilterParams *pars) Filter *filter; switch(pars->Pcategory) { - case 1: - filter = new FormantFilter(pars); - break; - case 2: - filter = new SVFilter(Ftype, 1000.0f, pars->getq(), Fstages); - filter->outgain = dB2rap(pars->getgain()); - if(filter->outgain > 1.0f) - filter->outgain = sqrt(filter->outgain); - break; - default: - filter = new AnalogFilter(Ftype, 1000.0f, pars->getq(), Fstages); - if((Ftype >= 6) && (Ftype <= 8)) - filter->setgain(pars->getgain()); - else + case 1: + filter = new FormantFilter(pars); + break; + case 2: + filter = new SVFilter(Ftype, 1000.0f, pars->getq(), Fstages); filter->outgain = dB2rap(pars->getgain()); - break; + if(filter->outgain > 1.0f) + filter->outgain = sqrt(filter->outgain); + break; + default: + filter = new AnalogFilter(Ftype, 1000.0f, pars->getq(), Fstages); + if((Ftype >= 6) && (Ftype <= 8)) + filter->setgain(pars->getgain()); + else + filter->outgain = dB2rap(pars->getgain()); + break; } return filter; } @@ -60,4 +60,3 @@ float Filter::getrealfreq(float freqpitch) { return powf(2.0f, freqpitch + 9.96578428f); //log2(1000)=9.95748f } - diff --git a/src/DSP/Filter.h b/src/DSP/Filter.h index 9550af7b..41761e50 100644 --- a/src/DSP/Filter.h +++ b/src/DSP/Filter.h @@ -29,7 +29,7 @@ class Filter { public: static float getrealfreq(float freqpitch); - static Filter *generate(class FilterParams *pars); + static Filter *generate(class FilterParams * pars); virtual ~Filter() {} virtual void filterout(float *smp) = 0; @@ -43,4 +43,3 @@ class Filter }; #endif - diff --git a/src/DSP/FormantFilter.cpp b/src/DSP/FormantFilter.cpp index 56c6f1bb..34713bc9 100644 --- a/src/DSP/FormantFilter.cpp +++ b/src/DSP/FormantFilter.cpp @@ -38,9 +38,9 @@ FormantFilter::FormantFilter(FilterParams *pars) for(int i = 0; i < numformants; ++i) { formantpar[j][i].freq = pars->getformantfreq( pars->Pvowels[j].formants[i].freq); - formantpar[j][i].amp = pars->getformantamp( + formantpar[j][i].amp = pars->getformantamp( pars->Pvowels[j].formants[i].amp); - formantpar[j][i].q = pars->getformantq( + formantpar[j][i].q = pars->getformantq( pars->Pvowels[j].formants[i].q); } @@ -54,19 +54,19 @@ FormantFilter::FormantFilter(FilterParams *pars) formantslowness = powf(1.0f - (pars->Pformantslowness / 128.0f), 3.0f); - sequencesize = pars->Psequencesize; + sequencesize = pars->Psequencesize; if(sequencesize == 0) sequencesize = 1; for(int k = 0; k < sequencesize; ++k) sequence[k].nvowel = pars->Psequence[k].nvowel; - vowelclearness = powf(10.0f, (pars->Pvowelclearness - 32.0f) / 48.0f); + vowelclearness = powf(10.0f, (pars->Pvowelclearness - 32.0f) / 48.0f); sequencestretch = powf(0.1f, (pars->Psequencestretch - 32.0f) / 48.0f); if(pars->Psequencereversed) sequencestretch *= -1.0f; - outgain = dB2rap(pars->getgain()); + outgain = dB2rap(pars->getgain()); oldinput = -1.0f; Qfactor = 1.0f; @@ -123,7 +123,8 @@ void FormantFilter::setpos(float input) pos = 1.0f; pos = (atanf((pos * 2.0f - - 1.0f) * vowelclearness) / atanf(vowelclearness) + 1.0f) * 0.5f; + - 1.0f) + * vowelclearness) / atanf(vowelclearness) + 1.0f) * 0.5f; p1 = sequence[p1].nvowel; p2 = sequence[p2].nvowel; @@ -133,18 +134,18 @@ void FormantFilter::setpos(float input) currentformants[i].freq = formantpar[p1][i].freq * (1.0f - pos) + formantpar[p2][i].freq * pos; - currentformants[i].amp = formantpar[p1][i].amp - * (1.0f - - pos) + formantpar[p2][i].amp * pos; - currentformants[i].q = formantpar[p1][i].q - * (1.0f - pos) + formantpar[p2][i].q * pos; + currentformants[i].amp = formantpar[p1][i].amp + * (1.0f + - pos) + formantpar[p2][i].amp * pos; + currentformants[i].q = formantpar[p1][i].q + * (1.0f - pos) + formantpar[p2][i].q * pos; formant[i]->setfreq_and_q(currentformants[i].freq, currentformants[i].q * Qfactor); oldformantamp[i] = currentformants[i].amp; } firsttime = 0; } - else { + else for(int i = 0; i < numformants; ++i) { currentformants[i].freq = currentformants[i].freq * (1.0f - formantslowness) @@ -170,7 +171,6 @@ void FormantFilter::setpos(float input) formant[i]->setfreq_and_q(currentformants[i].freq, currentformants[i].q * Qfactor); } - } oldQfactor = Qfactor; } @@ -192,7 +192,7 @@ void FormantFilter::setgain(float /*dBgain*/) inline float log_2(float x) { - return logf(x)/logf(2.0f); + return logf(x) / logf(2.0f); } void FormantFilter::setfreq_and_q(float frequency, float q_) @@ -233,4 +233,3 @@ void FormantFilter::filterout(float *smp) } returnTmpBuffer(inbuffer); } - diff --git a/src/DSP/FormantFilter.h b/src/DSP/FormantFilter.h index bfa9cbc9..1a7f0dae 100644 --- a/src/DSP/FormantFilter.h +++ b/src/DSP/FormantFilter.h @@ -40,7 +40,7 @@ class FormantFilter:public Filter void cleanup(); private: - class AnalogFilter *formant[FF_MAX_FORMANTS]; + class AnalogFilter * formant[FF_MAX_FORMANTS]; struct { float freq, amp, q; //frequency,amplitude,Q @@ -53,7 +53,7 @@ class FormantFilter:public Filter float oldformantamp[FF_MAX_FORMANTS]; - int sequencesize, numformants, firsttime; + int sequencesize, numformants, firsttime; float oldinput, slowinput; float Qfactor, formantslowness, oldQfactor; float vowelclearness, sequencestretch; @@ -62,4 +62,3 @@ class FormantFilter:public Filter }; #endif - diff --git a/src/DSP/SVFilter.cpp b/src/DSP/SVFilter.cpp index 7253315c..63a07fd0 100644 --- a/src/DSP/SVFilter.cpp +++ b/src/DSP/SVFilter.cpp @@ -33,13 +33,13 @@ SVFilter::SVFilter(unsigned char Ftype, float Fq, unsigned char Fstages) { - assert(Ftype<4); - stages = Fstages; - type = Ftype; - freq = Ffreq; - q = Fq; - gain = 1.0f; - outgain = 1.0f; + assert(Ftype < 4); + stages = Fstages; + type = Ftype; + freq = Ffreq; + q = Fq; + gain = 1.0f; + outgain = 1.0f; needsinterpolation = false; firsttime = true; if(stages >= MAX_FILTER_STAGES) @@ -65,7 +65,7 @@ void SVFilter::cleanup() void SVFilter::computefiltercoefs() { - par.f = freq / SAMPLE_RATE * 4.0f; + par.f = freq / SAMPLE_RATE * 4.0f; if(par.f > 0.99999f) par.f = 0.99999f; par.q = 1.0f - atanf(sqrt(q)) * 2.0f / PI; @@ -88,12 +88,12 @@ void SVFilter::setfreq(float frequency) bool nyquistthresh = (abovenq ^ oldabovenq); //if the frequency is changed fast, it needs interpolation - if((rap > 3.0f) || nyquistthresh) {//(now, filter and coeficients backup) + if((rap > 3.0f) || nyquistthresh) { //(now, filter and coeficients backup) ipar = par; if(!firsttime) needsinterpolation = true; } - freq = frequency; + freq = frequency; computefiltercoefs(); firsttime = false; } @@ -135,20 +135,20 @@ void SVFilter::singlefilterout(float *smp, fstage &x, parameters &par) { float *out = NULL; switch(type) { - case 0: - out = &x.low; - break; - case 1: - out = &x.high; - break; - case 2: - out = &x.band; - break; - case 3: - out = &x.notch; - break; - default: - errx(1, "Impossible SVFilter type encountered [%d]", type); + case 0: + out = &x.low; + break; + case 1: + out = &x.high; + break; + case 2: + out = &x.band; + break; + case 3: + out = &x.notch; + break; + default: + errx(1, "Impossible SVFilter type encountered [%d]", type); } for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { @@ -157,7 +157,7 @@ void SVFilter::singlefilterout(float *smp, fstage &x, parameters &par) x.band = par.f * x.high + x.band; x.notch = x.high + x.low; - smp[i] = *out; + smp[i] = *out; } } @@ -184,4 +184,3 @@ void SVFilter::filterout(float *smp) for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) smp[i] *= outgain; } - diff --git a/src/DSP/SVFilter.h b/src/DSP/SVFilter.h index beef25a3..94e926ad 100644 --- a/src/DSP/SVFilter.h +++ b/src/DSP/SVFilter.h @@ -55,8 +55,8 @@ class SVFilter:public Filter void singlefilterout(float *smp, fstage &x, parameters &par); void computefiltercoefs(); - int type; //The type of the filter (LPF1,HPF1,LPF2,HPF2...) - int stages; //how many times the filter is applied (0->1,1->2,etc.) + int type; //The type of the filter (LPF1,HPF1,LPF2,HPF2...) + int stages; //how many times the filter is applied (0->1,1->2,etc.) float freq; //Frequency given in Hz float q; //Q factor (resonance or Q factor) float gain; //the gain of the filter (if are shelf/peak) filters @@ -68,4 +68,3 @@ class SVFilter:public Filter #endif - diff --git a/src/DSP/Unison.cpp b/src/DSP/Unison.cpp index ba98209b..00450c51 100644 --- a/src/DSP/Unison.cpp +++ b/src/DSP/Unison.cpp @@ -25,7 +25,7 @@ Unison::Unison(int update_period_samples_, float max_delay_sec_) { update_period_samples = update_period_samples_; - max_delay = (int)(max_delay_sec_ * (float)SAMPLE_RATE + 1); + max_delay = (int)(max_delay_sec_ * (float)SAMPLE_RATE + 1); if(max_delay < 10) max_delay = 10; delay_buffer = new float[max_delay]; @@ -81,10 +81,10 @@ void Unison::update_parameters() { if(!uv) return; float increments_per_second = SAMPLE_RATE - / (float) update_period_samples; + / (float) update_period_samples; // printf("#%g, %g\n",increments_per_second,base_freq); for(int i = 0; i < unison_size; ++i) { - float base = powf(UNISON_FREQ_SPAN, RND * 2.0f - 1.0f); + float base = powf(UNISON_FREQ_SPAN, RND * 2.0f - 1.0f); uv[i].relative_amplitude = base; float period = base / base_freq; float m = 4.0f / (period * increments_per_second); @@ -123,14 +123,14 @@ void Unison::process(int bufsize, float *inbuf, float *outbuf) { xpos = 0.0f; } xpos += xpos_step; - float in = inbuf[i], out = 0.0f; + float in = inbuf[i], out = 0.0f; float sign = 1.0f; for(int k = 0; k < unison_size; ++k) { float vpos = uv[k].realpos1 - * (1.0f - xpos) + uv[k].realpos2 * xpos; //optimize - float pos = delay_k + max_delay - vpos - 1.0f; //optimize - int posi; + * (1.0f - xpos) + uv[k].realpos2 * xpos; //optimize + float pos = delay_k + max_delay - vpos - 1.0f; //optimize + int posi; float posf; F2I(pos, posi); //optimize! if(posi >= max_delay) @@ -172,13 +172,13 @@ void Unison::update_unison_data() { #warning \ I have to enlarge (reallocate) the buffer to make place for the whole delay float newval = 1.0f + 0.5f - * (vibratto_val - + 1.0f) * unison_amplitude_samples - * uv[k].relative_amplitude; + * (vibratto_val + + 1.0f) * unison_amplitude_samples + * uv[k].relative_amplitude; if(first_time) uv[k].realpos1 = uv[k].realpos2 = newval; - else{ + else { uv[k].realpos1 = uv[k].realpos2; uv[k].realpos2 = newval; } @@ -189,4 +189,3 @@ void Unison::update_unison_data() { if(first_time) first_time = false; } - diff --git a/src/DSP/Unison.h b/src/DSP/Unison.h index 3fc0c324..d291608d 100644 --- a/src/DSP/Unison.h +++ b/src/DSP/Unison.h @@ -43,7 +43,7 @@ class Unison void update_parameters(); void update_unison_data(); - int unison_size; + int unison_size; float base_freq; struct UnisonVoice { float step, position; //base LFO @@ -51,19 +51,18 @@ class Unison float relative_amplitude; float lin_fpos, lin_ffreq; UnisonVoice() { - position = RND * 1.8f - 0.9f; - realpos1 = 0.0f; - realpos2 = 0.0f; - step = 0.0f; - relative_amplitude = 1.0f; + position = RND * 1.8f - 0.9f; + realpos1 = 0.0f; + realpos2 = 0.0f; + step = 0.0f; + relative_amplitude = 1.0f; } } *uv; - int update_period_samples, update_period_sample_k; - int max_delay, delay_k; - bool first_time; + int update_period_samples, update_period_sample_k; + int max_delay, delay_k; + bool first_time; float *delay_buffer; float unison_amplitude_samples; float unison_bandwidth_cents; }; #endif - diff --git a/src/Effects/Alienwah.cpp b/src/Effects/Alienwah.cpp index 0a1ae2d6..48fe6037 100644 --- a/src/Effects/Alienwah.cpp +++ b/src/Effects/Alienwah.cpp @@ -66,10 +66,10 @@ void Alienwah::out(const Stereo &smp) //left complex tmp = clfol * x + oldclfol * x1; - complexout = tmp * oldl[oldk]; + complex out = tmp * oldl[oldk]; out.real() += (1 - fabs(fb)) * smp.l[i] * pangainL; - oldl[oldk] = out; + oldl[oldk] = out; float l = out.real() * 10.0f * (fb + 0.1f); //right @@ -78,7 +78,7 @@ void Alienwah::out(const Stereo &smp) out = tmp * oldr[oldk]; out.real() += (1 - fabs(fb)) * smp.r[i] * pangainR; - oldr[oldk] = out; + oldr[oldk] = out; float r = out.real() * 10.0f * (fb + 0.1f); @@ -164,13 +164,13 @@ void Alienwah::setpreset(unsigned char npreset) const int NUM_PRESETS = 4; unsigned char presets[NUM_PRESETS][PRESET_SIZE] = { //AlienWah1 - {127, 64, 70, 0, 0, 62, 60, 105, 25, 0, 64}, + {127, 64, 70, 0, 0, 62, 60, 105, 25, 0, 64}, //AlienWah2 - {127, 64, 73, 106, 0, 101, 60, 105, 17, 0, 64}, + {127, 64, 73, 106, 0, 101, 60, 105, 17, 0, 64}, //AlienWah3 - {127, 64, 63, 0, 1, 100, 112, 105, 31, 0, 42}, + {127, 64, 63, 0, 1, 100, 112, 105, 31, 0, 42}, //AlienWah4 - {93, 64, 25, 0, 1, 66, 101, 11, 47, 0, 86} + {93, 64, 25, 0, 1, 66, 101, 11, 47, 0, 86} }; if(npreset >= NUM_PRESETS) diff --git a/src/Effects/Alienwah.h b/src/Effects/Alienwah.h index 7a02ab24..885f5f8f 100644 --- a/src/Effects/Alienwah.h +++ b/src/Effects/Alienwah.h @@ -78,4 +78,3 @@ class Alienwah:public Effect }; #endif - diff --git a/src/Effects/Chorus.cpp b/src/Effects/Chorus.cpp index 0baca9b4..94301dad 100644 --- a/src/Effects/Chorus.cpp +++ b/src/Effects/Chorus.cpp @@ -79,7 +79,6 @@ void Chorus::out(const Stereo &input) dr2 = getdelay(lfor); for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { - float inl = input.l[i]; float inr = input.r[i]; //LRcross @@ -110,7 +109,7 @@ void Chorus::out(const Stereo &input) mdel = (dr1 * (SOUND_BUFFER_SIZE - i) + dr2 * i) / SOUND_BUFFER_SIZE; if(++drk >= maxdelay) drk = 0; - tmp = drk * 1.0f - mdel + maxdelay * 2.0f; //where should I get the sample from + tmp = drk * 1.0f - mdel + maxdelay * 2.0f; //where should I get the sample from F2I(tmp, dlhi); dlhi %= maxdelay; @@ -180,25 +179,25 @@ void Chorus::setpreset(unsigned char npreset) const int NUM_PRESETS = 10; unsigned char presets[NUM_PRESETS][PRESET_SIZE] = { //Chorus1 - {64, 64, 50, 0, 0, 90, 40, 85, 64, 119, 0, 0 }, + {64, 64, 50, 0, 0, 90, 40, 85, 64, 119, 0, 0 }, //Chorus2 - {64, 64, 45, 0, 0, 98, 56, 90, 64, 19, 0, 0 }, + {64, 64, 45, 0, 0, 98, 56, 90, 64, 19, 0, 0 }, //Chorus3 - {64, 64, 29, 0, 1, 42, 97, 95, 90, 127, 0, 0 }, + {64, 64, 29, 0, 1, 42, 97, 95, 90, 127, 0, 0 }, //Celeste1 - {64, 64, 26, 0, 0, 42, 115, 18, 90, 127, 0, 0 }, + {64, 64, 26, 0, 0, 42, 115, 18, 90, 127, 0, 0 }, //Celeste2 - {64, 64, 29, 117, 0, 50, 115, 9, 31, 127, 0, 1 }, + {64, 64, 29, 117, 0, 50, 115, 9, 31, 127, 0, 1 }, //Flange1 - {64, 64, 57, 0, 0, 60, 23, 3, 62, 0, 0, 0 }, + {64, 64, 57, 0, 0, 60, 23, 3, 62, 0, 0, 0 }, //Flange2 - {64, 64, 33, 34, 1, 40, 35, 3, 109, 0, 0, 0 }, + {64, 64, 33, 34, 1, 40, 35, 3, 109, 0, 0, 0 }, //Flange3 - {64, 64, 53, 34, 1, 94, 35, 3, 54, 0, 0, 1 }, + {64, 64, 53, 34, 1, 94, 35, 3, 54, 0, 0, 1 }, //Flange4 - {64, 64, 40, 0, 1, 62, 12, 19, 97, 0, 0, 0 }, + {64, 64, 40, 0, 1, 62, 12, 19, 97, 0, 0, 0 }, //Flange5 - {64, 64, 55, 105, 0, 24, 39, 19, 17, 0, 0, 1 } + {64, 64, 55, 105, 0, 24, 39, 19, 17, 0, 0, 1 } }; if(npreset >= NUM_PRESETS) @@ -273,4 +272,3 @@ unsigned char Chorus::getpar(int npar) const default: return 0; } } - diff --git a/src/Effects/Chorus.h b/src/Effects/Chorus.h index 828bef90..6a139554 100644 --- a/src/Effects/Chorus.h +++ b/src/Effects/Chorus.h @@ -99,7 +99,7 @@ class Chorus:public Effect //Internal Values float depth, delay, fb; float dl1, dl2, dr1, dr2, lfol, lfor; - int maxdelay; + int maxdelay; Stereo delaySample; int dlk, drk, dlhi, dlhi2; float getdelay(float xlfo); @@ -107,4 +107,3 @@ class Chorus:public Effect }; #endif - diff --git a/src/Effects/Distorsion.cpp b/src/Effects/Distorsion.cpp index d84ac445..ed742298 100644 --- a/src/Effects/Distorsion.cpp +++ b/src/Effects/Distorsion.cpp @@ -38,13 +38,13 @@ Distorsion::Distorsion(const int &insertion_, //default values Pvolume = 50; - Pdrive = 90; - Plevel = 64; - Ptype = 0; - Pnegate = 0; - Plpf = 127; - Phpf = 0; - Pstereo = 0; + Pdrive = 90; + Plevel = 64; + Ptype = 0; + Pnegate = 0; + Plpf = 127; + Phpf = 0; + Pstereo = 0; Pprefiltering = 0; setpreset(Ppreset); @@ -91,23 +91,21 @@ void Distorsion::applyfilters(float *efxoutl, float *efxoutr) */ void Distorsion::out(const Stereo &smp) { - int i; + int i; float l, r, lout, rout; float inputvol = powf(5.0f, (Pdrive - 32.0f) / 127.0f); if(Pnegate != 0) inputvol *= -1.0f; - if(Pstereo != 0) { //Stereo + if(Pstereo != 0) //Stereo for(i = 0; i < SOUND_BUFFER_SIZE; ++i) { efxoutl[i] = smp.l[i] * inputvol * pangainL; efxoutr[i] = smp.r[i] * inputvol * pangainR; } - } - else { + else for(i = 0; i < SOUND_BUFFER_SIZE; ++i) efxoutl[i] = (smp.l[i] * pangainL + smp.r[i] * pangainR) * inputvol; - } if(Pprefiltering != 0) applyfilters(efxoutl, efxoutr); @@ -180,17 +178,17 @@ void Distorsion::setpreset(unsigned char npreset) const int NUM_PRESETS = 6; unsigned char presets[NUM_PRESETS][PRESET_SIZE] = { //Overdrive 1 - {127, 64, 35, 56, 70, 0, 0, 96, 0, 0, 0 }, + {127, 64, 35, 56, 70, 0, 0, 96, 0, 0, 0 }, //Overdrive 2 - {127, 64, 35, 29, 75, 1, 0, 127, 0, 0, 0 }, + {127, 64, 35, 29, 75, 1, 0, 127, 0, 0, 0 }, //A. Exciter 1 - {64, 64, 35, 75, 80, 5, 0, 127, 105, 1, 0 }, + {64, 64, 35, 75, 80, 5, 0, 127, 105, 1, 0 }, //A. Exciter 2 - {64, 64, 35, 85, 62, 1, 0, 127, 118, 1, 0 }, + {64, 64, 35, 85, 62, 1, 0, 127, 118, 1, 0 }, //Guitar Amp - {127, 64, 35, 63, 75, 2, 0, 55, 0, 0, 0 }, + {127, 64, 35, 63, 75, 2, 0, 55, 0, 0, 0 }, //Quantisize - {127, 64, 35, 88, 75, 4, 0, 127, 0, 1, 0 } + {127, 64, 35, 88, 75, 4, 0, 127, 0, 1, 0 } }; @@ -267,4 +265,3 @@ unsigned char Distorsion::getpar(int npar) const default: return 0; } } - diff --git a/src/Effects/Distorsion.h b/src/Effects/Distorsion.h index cfe13950..4aec84f4 100644 --- a/src/Effects/Distorsion.h +++ b/src/Effects/Distorsion.h @@ -56,9 +56,8 @@ class Distorsion:public Effect void sethpf(unsigned char Phpf); //Real Parameters - class AnalogFilter *lpfl, *lpfr, *hpfl, *hpfr; + class AnalogFilter * lpfl, *lpfr, *hpfl, *hpfr; }; #endif - diff --git a/src/Effects/DynamicFilter.cpp b/src/Effects/DynamicFilter.cpp index 1a6ba5eb..60695fe3 100644 --- a/src/Effects/DynamicFilter.cpp +++ b/src/Effects/DynamicFilter.cpp @@ -151,15 +151,15 @@ void DynamicFilter::setpreset(unsigned char npreset) const int NUM_PRESETS = 5; unsigned char presets[NUM_PRESETS][PRESET_SIZE] = { //WahWah - {110, 64, 80, 0, 0, 64, 0, 90, 0, 60}, + {110, 64, 80, 0, 0, 64, 0, 90, 0, 60}, //AutoWah - {110, 64, 70, 0, 0, 80, 70, 0, 0, 60}, + {110, 64, 70, 0, 0, 80, 70, 0, 0, 60}, //Sweep - {100, 64, 30, 0, 0, 50, 80, 0, 0, 60}, + {100, 64, 30, 0, 0, 50, 80, 0, 0, 60}, //VocalMorph1 - {110, 64, 80, 0, 0, 64, 0, 64, 0, 60}, + {110, 64, 80, 0, 0, 64, 0, 64, 0, 60}, //VocalMorph1 - {127, 64, 50, 0, 0, 96, 64, 0, 0, 60} + {127, 64, 50, 0, 0, 96, 64, 0, 0, 60} }; if(npreset >= NUM_PRESETS) @@ -169,86 +169,86 @@ void DynamicFilter::setpreset(unsigned char npreset) filterpars->defaults(); switch(npreset) { - case 0: - filterpars->Pcategory = 0; - filterpars->Ptype = 2; - filterpars->Pfreq = 45; - filterpars->Pq = 64; - filterpars->Pstages = 1; - filterpars->Pgain = 64; - break; - case 1: - filterpars->Pcategory = 2; - filterpars->Ptype = 0; - filterpars->Pfreq = 72; - filterpars->Pq = 64; - filterpars->Pstages = 0; - filterpars->Pgain = 64; - break; - case 2: - filterpars->Pcategory = 0; - filterpars->Ptype = 4; - filterpars->Pfreq = 64; - filterpars->Pq = 64; - filterpars->Pstages = 2; - filterpars->Pgain = 64; - break; - case 3: - filterpars->Pcategory = 1; - filterpars->Ptype = 0; - filterpars->Pfreq = 50; - filterpars->Pq = 70; - filterpars->Pstages = 1; - filterpars->Pgain = 64; - - filterpars->Psequencesize = 2; - // "I" - filterpars->Pvowels[0].formants[0].freq = 34; - filterpars->Pvowels[0].formants[0].amp = 127; - filterpars->Pvowels[0].formants[0].q = 64; - filterpars->Pvowels[0].formants[1].freq = 99; - filterpars->Pvowels[0].formants[1].amp = 122; - filterpars->Pvowels[0].formants[1].q = 64; - filterpars->Pvowels[0].formants[2].freq = 108; - filterpars->Pvowels[0].formants[2].amp = 112; - filterpars->Pvowels[0].formants[2].q = 64; - // "A" - filterpars->Pvowels[1].formants[0].freq = 61; - filterpars->Pvowels[1].formants[0].amp = 127; - filterpars->Pvowels[1].formants[0].q = 64; - filterpars->Pvowels[1].formants[1].freq = 71; - filterpars->Pvowels[1].formants[1].amp = 121; - filterpars->Pvowels[1].formants[1].q = 64; - filterpars->Pvowels[1].formants[2].freq = 99; - filterpars->Pvowels[1].formants[2].amp = 117; - filterpars->Pvowels[1].formants[2].q = 64; - break; - case 4: - filterpars->Pcategory = 1; - filterpars->Ptype = 0; - filterpars->Pfreq = 64; - filterpars->Pq = 70; - filterpars->Pstages = 1; - filterpars->Pgain = 64; - - filterpars->Psequencesize = 2; - filterpars->Pnumformants = 2; - filterpars->Pvowelclearness = 0; - - filterpars->Pvowels[0].formants[0].freq = 70; - filterpars->Pvowels[0].formants[0].amp = 127; - filterpars->Pvowels[0].formants[0].q = 64; - filterpars->Pvowels[0].formants[1].freq = 80; - filterpars->Pvowels[0].formants[1].amp = 122; - filterpars->Pvowels[0].formants[1].q = 64; - - filterpars->Pvowels[1].formants[0].freq = 20; - filterpars->Pvowels[1].formants[0].amp = 127; - filterpars->Pvowels[1].formants[0].q = 64; - filterpars->Pvowels[1].formants[1].freq = 100; - filterpars->Pvowels[1].formants[1].amp = 121; - filterpars->Pvowels[1].formants[1].q = 64; - break; + case 0: + filterpars->Pcategory = 0; + filterpars->Ptype = 2; + filterpars->Pfreq = 45; + filterpars->Pq = 64; + filterpars->Pstages = 1; + filterpars->Pgain = 64; + break; + case 1: + filterpars->Pcategory = 2; + filterpars->Ptype = 0; + filterpars->Pfreq = 72; + filterpars->Pq = 64; + filterpars->Pstages = 0; + filterpars->Pgain = 64; + break; + case 2: + filterpars->Pcategory = 0; + filterpars->Ptype = 4; + filterpars->Pfreq = 64; + filterpars->Pq = 64; + filterpars->Pstages = 2; + filterpars->Pgain = 64; + break; + case 3: + filterpars->Pcategory = 1; + filterpars->Ptype = 0; + filterpars->Pfreq = 50; + filterpars->Pq = 70; + filterpars->Pstages = 1; + filterpars->Pgain = 64; + + filterpars->Psequencesize = 2; + // "I" + filterpars->Pvowels[0].formants[0].freq = 34; + filterpars->Pvowels[0].formants[0].amp = 127; + filterpars->Pvowels[0].formants[0].q = 64; + filterpars->Pvowels[0].formants[1].freq = 99; + filterpars->Pvowels[0].formants[1].amp = 122; + filterpars->Pvowels[0].formants[1].q = 64; + filterpars->Pvowels[0].formants[2].freq = 108; + filterpars->Pvowels[0].formants[2].amp = 112; + filterpars->Pvowels[0].formants[2].q = 64; + // "A" + filterpars->Pvowels[1].formants[0].freq = 61; + filterpars->Pvowels[1].formants[0].amp = 127; + filterpars->Pvowels[1].formants[0].q = 64; + filterpars->Pvowels[1].formants[1].freq = 71; + filterpars->Pvowels[1].formants[1].amp = 121; + filterpars->Pvowels[1].formants[1].q = 64; + filterpars->Pvowels[1].formants[2].freq = 99; + filterpars->Pvowels[1].formants[2].amp = 117; + filterpars->Pvowels[1].formants[2].q = 64; + break; + case 4: + filterpars->Pcategory = 1; + filterpars->Ptype = 0; + filterpars->Pfreq = 64; + filterpars->Pq = 70; + filterpars->Pstages = 1; + filterpars->Pgain = 64; + + filterpars->Psequencesize = 2; + filterpars->Pnumformants = 2; + filterpars->Pvowelclearness = 0; + + filterpars->Pvowels[0].formants[0].freq = 70; + filterpars->Pvowels[0].formants[0].amp = 127; + filterpars->Pvowels[0].formants[0].q = 64; + filterpars->Pvowels[0].formants[1].freq = 80; + filterpars->Pvowels[0].formants[1].amp = 122; + filterpars->Pvowels[0].formants[1].q = 64; + + filterpars->Pvowels[1].formants[0].freq = 20; + filterpars->Pvowels[1].formants[0].amp = 127; + filterpars->Pvowels[1].formants[0].q = 64; + filterpars->Pvowels[1].formants[1].freq = 100; + filterpars->Pvowels[1].formants[1].amp = 121; + filterpars->Pvowels[1].formants[1].q = 64; + break; } // for (int i=0;i<5;i++){ @@ -320,4 +320,3 @@ unsigned char DynamicFilter::getpar(int npar) const default: return 0; } } - diff --git a/src/Effects/DynamicFilter.h b/src/Effects/DynamicFilter.h index c065a895..b5ffc9d5 100644 --- a/src/Effects/DynamicFilter.h +++ b/src/Effects/DynamicFilter.h @@ -58,10 +58,9 @@ class DynamicFilter:public Effect //Internal Values float depth, ampsns, ampsmooth; - class Filter *filterl, *filterr; + class Filter * filterl, *filterr; float ms1, ms2, ms3, ms4; //mean squares }; #endif - diff --git a/src/Effects/EQ.cpp b/src/Effects/EQ.cpp index c5573bb5..a5667973 100644 --- a/src/Effects/EQ.cpp +++ b/src/Effects/EQ.cpp @@ -78,7 +78,7 @@ void EQ::setvolume(unsigned char Pvolume) { this->Pvolume = Pvolume; - outvolume = powf(0.005f, (1.0f - Pvolume / 127.0f)) * 10.0f; + outvolume = powf(0.005f, (1.0f - Pvolume / 127.0f)) * 10.0f; if(insertion == 0) volume = 1.0f; else @@ -109,9 +109,9 @@ void EQ::setpreset(unsigned char npreset) void EQ::changepar(int npar, unsigned char value) { switch(npar) { - case 0: - setvolume(value); - break; + case 0: + setvolume(value); + break; } if(npar < 10) return; @@ -123,49 +123,49 @@ void EQ::changepar(int npar, unsigned char value) float tmp; switch(bp) { - case 0: - filter[nb].Ptype = value; - if(value > 9) - filter[nb].Ptype = 0; //has to be changed if more filters will be added - if(filter[nb].Ptype != 0) { - filter[nb].l->settype(value - 1); - filter[nb].r->settype(value - 1); - } - break; - case 1: - filter[nb].Pfreq = value; - tmp = 600.0f * powf(30.0f, (value - 64.0f) / 64.0f); - filter[nb].l->setfreq(tmp); - filter[nb].r->setfreq(tmp); - break; - case 2: - filter[nb].Pgain = value; - tmp = 30.0f * (value - 64.0f) / 64.0f; - filter[nb].l->setgain(tmp); - filter[nb].r->setgain(tmp); - break; - case 3: - filter[nb].Pq = value; - tmp = powf(30.0f, (value - 64.0f) / 64.0f); - filter[nb].l->setq(tmp); - filter[nb].r->setq(tmp); - break; - case 4: - filter[nb].Pstages = value; - if(value >= MAX_FILTER_STAGES) - filter[nb].Pstages = MAX_FILTER_STAGES - 1; - filter[nb].l->setstages(value); - filter[nb].r->setstages(value); - break; + case 0: + filter[nb].Ptype = value; + if(value > 9) + filter[nb].Ptype = 0; //has to be changed if more filters will be added + if(filter[nb].Ptype != 0) { + filter[nb].l->settype(value - 1); + filter[nb].r->settype(value - 1); + } + break; + case 1: + filter[nb].Pfreq = value; + tmp = 600.0f * powf(30.0f, (value - 64.0f) / 64.0f); + filter[nb].l->setfreq(tmp); + filter[nb].r->setfreq(tmp); + break; + case 2: + filter[nb].Pgain = value; + tmp = 30.0f * (value - 64.0f) / 64.0f; + filter[nb].l->setgain(tmp); + filter[nb].r->setgain(tmp); + break; + case 3: + filter[nb].Pq = value; + tmp = powf(30.0f, (value - 64.0f) / 64.0f); + filter[nb].l->setq(tmp); + filter[nb].r->setq(tmp); + break; + case 4: + filter[nb].Pstages = value; + if(value >= MAX_FILTER_STAGES) + filter[nb].Pstages = MAX_FILTER_STAGES - 1; + filter[nb].l->setstages(value); + filter[nb].r->setstages(value); + break; } } unsigned char EQ::getpar(int npar) const { switch(npar) { - case 0: - return Pvolume; - break; + case 0: + return Pvolume; + break; } if(npar < 10) @@ -176,21 +176,21 @@ unsigned char EQ::getpar(int npar) const return 0; int bp = npar % 5; //band paramenter switch(bp) { - case 0: - return filter[nb].Ptype; - break; - case 1: - return filter[nb].Pfreq; - break; - case 2: - return filter[nb].Pgain; - break; - case 3: - return filter[nb].Pq; - break; - case 4: - return filter[nb].Pstages; - break; + case 0: + return filter[nb].Ptype; + break; + case 1: + return filter[nb].Pfreq; + break; + case 2: + return filter[nb].Pgain; + break; + case 3: + return filter[nb].Pq; + break; + case 4: + return filter[nb].Pstages; + break; } return 0; //in case of bogus parameter number @@ -210,4 +210,3 @@ float EQ::getfreqresponse(float freq) } return rap2dB(resp * outvolume); } - diff --git a/src/Effects/EQ.h b/src/Effects/EQ.h index b4dad45b..cef15151 100644 --- a/src/Effects/EQ.h +++ b/src/Effects/EQ.h @@ -54,4 +54,3 @@ class EQ:public Effect #endif - diff --git a/src/Effects/Echo.cpp b/src/Effects/Echo.cpp index 0c964a81..b2dd4076 100644 --- a/src/Effects/Echo.cpp +++ b/src/Effects/Echo.cpp @@ -53,8 +53,8 @@ Echo::~Echo() */ void Echo::cleanup() { - memset(delay.l,0,MAX_DELAY*SAMPLE_RATE*sizeof(float)); - memset(delay.r,0,MAX_DELAY*SAMPLE_RATE*sizeof(float)); + memset(delay.l, 0, MAX_DELAY * SAMPLE_RATE * sizeof(float)); + memset(delay.r, 0, MAX_DELAY * SAMPLE_RATE * sizeof(float)); old = Stereo(0.0f); } @@ -75,8 +75,8 @@ void Echo::initdelays() //number of seconds to delay right chan float dr = avgDelay + lrdelay; - ndelta.l = max(1,(int) (dl * SAMPLE_RATE)); - ndelta.r = max(1,(int) (dr * SAMPLE_RATE)); + ndelta.l = max(1, (int) (dl * SAMPLE_RATE)); + ndelta.r = max(1, (int) (dr * SAMPLE_RATE)); } void Echo::out(const Stereo &input) @@ -96,20 +96,28 @@ void Echo::out(const Stereo &input) rdl = input.r[i] * pangainR - rdl * fb; //LowPass Filter - old.l = delay.l[(pos.l+delta.l)%(MAX_DELAY * SAMPLE_RATE)] = ldl * hidamp + old.l * (1.0f - hidamp); - old.r = delay.r[(pos.r+delta.r)%(MAX_DELAY * SAMPLE_RATE)] = rdl * hidamp + old.r * (1.0f - hidamp); + old.l = + delay.l[(pos.l + + delta.l) + % (MAX_DELAY + * SAMPLE_RATE)] = ldl * hidamp + old.l * (1.0f - hidamp); + old.r = + delay.r[(pos.r + + delta.r) + % (MAX_DELAY + * SAMPLE_RATE)] = rdl * hidamp + old.r * (1.0f - hidamp); //increment - ++pos.l;// += delta.l; - ++pos.r;// += delta.r; + ++pos.l; // += delta.l; + ++pos.r; // += delta.r; //ensure that pos is still in bounds pos.l %= MAX_DELAY * SAMPLE_RATE; pos.r %= MAX_DELAY * SAMPLE_RATE; //adjust delay if needed - delta.l = (15*delta.l + ndelta.l)/16; - delta.r = (15*delta.r + ndelta.r)/16; + delta.l = (15 * delta.l + ndelta.l) / 16; + delta.r = (15 * delta.r + ndelta.r) / 16; } } @@ -133,8 +141,8 @@ void Echo::setvolume(unsigned char Pvolume) void Echo::setdelay(unsigned char Pdelay) { - this->Pdelay=Pdelay; - avgDelay=(Pdelay/127.0f*1.5f);//0 .. 1.5f sec + this->Pdelay = Pdelay; + avgDelay = (Pdelay / 127.0f * 1.5f); //0 .. 1.5f sec initdelays(); } @@ -169,23 +177,23 @@ void Echo::setpreset(unsigned char npreset) const int NUM_PRESETS = 9; unsigned char presets[NUM_PRESETS][PRESET_SIZE] = { //Echo 1 - {67, 64, 35, 64, 30, 59, 0 }, + {67, 64, 35, 64, 30, 59, 0 }, //Echo 2 - {67, 64, 21, 64, 30, 59, 0 }, + {67, 64, 21, 64, 30, 59, 0 }, //Echo 3 - {67, 75, 60, 64, 30, 59, 10 }, + {67, 75, 60, 64, 30, 59, 10 }, //Simple Echo - {67, 60, 44, 64, 30, 0, 0 }, + {67, 60, 44, 64, 30, 0, 0 }, //Canyon - {67, 60, 102, 50, 30, 82, 48 }, + {67, 60, 102, 50, 30, 82, 48 }, //Panning Echo 1 - {67, 64, 44, 17, 0, 82, 24 }, + {67, 64, 44, 17, 0, 82, 24 }, //Panning Echo 2 - {81, 60, 46, 118, 100, 68, 18 }, + {81, 60, 46, 118, 100, 68, 18 }, //Panning Echo 3 - {81, 60, 26, 100, 127, 67, 36 }, + {81, 60, 26, 100, 127, 67, 36 }, //Feedback Echo - {62, 64, 28, 64, 100, 90, 55 } + {62, 64, 28, 64, 100, 90, 55 } }; diff --git a/src/Effects/Echo.h b/src/Effects/Echo.h index f1b81b3d..6dc3a529 100644 --- a/src/Effects/Echo.h +++ b/src/Effects/Echo.h @@ -99,11 +99,11 @@ class Echo:public Effect void setdryonly(); private: //Parameters - char Pvolume; /**<#1 Volume or Dry/Wetness*/ - char Pdelay; /**<#3 Delay of the Echo*/ - char Plrdelay; /**<#4 L/R delay difference*/ - char Pfb; /**<#6Feedback*/ - char Phidamp; /**<#7Dampening of the Echo*/ + char Pvolume; /**<#1 Volume or Dry/Wetness*/ + char Pdelay; /**<#3 Delay of the Echo*/ + char Plrdelay; /**<#4 L/R delay difference*/ + char Pfb; /**<#6Feedback*/ + char Phidamp; /**<#7Dampening of the Echo*/ void setvolume(unsigned char Pvolume); void setdelay(unsigned char Pdelay); @@ -115,13 +115,13 @@ class Echo:public Effect float fb, hidamp; //Left/Right delay lengths Stereo delayTime; - float lrdelay; - float avgDelay; + float lrdelay; + float avgDelay; void initdelays(); //2 channel ring buffer Stereo delay; - Stereo old; + Stereo old; //position of reading/writing from delaysample Stereo pos; @@ -131,4 +131,3 @@ class Echo:public Effect }; #endif - diff --git a/src/Effects/Effect.cpp b/src/Effects/Effect.cpp index 29bb451f..74b5d58d 100644 --- a/src/Effects/Effect.cpp +++ b/src/Effects/Effect.cpp @@ -29,12 +29,12 @@ Effect::Effect(bool insertion_, float *const efxoutl_, float *const efxoutr_, FilterParams *filterpars_, const unsigned char &Ppreset_) :Ppreset(Ppreset_), efxoutl(efxoutl_), efxoutr(efxoutr_), - filterpars(filterpars_), insertion(insertion_) + filterpars(filterpars_), insertion(insertion_) {} void Effect::out(float *const smpsl, float *const smpsr) { - out(Stereo(smpsl,smpsr)); + out(Stereo(smpsl, smpsr)); } void Effect::crossover(float &a, float &b, float crossover) @@ -56,5 +56,5 @@ void Effect::setpanning(char Ppanning_) void Effect::setlrcross(char Plrcross_) { Plrcross = Plrcross_; - lrcross = (float)Plrcross / 127.0f; + lrcross = (float)Plrcross / 127.0f; } diff --git a/src/Effects/Effect.h b/src/Effects/Effect.h index 550238a8..bfdc7da1 100644 --- a/src/Effects/Effect.h +++ b/src/Effects/Effect.h @@ -82,9 +82,9 @@ class Effect return freq; } - unsigned char Ppreset; /***/ float outvolume;/** 0.0f) && (x < 0.25f)) - out = 4.0f * x; - else - if((x > 0.25f) && (x < 0.75f)) - out = 2 - 4 * x; - else - out = 4.0f * x - 4.0f; - break; - /**\todo more to be added here; also ::updateparams() need to be updated (to allow more lfotypes)*/ - default: - out = cosf(x * 2 * PI); //EffectLFO_SINE + case 1: //EffectLFO_TRIANGLE + if((x > 0.0f) && (x < 0.25f)) + out = 4.0f * x; + else + if((x > 0.25f) && (x < 0.75f)) + out = 2 - 4 * x; + else + out = 4.0f * x - 4.0f; + break; + /**\todo more to be added here; also ::updateparams() need to be updated (to allow more lfotypes)*/ + default: + out = cosf(x * 2 * PI); //EffectLFO_SINE } return out; } @@ -113,10 +113,10 @@ void EffectLFO::effectlfoout(float *outl, float *outr) } *outl = (out + 1.0f) * 0.5f; - out = getlfoshape(xr); + out = getlfoshape(xr); if((lfotype == 0) || (lfotype == 1)) out *= (ampr1 + xr * (ampr2 - ampr1)); - xr += incx; + xr += incx; if(xr > 1.0f) { xr -= 1.0f; ampr1 = ampr2; @@ -124,4 +124,3 @@ void EffectLFO::effectlfoout(float *outl, float *outr) } *outr = (out + 1.0f) * 0.5f; } - diff --git a/src/Effects/EffectLFO.h b/src/Effects/EffectLFO.h index 1674be17..22c71856 100644 --- a/src/Effects/EffectLFO.h +++ b/src/Effects/EffectLFO.h @@ -45,9 +45,8 @@ class EffectLFO float ampl1, ampl2, ampr1, ampr2; //necessary for "randomness" float lfointensity; float lfornd; - char lfotype; /**\todo GET RID OF CHAR (replace with short or enum)*/ + char lfotype; /**\todo GET RID OF CHAR (replace with short or enum)*/ }; #endif - diff --git a/src/Effects/EffectMgr.cpp b/src/Effects/EffectMgr.cpp index edddf7bc..c5afd967 100644 --- a/src/Effects/EffectMgr.cpp +++ b/src/Effects/EffectMgr.cpp @@ -89,34 +89,34 @@ void EffectMgr::changeeffect(int nefx_) if(efx != NULL) delete efx; switch(nefx) { /**\todo replace leaky abstraction*/ - case 1: - efx = new Reverb(insertion, efxoutl, efxoutr); - break; - case 2: - efx = new Echo(insertion, efxoutl, efxoutr); - break; - case 3: - efx = new Chorus(insertion, efxoutl, efxoutr); - break; - case 4: - efx = new Phaser(insertion, efxoutl, efxoutr); - break; - case 5: - efx = new Alienwah(insertion, efxoutl, efxoutr); - break; - case 6: - efx = new Distorsion(insertion, efxoutl, efxoutr); - break; - case 7: - efx = new EQ(insertion, efxoutl, efxoutr); - break; - case 8: - efx = new DynamicFilter(insertion, efxoutl, efxoutr); - break; - //put more effect here - default: - efx = NULL; - break; //no effect (thru) + case 1: + efx = new Reverb(insertion, efxoutl, efxoutr); + break; + case 2: + efx = new Echo(insertion, efxoutl, efxoutr); + break; + case 3: + efx = new Chorus(insertion, efxoutl, efxoutr); + break; + case 4: + efx = new Phaser(insertion, efxoutl, efxoutr); + break; + case 5: + efx = new Alienwah(insertion, efxoutl, efxoutr); + break; + case 6: + efx = new Distorsion(insertion, efxoutl, efxoutr); + break; + case 7: + efx = new EQ(insertion, efxoutl, efxoutr); + break; + case 8: + efx = new DynamicFilter(insertion, efxoutl, efxoutr); + break; + //put more effect here + default: + efx = NULL; + break; //no effect (thru) } if(efx != NULL) @@ -254,29 +254,26 @@ void EffectMgr::out(float *smpsl, float *smpsr) if((nefx == 1) || (nefx == 2)) v2 *= v2; //for Reverb and Echo, the wet function is not liniar - if(dryonly) { //this is used for instrument effect only + if(dryonly) //this is used for instrument effect only for(i = 0; i < SOUND_BUFFER_SIZE; ++i) { smpsl[i] *= v1; smpsr[i] *= v1; efxoutl[i] *= v2; efxoutr[i] *= v2; } - } - else { //normal instrument/insertion effect + else //normal instrument/insertion effect for(i = 0; i < SOUND_BUFFER_SIZE; ++i) { smpsl[i] = smpsl[i] * v1 + efxoutl[i] * v2; smpsr[i] = smpsr[i] * v1 + efxoutr[i] * v2; } - } } - else { //System effect + else //System effect for(i = 0; i < SOUND_BUFFER_SIZE; ++i) { efxoutl[i] *= 2.0f * volume; efxoutr[i] *= 2.0f * volume; smpsl[i] = efxoutl[i]; smpsr[i] = efxoutr[i]; } - } } /* @@ -354,14 +351,12 @@ void EffectMgr::getfromXML(XMLwrapper *xml) seteffectpar_nolock(n, xml->getpar127("par", par)); xml->exitbranch(); } - if(filterpars != NULL) { + if(filterpars != NULL) if(xml->enterbranch("FILTER")) { filterpars->getfromXML(xml); xml->exitbranch(); } - } xml->exitbranch(); } cleanup(); } - diff --git a/src/Effects/EffectMgr.h b/src/Effects/EffectMgr.h index 09828333..2f579534 100644 --- a/src/Effects/EffectMgr.h +++ b/src/Effects/EffectMgr.h @@ -85,7 +85,7 @@ class EffectMgr:public Presets void seteffectpar_nolock(int npar, unsigned char value); unsigned char geteffectpar(int npar); const bool insertion; /**<1 if the effect is connected as insertion effect*/ - float *efxoutl, *efxoutr; + float *efxoutl, *efxoutr; /**used by UI * \todo needs to be decoupled*/ @@ -101,4 +101,3 @@ class EffectMgr:public Presets }; #endif - diff --git a/src/Effects/Phaser.cpp b/src/Effects/Phaser.cpp index 4352cf51..e4f694b5 100644 --- a/src/Effects/Phaser.cpp +++ b/src/Effects/Phaser.cpp @@ -41,7 +41,7 @@ using namespace std; Phaser::Phaser(const int &insertion_, float *efxoutl_, float *efxoutr_) :Effect(insertion_, efxoutl_, efxoutr_, NULL, 0), old(NULL), xn1(NULL), - yn1(NULL), diff(0.0f), oldgain(0.0f), fb(0.0f) + yn1(NULL), diff(0.0f), oldgain(0.0f), fb(0.0f) { analog_setup(); setpreset(Ppreset); @@ -51,28 +51,28 @@ Phaser::Phaser(const int &insertion_, float *efxoutl_, float *efxoutr_) void Phaser::analog_setup() { //model mismatch between JFET devices - offset[0] = -0.2509303f; - offset[1] = 0.9408924f; - offset[2] = 0.998f; - offset[3] = -0.3486182f; - offset[4] = -0.2762545f; - offset[5] = -0.5215785f; - offset[6] = 0.2509303f; - offset[7] = -0.9408924f; - offset[8] = -0.998f; - offset[9] = 0.3486182f; + offset[0] = -0.2509303f; + offset[1] = 0.9408924f; + offset[2] = 0.998f; + offset[3] = -0.3486182f; + offset[4] = -0.2762545f; + offset[5] = -0.5215785f; + offset[6] = 0.2509303f; + offset[7] = -0.9408924f; + offset[8] = -0.998f; + offset[9] = 0.3486182f; offset[10] = 0.2762545f; offset[11] = 0.5215785f; barber = 0; //Deactivate barber pole phasing by default - mis = 1.0f; - Rmin = 625.0f;// 2N5457 typical on resistance at Vgs = 0 - Rmax = 22000.0f;// Resistor parallel to FET - Rmx = Rmin/Rmax; - Rconst = 1.0f + Rmx; // Handle parallel resistor relationship - C = 0.00000005f; // 50 nF - CFs = (float) 2.0f*(float)SAMPLE_RATE*C; + mis = 1.0f; + Rmin = 625.0f; // 2N5457 typical on resistance at Vgs = 0 + Rmax = 22000.0f; // Resistor parallel to FET + Rmx = Rmin / Rmax; + Rconst = 1.0f + Rmx; // Handle parallel resistor relationship + C = 0.00000005f; // 50 nF + CFs = (float) 2.0f * (float)SAMPLE_RATE * C; invperiod = 1.0f / ((float) SOUND_BUFFER_SIZE); } @@ -101,11 +101,12 @@ void Phaser::out(const Stereo &input) void Phaser::AnalogPhase(const Stereo &input) { - Stereo gain(0.0f), lfoVal(0.0f), mod(0.0f), g(0.0f), b(0.0f), hpf(0.0f); + Stereo gain(0.0f), lfoVal(0.0f), mod(0.0f), g(0.0f), b(0.0f), hpf( + 0.0f); lfo.effectlfoout(&lfoVal.l, &lfoVal.r); - mod.l = lfoVal.l*width + (depth - 0.5f); - mod.r = lfoVal.r*width + (depth - 0.5f); + mod.l = lfoVal.l * width + (depth - 0.5f); + mod.r = lfoVal.r * width + (depth - 0.5f); mod.l = limit(mod.l, ZERO_, ONE_); mod.r = limit(mod.r, ZERO_, ONE_); @@ -128,13 +129,13 @@ void Phaser::AnalogPhase(const Stereo &input) g = oldgain; oldgain = mod; - for (int i = 0; i < SOUND_BUFFER_SIZE; ++i) { - g.l += diff.l;// Linear interpolation between LFO samples + for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { + g.l += diff.l; // Linear interpolation between LFO samples g.r += diff.r; Stereo xn(input.l[i] * pangainL, input.r[i] * pangainR); - if (barber) { + if(barber) { g.l = fmodf((g.l + 0.25f), ONE_); g.r = fmodf((g.r + 0.25f), ONE_); } @@ -156,29 +157,29 @@ void Phaser::AnalogPhase(const Stereo &input) } float Phaser::applyPhase(float x, float g, float fb, - float &hpf, float *yn1, float *xn1) + float &hpf, float *yn1, float *xn1) { for(int j = 0; j < Pstages; ++j) { //Phasing routine - mis = 1.0f + offsetpct*offset[j]; + mis = 1.0f + offsetpct * offset[j]; //This is symmetrical. //FET is not, so this deviates slightly, however sym dist. is //better sounding than a real FET. - float d = (1.0f + 2.0f*(0.25f + g)*hpf*hpf*distortion) * mis; - Rconst = 1.0f + mis*Rmx; + float d = (1.0f + 2.0f * (0.25f + g) * hpf * hpf * distortion) * mis; + Rconst = 1.0f + mis * Rmx; // This is 1/R. R is being modulated to control filter fc. - float b = (Rconst - g)/ (d*Rmin); - float gain = (CFs - b)/(CFs + b); + float b = (Rconst - g) / (d * Rmin); + float gain = (CFs - b) / (CFs + b); yn1[j] = gain * (x + yn1[j]) - xn1[j]; //high pass filter: //Distortion depends on the high-pass part of the AP stage. - hpf = yn1[j] + (1.0f-gain)*xn1[j]; + hpf = yn1[j] + (1.0f - gain) * xn1[j]; xn1[j] = x; - x = yn1[j]; - if (j==1) + x = yn1[j]; + if(j == 1) x += fb; //Insert feedback after first phase stage } return x; @@ -188,8 +189,12 @@ void Phaser::normalPhase(const Stereo &input) Stereo gain(0.0f), lfoVal(0.0f); lfo.effectlfoout(&lfoVal.l, &lfoVal.r); - gain.l = (expf(lfoVal.l * PHASER_LFO_SHAPE) - 1) / (expf(PHASER_LFO_SHAPE) - 1.0f); - gain.r = (expf(lfoVal.r * PHASER_LFO_SHAPE) - 1) / (expf(PHASER_LFO_SHAPE) - 1.0f); + gain.l = + (expf(lfoVal.l + * PHASER_LFO_SHAPE) - 1) / (expf(PHASER_LFO_SHAPE) - 1.0f); + gain.r = + (expf(lfoVal.r + * PHASER_LFO_SHAPE) - 1) / (expf(PHASER_LFO_SHAPE) - 1.0f); gain.l = 1.0f - phase * (1.0f - depth) - (1.0f - phase) * gain.l * depth; gain.r = 1.0f - phase * (1.0f - depth) - (1.0f - phase) * gain.r * depth; @@ -198,14 +203,14 @@ void Phaser::normalPhase(const Stereo &input) gain.r = limit(gain.r, ZERO_, ONE_); for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { - float x = (float) i / SOUND_BUFFER_SIZE; - float x1 = 1.0f - x; + float x = (float) i / SOUND_BUFFER_SIZE; + float x1 = 1.0f - x; //TODO think about making panning an external feature Stereo xn(input.l[i] * pangainL + fb.l, - input.r[i] * pangainR + fb.r); + input.r[i] * pangainR + fb.r); Stereo g(gain.l * x + oldgain.l * x1, - gain.r * x + oldgain.r * x1); + gain.r * x + oldgain.r * x1); xn.l = applyPhase(xn.l, g.l, old.l); xn.r = applyPhase(xn.r, g.r, old.r); @@ -232,7 +237,7 @@ float Phaser::applyPhase(float x, float g, float *old) for(int j = 0; j < Pstages * 2; ++j) { //Phasing routine float tmp = old[j]; old[j] = g * tmp + x; - x = tmp - g *old[j]; + x = tmp - g * old[j]; } return x; } @@ -267,7 +272,7 @@ void Phaser::setwidth(unsigned char Pwidth) void Phaser::setfb(unsigned char Pfb) { this->Pfb = Pfb; - feedback = (float) (Pfb - 64) / 64.2f; + feedback = (float) (Pfb - 64) / 64.2f; } void Phaser::setvolume(unsigned char Pvolume) @@ -289,7 +294,7 @@ void Phaser::setdistortion(unsigned char Pdistortion) void Phaser::setoffset(unsigned char Poffset) { this->Poffset = Poffset; - offsetpct = (float)Poffset / 127.0f; + offsetpct = (float)Poffset / 127.0f; } void Phaser::setstages(unsigned char Pstages) @@ -307,13 +312,13 @@ void Phaser::setstages(unsigned char Pstages) this->Pstages = min(MAX_PHASER_STAGES, (int)Pstages); old = Stereo(new float[Pstages * 2], - new float[Pstages * 2]); + new float[Pstages * 2]); xn1 = Stereo(new float[Pstages], - new float[Pstages]); + new float[Pstages]); yn1 = Stereo(new float[Pstages], - new float[Pstages]); + new float[Pstages]); cleanup(); } @@ -333,25 +338,38 @@ void Phaser::setdepth(unsigned char Pdepth) void Phaser::setpreset(unsigned char npreset) { - const int PRESET_SIZE = 15; - const int NUM_PRESETS = 12; + const int PRESET_SIZE = 15; + const int NUM_PRESETS = 12; unsigned char presets[NUM_PRESETS][PRESET_SIZE] = { //Phaser //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 - {64, 64, 36, 0, 0, 64, 110, 64, 1, 0, 0, 20, 0, 0, 0}, - {64, 64, 35, 0, 0, 88, 40, 64, 3, 0, 0, 20, 0, 0, 0}, - {64, 64, 31, 0, 0, 66, 68, 107, 2, 0, 0, 20, 0, 0, 0}, - {39, 64, 22, 0, 0, 66, 67, 10, 5, 0, 1, 20, 0, 0, 0}, - {64, 64, 20, 0, 1, 110, 67, 78, 10, 0, 0, 20, 0, 0, 0}, - {64, 64, 53, 100, 0, 58, 37, 78, 3, 0, 0, 20, 0, 0, 0}, + {64, 64, 36, 0, 0, 64, 110, 64, 1, 0, 0, 20, + 0, 0, + 0 }, + {64, 64, 35, 0, 0, 88, 40, 64, 3, 0, 0, 20, 0, 0, + 0 }, + {64, 64, 31, 0, 0, 66, 68, 107, 2, 0, 0, 20, 0, 0, + 0 }, + {39, 64, 22, 0, 0, 66, 67, 10, 5, 0, 1, 20, 0, 0, + 0 }, + {64, 64, 20, 0, 1, 110, 67, 78, 10, 0, 0, 20, 0, 0, + 0 }, + {64, 64, 53, 100, 0, 58, 37, 78, 3, 0, 0, 20, 0, 0, + 0 }, //APhaser //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 - {64, 64, 14, 0, 1, 64, 64, 40, 4, 10, 0, 110, 1, 20, 1}, - {64, 64, 14, 5, 1, 64, 70, 40, 6, 10, 0, 110, 1, 20, 1}, - {64, 64, 9, 0, 0, 64, 60, 40, 8, 10, 0, 40, 0, 20, 1}, - {64, 64, 14, 10, 0, 64, 45, 80, 7, 10, 1, 110, 1, 20, 1}, - {25, 64, 127, 10, 0, 64, 25, 16, 8, 100, 0, 25, 0, 20, 1}, - {64, 64, 1, 10, 1, 64, 70, 40, 12, 10, 0, 110, 1, 20, 1} + {64, 64, 14, 0, 1, 64, 64, 40, 4, 10, 0, 110,1, 20, + 1 }, + {64, 64, 14, 5, 1, 64, 70, 40, 6, 10, 0, 110,1, 20, + 1 }, + {64, 64, 9, 0, 0, 64, 60, 40, 8, 10, 0, 40, 0, 20, + 1 }, + {64, 64, 14, 10, 0, 64, 45, 80, 7, 10, 1, 110,1, 20, + 1 }, + {25, 64, 127, 10, 0, 64, 25, 16, 8, 100, 0, 25, 0, 20, + 1 }, + {64, 64, 1, 10, 1, 64, 70, 40, 12, 10, 0, 110,1, 20, + 1 } }; if(npreset >= NUM_PRESETS) npreset = NUM_PRESETS - 1; @@ -401,7 +419,7 @@ void Phaser::changepar(int npar, unsigned char value) setoffset(value); break; case 10: - Poutsub = min((int)value,1); + Poutsub = min((int)value, 1); break; case 11: setphase(value); @@ -432,10 +450,10 @@ unsigned char Phaser::getpar(int npar) const case 7: return Pfb; case 8: return Pstages; case 9: return Plrcross; - return Poffset; //same + return Poffset; //same case 10: return Poutsub; case 11: return Pphase; - return Pwidth; //same + return Pwidth; //same case 12: return Phyper; case 13: return Pdistortion; case 14: return Panalog; diff --git a/src/Effects/Phaser.h b/src/Effects/Phaser.h index e9fec22d..dd8a400a 100644 --- a/src/Effects/Phaser.h +++ b/src/Effects/Phaser.h @@ -45,7 +45,7 @@ class Phaser:public Effect private: //Phaser parameters - EffectLFO lfo; //Phaser modulator + EffectLFO lfo; //Phaser modulator unsigned char Pvolume; //Used to set wet/dry mix unsigned char Pdistortion; //Model distortion added by FET element unsigned char Pdepth; //Depth of phaser sweep @@ -69,14 +69,14 @@ class Phaser:public Effect void setphase(unsigned char Pphase); //Internal Variables - bool barber; //Barber pole phasing flag + bool barber; //Barber pole phasing flag float distortion, width, offsetpct; float feedback, depth, phase; Stereo old, xn1, yn1; - Stereo diff, oldgain, fb; + Stereo diff, oldgain, fb; float invperiod; float offset[12]; - + float mis; float Rmin; // 3N5457 typical on resistance at Vgs = 0 float Rmax; // Resistor parallel to FET @@ -89,11 +89,10 @@ class Phaser:public Effect void AnalogPhase(const Stereo &input); //analog case float applyPhase(float x, float g, float fb, - float &hpf, float *yn1, float *xn1); + float &hpf, float *yn1, float *xn1); void normalPhase(const Stereo &input); float applyPhase(float x, float g, float *old); }; #endif - diff --git a/src/Effects/Reverb.cpp b/src/Effects/Reverb.cpp index 3f6c40eb..4d324616 100644 --- a/src/Effects/Reverb.cpp +++ b/src/Effects/Reverb.cpp @@ -125,12 +125,12 @@ void Reverb::processmono(int ch, float *output, float *inputbuf) for(int j = REV_COMBS * ch; j < REV_COMBS * (ch + 1); ++j) { int &ck = combk[j]; const int comblength = comblen[j]; - float &lpcombj = lpcomb[j]; + float &lpcombj = lpcomb[j]; for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { float fbout = comb[j][ck] * combfb[j]; - fbout = fbout * (1.0f - lohifb) + lpcombj * lohifb; - lpcombj = fbout; + fbout = fbout * (1.0f - lohifb) + lpcombj * lohifb; + lpcombj = fbout; comb[j][ck] = inputbuf[i] + fbout; output[i] += fbout; @@ -165,7 +165,7 @@ void Reverb::out(const Stereo &smp) for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) inputbuf[i] = (smp.l[i] + smp.r[i]) / 2.0f; - if(idelay != NULL) { + if(idelay != NULL) for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { //Initial delay r float tmp = inputbuf[i] + idelay[idelayk] * idelayfb; @@ -175,7 +175,6 @@ void Reverb::out(const Stereo &smp) if(idelayk >= idelaylen) idelayk = 0; } - } if(bandwidth) bandwidth->process(SOUND_BUFFER_SIZE, inputbuf); @@ -221,7 +220,7 @@ void Reverb::setvolume(unsigned char Pvolume) void Reverb::settime(unsigned char Ptime) { - int i; + int i; float t; this->Ptime = Ptime; t = powf(60.0f, (float)Ptime / 127.0f) - 0.97f; @@ -229,7 +228,7 @@ void Reverb::settime(unsigned char Ptime) for(i = 0; i < REV_COMBS * 2; ++i) combfb[i] = -expf((float)comblen[i] / (float)SAMPLE_RATE * logf(0.001f) / t); - //the feedback is negative because it removes the DC + //the feedback is negative because it removes the DC } void Reverb::setlohidamp(unsigned char Plohidamp) @@ -260,7 +259,7 @@ void Reverb::setidelay(unsigned char Pidelay) if(idelay != NULL) delete [] idelay; - idelay = NULL; + idelay = NULL; idelaylen = (int) (SAMPLE_RATE * delay / 1000); if(idelaylen > 1) { @@ -353,7 +352,7 @@ void Reverb::settype(unsigned char Ptype) lpcomb[i] = 0; if(comb[i] != NULL) delete [] comb[i]; - comb[i] = new float[comblen[i]]; + comb[i] = new float[comblen[i]]; } for(int i = 0; i < REV_APS * 2; ++i) { @@ -361,17 +360,17 @@ void Reverb::settype(unsigned char Ptype) tmp = 500 + (int)(RND * 500); else tmp = aptunings[Ptype][i % REV_APS]; - tmp *= roomsize; + tmp *= roomsize; if(i > REV_APS) tmp += 23.0f; - tmp *= SAMPLE_RATE / 44100.0f; //adjust the combs according to the samplerate + tmp *= SAMPLE_RATE / 44100.0f; //adjust the combs according to the samplerate if(tmp < 10) tmp = 10; aplen[i] = (int) tmp; apk[i] = 0; if(ap[i] != NULL) delete [] ap[i]; - ap[i] = new float[aplen[i]]; + ap[i] = new float[aplen[i]]; } settime(Ptime); cleanup(); @@ -412,31 +411,31 @@ void Reverb::setpreset(unsigned char npreset) const int NUM_PRESETS = 13; unsigned char presets[NUM_PRESETS][PRESET_SIZE] = { //Cathedral1 - {80, 64, 63, 24, 0, 0, 0, 85, 5, 83, 1, 64, 20 }, + {80, 64, 63, 24, 0, 0, 0, 85, 5, 83, 1, 64, 20 }, //Cathedral2 - {80, 64, 69, 35, 0, 0, 0, 127, 0, 71, 0, 64, 20 }, + {80, 64, 69, 35, 0, 0, 0, 127, 0, 71, 0, 64, 20 }, //Cathedral3 - {80, 64, 69, 24, 0, 0, 0, 127, 75, 78, 1, 85, 20 }, + {80, 64, 69, 24, 0, 0, 0, 127, 75, 78, 1, 85, 20 }, //Hall1 - {90, 64, 51, 10, 0, 0, 0, 127, 21, 78, 1, 64, 20 }, + {90, 64, 51, 10, 0, 0, 0, 127, 21, 78, 1, 64, 20 }, //Hall2 - {90, 64, 53, 20, 0, 0, 0, 127, 75, 71, 1, 64, 20 }, + {90, 64, 53, 20, 0, 0, 0, 127, 75, 71, 1, 64, 20 }, //Room1 - {100, 64, 33, 0, 0, 0, 0, 127, 0, 106, 0, 30, 20 }, + {100, 64, 33, 0, 0, 0, 0, 127, 0, 106, 0, 30, 20 }, //Room2 - {100, 64, 21, 26, 0, 0, 0, 62, 0, 77, 1, 45, 20 }, + {100, 64, 21, 26, 0, 0, 0, 62, 0, 77, 1, 45, 20 }, //Basement - {110, 64, 14, 0, 0, 0, 0, 127, 5, 71, 0, 25, 20 }, + {110, 64, 14, 0, 0, 0, 0, 127, 5, 71, 0, 25, 20 }, //Tunnel - {85, 80, 84, 20, 42, 0, 0, 51, 0, 78, 1, 105, 20 }, + {85, 80, 84, 20, 42, 0, 0, 51, 0, 78, 1, 105, 20 }, //Echoed1 - {95, 64, 26, 60, 71, 0, 0, 114, 0, 64, 1, 64, 20 }, + {95, 64, 26, 60, 71, 0, 0, 114, 0, 64, 1, 64, 20 }, //Echoed2 - {90, 64, 40, 88, 71, 0, 0, 114, 0, 88, 1, 64, 20 }, + {90, 64, 40, 88, 71, 0, 0, 114, 0, 88, 1, 64, 20 }, //VeryLong1 - {90, 64, 93, 15, 0, 0, 0, 114, 0, 77, 0, 95, 20 }, + {90, 64, 93, 15, 0, 0, 0, 114, 0, 77, 0, 95, 20 }, //VeryLong2 - {90, 64, 111, 30, 0, 0, 0, 114, 90, 74, 1, 80, 20 } + {90, 64, 111, 30, 0, 0, 0, 114, 90, 74, 1, 80, 20 } }; if(npreset >= NUM_PRESETS) diff --git a/src/Effects/Reverb.h b/src/Effects/Reverb.h index 979d6e24..52a71a86 100644 --- a/src/Effects/Reverb.h +++ b/src/Effects/Reverb.h @@ -99,19 +99,19 @@ class Reverb:public Effect float erbalance; //Parameters - int lohidamptype; /**<0=disable,1=highdamp(lowpass),2=lowdamp(highpass)*/ - int idelaylen, rdelaylen; - int idelayk; - float lohifb, idelayfb, roomsize, rs; //rs is used to "normalise" the volume according to the roomsize - int comblen[REV_COMBS * 2]; - int aplen[REV_APS * 2]; - Unison *bandwidth; + int lohidamptype; /**<0=disable,1=highdamp(lowpass),2=lowdamp(highpass)*/ + int idelaylen, rdelaylen; + int idelayk; + float lohifb, idelayfb, roomsize, rs; //rs is used to "normalise" the volume according to the roomsize + int comblen[REV_COMBS * 2]; + int aplen[REV_APS * 2]; + Unison *bandwidth; //Internal Variables float *comb[REV_COMBS * 2]; - int combk[REV_COMBS * 2]; + int combk[REV_COMBS * 2]; float combfb[REV_COMBS * 2]; /**::operator++() } template -T Atomic::operator--(){ +T Atomic::operator--() { T tmp; pthread_mutex_lock(&mutex); tmp = --value; diff --git a/src/Misc/Atomic.h b/src/Misc/Atomic.h index 7baa1725..d49dd7d5 100644 --- a/src/Misc/Atomic.h +++ b/src/Misc/Atomic.h @@ -43,4 +43,3 @@ class Atomic }; #include "Atomic.cpp" #endif - diff --git a/src/Misc/Bank.cpp b/src/Misc/Bank.cpp index e9ba7f73..50ea8fd4 100644 --- a/src/Misc/Bank.cpp +++ b/src/Misc/Bank.cpp @@ -88,7 +88,7 @@ void Bank::setname(unsigned int ninstrument, const string &newname, int newslot) return; string newfilename; - char tmpfilename[100 + 1]; + char tmpfilename[100 + 1]; if(newslot >= 0) snprintf(tmpfilename, 100, "%4d-%s", newslot + 1, newname.c_str()); @@ -105,7 +105,7 @@ void Bank::setname(unsigned int ninstrument, const string &newname, int newslot) rename(ins[ninstrument].filename.c_str(), newfilename.c_str()); ins[ninstrument].filename = newfilename; - ins[ninstrument].name = legalizeFilename(tmpfilename); //TODO limit name to PART_MAX_NAME_LEN + ins[ninstrument].name = legalizeFilename(tmpfilename); //TODO limit name to PART_MAX_NAME_LEN } /* @@ -222,12 +222,11 @@ int Bank::loadbank(string bankdirname) string name = filename; //remove the file extension - for(int i = name.size() - 1; i >= 2; i--) { + for(int i = name.size() - 1; i >= 2; i--) if(name[i] == '.') { - name = name.substr(0,i); + name = name.substr(0, i); break; } - } if(no != 0) //the instrument position in the bank is found addtobank(no - 1, filename, name.substr(startname)); @@ -298,7 +297,7 @@ void Bank::swapslot(unsigned int n1, unsigned int n2) setname(n1, getname(n1), n2); setname(n2, getname(n2), n1); - swap(ins[n2],ins[n1]); + swap(ins[n2], ins[n1]); } } @@ -326,11 +325,12 @@ void Bank::rescanforbanks() //remove duplicate bank names int dupl = 0; - for(int j = 0; j < (int) banks.size() - 1; ++j) { - for(int i = j + 1; i <(int) banks.size(); ++i) { + for(int j = 0; j < (int) banks.size() - 1; ++j) + for(int i = j + 1; i < (int) banks.size(); ++i) { if(banks[i].name == banks[j].name) { //add a [1] to the first bankname and [n] to others - banks[i].name = banks[i].name + '[' + stringFrom(dupl +2) + ']'; + banks[i].name = banks[i].name + '[' + + stringFrom(dupl + 2) + ']'; if(dupl == 0) banks[j].name += "[1]"; @@ -339,7 +339,6 @@ void Bank::rescanforbanks() else dupl = 0; } - } } @@ -366,12 +365,12 @@ void Bank::scanrootdir(string rootdir) if(dirname[0] == '.') continue; - bank.dir = rootdir + separator + dirname + '/'; + bank.dir = rootdir + separator + dirname + '/'; bank.name = dirname; //find out if the directory contains at least 1 instrument bool isbank = false; - DIR *d = opendir(bank.dir.c_str()); + DIR *d = opendir(bank.dir.c_str()); if(d == NULL) continue; @@ -410,26 +409,24 @@ int Bank::addtobank(int pos, string filename, string name) pos = -1; //force it to find a new free position } else - if(pos >= BANK_SIZE) - pos = -1; + if(pos >= BANK_SIZE) + pos = -1; - if(pos < 0) { //find a free position - for(int i = BANK_SIZE - 1; i >= 0; i--) { + if(pos < 0) //find a free position + for(int i = BANK_SIZE - 1; i >= 0; i--) if(!ins[i].used) { pos = i; break; } - } - } if(pos < 0) - return -1;//the bank is full + return -1; //the bank is full deletefrombank(pos); - ins[pos].used = true; - ins[pos].name = name; + ins[pos].used = true; + ins[pos].name = name; ins[pos].filename = dirname + '/' + filename; //see if PADsynth is used @@ -466,4 +463,3 @@ Bank::ins_t::ins_t() { info.PADsynth_used = false; } - diff --git a/src/Misc/Bank.h b/src/Misc/Bank.h index 99157728..d7a794c1 100644 --- a/src/Misc/Bank.h +++ b/src/Misc/Bank.h @@ -42,7 +42,9 @@ class Bank ~Bank(); std::string getname(unsigned int ninstrument); std::string getnamenumbered(unsigned int ninstrument); - void setname(unsigned int ninstrument, const std::string &newname, int newslot); //if newslot==-1 then this is ignored, else it will be put on that slot + void setname(unsigned int ninstrument, + const std::string &newname, + int newslot); //if newslot==-1 then this is ignored, else it will be put on that slot bool isPADsynth_used(unsigned int ninstrument); /**returns true when slot is empty*/ @@ -89,7 +91,7 @@ class Bank struct ins_t { ins_t(); - bool used; + bool used; std::string name; std::string filename; struct { @@ -103,4 +105,3 @@ class Bank }; #endif - diff --git a/src/Misc/Config.cpp b/src/Misc/Config.cpp index 5c4535ca..9e2a430f 100644 --- a/src/Misc/Config.cpp +++ b/src/Misc/Config.cpp @@ -36,29 +36,29 @@ void Config::init() { maxstringsize = MAX_STRING_SIZE; //for ui //defaults - cfg.SampleRate = 44100; - cfg.SoundBufferSize = 256; - cfg.OscilSize = 1024; - cfg.SwapStereo = 0; + cfg.SampleRate = 44100; + cfg.SoundBufferSize = 256; + cfg.OscilSize = 1024; + cfg.SwapStereo = 0; cfg.LinuxOSSWaveOutDev = new char[MAX_STRING_SIZE]; snprintf(cfg.LinuxOSSWaveOutDev, MAX_STRING_SIZE, "/dev/dsp"); - cfg.LinuxOSSSeqInDev = new char[MAX_STRING_SIZE]; + cfg.LinuxOSSSeqInDev = new char[MAX_STRING_SIZE]; snprintf(cfg.LinuxOSSSeqInDev, MAX_STRING_SIZE, "/dev/sequencer"); cfg.DumpFile = "zynaddsubfx_dump.txt"; - cfg.WindowsWaveOutId = 0; - cfg.WindowsMidiInId = 0; + cfg.WindowsWaveOutId = 0; + cfg.WindowsMidiInId = 0; - cfg.BankUIAutoClose = 0; - cfg.DumpNotesToFile = 0; - cfg.DumpAppend = 1; + cfg.BankUIAutoClose = 0; + cfg.DumpNotesToFile = 0; + cfg.DumpAppend = 1; - cfg.GzipCompression = 3; + cfg.GzipCompression = 3; - cfg.Interpolation = 0; - cfg.CheckPADsynth = 1; + cfg.Interpolation = 0; + cfg.CheckPADsynth = 1; cfg.UserInterfaceMode = 0; cfg.VirKeybLayout = 1; @@ -129,7 +129,7 @@ void Config::clearbankrootdirlist() void Config::clearpresetsdirlist() { for(int i = 0; i < MAX_BANK_ROOT_DIRS; ++i) - cfg.presetsDirList[i].clear(); + cfg.presetsDirList[i].clear(); } void Config::readConfig(const char *filename) @@ -138,96 +138,94 @@ void Config::readConfig(const char *filename) if(xmlcfg.loadXMLfile(filename) < 0) return; if(xmlcfg.enterbranch("CONFIGURATION")) { - cfg.SampleRate = xmlcfg.getpar("sample_rate", - cfg.SampleRate, - 4000, - 1024000); + cfg.SampleRate = xmlcfg.getpar("sample_rate", + cfg.SampleRate, + 4000, + 1024000); cfg.SoundBufferSize = xmlcfg.getpar("sound_buffer_size", - cfg.SoundBufferSize, - 16, - 8192); + cfg.SoundBufferSize, + 16, + 8192); cfg.OscilSize = xmlcfg.getpar("oscil_size", - cfg.OscilSize, - MAX_AD_HARMONICS * 2, - 131072); - cfg.SwapStereo = xmlcfg.getpar("swap_stereo", - cfg.SwapStereo, - 0, - 1); + cfg.OscilSize, + MAX_AD_HARMONICS * 2, + 131072); + cfg.SwapStereo = xmlcfg.getpar("swap_stereo", + cfg.SwapStereo, + 0, + 1); cfg.BankUIAutoClose = xmlcfg.getpar("bank_window_auto_close", - cfg.BankUIAutoClose, - 0, - 1); + cfg.BankUIAutoClose, + 0, + 1); cfg.DumpNotesToFile = xmlcfg.getpar("dump_notes_to_file", - cfg.DumpNotesToFile, - 0, - 1); - cfg.DumpAppend = xmlcfg.getpar("dump_append", - cfg.DumpAppend, - 0, - 1); + cfg.DumpNotesToFile, + 0, + 1); + cfg.DumpAppend = xmlcfg.getpar("dump_append", + cfg.DumpAppend, + 0, + 1); cfg.DumpFile = xmlcfg.getparstr("dump_file", ""); cfg.GzipCompression = xmlcfg.getpar("gzip_compression", - cfg.GzipCompression, - 0, - 9); + cfg.GzipCompression, + 0, + 9); cfg.currentBankDir = xmlcfg.getparstr("bank_current", ""); - cfg.Interpolation = xmlcfg.getpar("interpolation", + cfg.Interpolation = xmlcfg.getpar("interpolation", cfg.Interpolation, 0, 1); cfg.CheckPADsynth = xmlcfg.getpar("check_pad_synth", - cfg.CheckPADsynth, - 0, - 1); + cfg.CheckPADsynth, + 0, + 1); cfg.UserInterfaceMode = xmlcfg.getpar("user_interface_mode", - cfg.UserInterfaceMode, - 0, - 2); - cfg.VirKeybLayout = xmlcfg.getpar("virtual_keyboard_layout", - cfg.VirKeybLayout, - 0, - 10); + cfg.UserInterfaceMode, + 0, + 2); + cfg.VirKeybLayout = xmlcfg.getpar("virtual_keyboard_layout", + cfg.VirKeybLayout, + 0, + 10); //get bankroot dirs - for(int i = 0; i < MAX_BANK_ROOT_DIRS; ++i) { + for(int i = 0; i < MAX_BANK_ROOT_DIRS; ++i) if(xmlcfg.enterbranch("BANKROOT", i)) { cfg.bankRootDirList[i] = xmlcfg.getparstr("bank_root", ""); xmlcfg.exitbranch(); } - } //get preset root dirs - for(int i = 0; i < MAX_BANK_ROOT_DIRS; ++i) { + for(int i = 0; i < MAX_BANK_ROOT_DIRS; ++i) if(xmlcfg.enterbranch("PRESETSROOT", i)) { cfg.presetsDirList[i] = xmlcfg.getparstr("presets_root", ""); xmlcfg.exitbranch(); } - } //linux stuff xmlcfg.getparstr("linux_oss_wave_out_dev", - cfg.LinuxOSSWaveOutDev, - MAX_STRING_SIZE); + cfg.LinuxOSSWaveOutDev, + MAX_STRING_SIZE); xmlcfg.getparstr("linux_oss_seq_in_dev", - cfg.LinuxOSSSeqInDev, - MAX_STRING_SIZE); + cfg.LinuxOSSSeqInDev, + MAX_STRING_SIZE); //windows stuff cfg.WindowsWaveOutId = xmlcfg.getpar("windows_wave_out_id", - cfg.WindowsWaveOutId, - 0, - winwavemax); - cfg.WindowsMidiInId = xmlcfg.getpar("windows_midi_in_id", - cfg.WindowsMidiInId, - 0, - winmidimax); + cfg.WindowsWaveOutId, + 0, + winwavemax); + cfg.WindowsMidiInId = xmlcfg.getpar("windows_midi_in_id", + cfg.WindowsMidiInId, + 0, + winmidimax); xmlcfg.exitbranch(); } @@ -300,4 +298,3 @@ void Config::getConfigFileName(char *name, int namesize) name[0] = 0; snprintf(name, namesize, "%s%s", getenv("HOME"), "/.zynaddsubfxXML.cfg"); } - diff --git a/src/Misc/Config.h b/src/Misc/Config.h index 568fae1b..4b86390b 100644 --- a/src/Misc/Config.h +++ b/src/Misc/Config.h @@ -46,9 +46,9 @@ class Config std::string DumpFile; std::string bankRootDirList[MAX_BANK_ROOT_DIRS], currentBankDir; std::string presetsDirList[MAX_BANK_ROOT_DIRS]; - int CheckPADsynth; - int UserInterfaceMode; - int VirKeybLayout; + int CheckPADsynth; + int UserInterfaceMode; + int VirKeybLayout; std::string LinuxALSAaudioDev; std::string nameTag; } cfg; @@ -71,4 +71,3 @@ class Config void getConfigFileName(char *name, int namesize); }; #endif - diff --git a/src/Misc/Control.h b/src/Misc/Control.h index 297e6f0d..a605a66b 100644 --- a/src/Misc/Control.h +++ b/src/Misc/Control.h @@ -97,4 +97,3 @@ class ControlUser }; #endif /* _CONTROL_H_ */ - diff --git a/src/Misc/Dump.cpp b/src/Misc/Dump.cpp index cf39fc0f..8b34e05b 100644 --- a/src/Misc/Dump.cpp +++ b/src/Misc/Dump.cpp @@ -107,12 +107,12 @@ void Dump::dumpcontroller(char chan, unsigned int type, int par) if(file == NULL) return; switch(type) { - case C_pitchwheel: - fprintf(file, "P %d -> %d %d\n", tick, chan, par); - break; - default: - fprintf(file, "C %d -> %d %d %d\n", tick, chan, type, par); - break; + case C_pitchwheel: + fprintf(file, "P %d -> %d %d\n", tick, chan, par); + break; + default: + fprintf(file, "C %d -> %d %d %d\n", tick, chan, type, par); + break; } #ifndef JACKAUDIOOUT if(k++ > 25) { @@ -121,4 +121,3 @@ void Dump::dumpcontroller(char chan, unsigned int type, int par) } #endif } - diff --git a/src/Misc/Dump.h b/src/Misc/Dump.h index 392fd407..dc543cf0 100644 --- a/src/Misc/Dump.h +++ b/src/Misc/Dump.h @@ -61,4 +61,3 @@ class Dump int keyspressed; }; #endif - diff --git a/src/Misc/LASHClient.cpp b/src/Misc/LASHClient.cpp index d5b9a807..57979a32 100644 --- a/src/Misc/LASHClient.cpp +++ b/src/Misc/LASHClient.cpp @@ -101,4 +101,3 @@ void LASHClient::confirmevent(Event event) if(event == Restore) lash_send_event(client, lash_event_new_with_type(LASH_Restore_File)); } - diff --git a/src/Misc/LASHClient.h b/src/Misc/LASHClient.h index 6bf140cc..1f3a4946 100644 --- a/src/Misc/LASHClient.h +++ b/src/Misc/LASHClient.h @@ -61,4 +61,3 @@ class LASHClient #endif - diff --git a/src/Misc/Master.cpp b/src/Misc/Master.cpp index e03df9a2..c63156a5 100644 --- a/src/Misc/Master.cpp +++ b/src/Misc/Master.cpp @@ -44,7 +44,7 @@ Master::Master() pthread_mutex_init(&vumutex, NULL); fft = new FFTwrapper(OSCIL_SIZE); - shutup = 0; + shutup = 0; for(int npart = 0; npart < NUM_MIDI_PARTS; ++npart) { vuoutpeakpart[npart] = 1e-9; fakepeakpart[npart] = 0; @@ -99,8 +99,7 @@ void Master::defaults() bool Master::mutexLock(lockset request) { - switch (request) - { + switch(request) { case MUTEX_TRYLOCK: return !pthread_mutex_trylock(&mutex); case MUTEX_LOCK: @@ -123,13 +122,12 @@ Master &Master::getInstance() void Master::noteOn(char chan, char note, char velocity) { if(velocity) { - for(int npart = 0; npart < NUM_MIDI_PARTS; ++npart) { + for(int npart = 0; npart < NUM_MIDI_PARTS; ++npart) if(chan == part[npart]->Prcvchn) { fakepeakpart[npart] = velocity * 2; if(part[npart]->Penabled) part[npart]->NoteOn(note, velocity, keyshift); } - } } else this->noteOff(chan, note); @@ -159,16 +157,16 @@ void Master::setController(char chan, int type, int par) if(ctl.getnrpn(&parhi, &parlo, &valhi, &vallo) == 0) //this is NRPN //fprintf(stderr,"rcv. NRPN: %d %d %d %d\n",parhi,parlo,valhi,vallo); switch(parhi) { - case 0x04: //System Effects - if(parlo < NUM_SYS_EFX) - sysefx[parlo]->seteffectpar_nolock(valhi, vallo); - ; - break; - case 0x08: //Insertion Effects - if(parlo < NUM_INS_EFX) - insefx[parlo]->seteffectpar_nolock(valhi, vallo); - ; - break; + case 0x04: //System Effects + if(parlo < NUM_SYS_EFX) + sysefx[parlo]->seteffectpar_nolock(valhi, vallo); + ; + break; + case 0x08: //Insertion Effects + if(parlo < NUM_INS_EFX) + insefx[parlo]->seteffectpar_nolock(valhi, vallo); + ; + break; } ; } @@ -220,7 +218,7 @@ void Master::vuUpdate(const float *outl, const float *outr) vuoutpeakpart[npart] = 1.0e-12f; if(part[npart]->Penabled != 0) { float *outl = part[npart]->partoutl, - *outr = part[npart]->partoutr; + *outr = part[npart]->partoutr; for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { float tmp = fabs(outl[i] + outr[i]); if(tmp > vuoutpeakpart[npart]) @@ -229,8 +227,8 @@ void Master::vuUpdate(const float *outl, const float *outr) vuoutpeakpart[npart] *= volume; } else - if(fakepeakpart[npart] > 1) - fakepeakpart[npart]--; + if(fakepeakpart[npart] > 1) + fakepeakpart[npart]--; } } @@ -264,7 +262,7 @@ void Master::AudioOut(float *outl, float *outr) { //Swaps the Left channel with Right Channel if(swaplr) - swap(outl,outr); + swap(outl, outr); //clean up the output samples (should not be needed?) memset(outl, 0, sizeof(float) * SOUND_BUFFER_SIZE); @@ -276,14 +274,13 @@ void Master::AudioOut(float *outl, float *outr) part[npart]->ComputePartSmps(); //Insertion effects - for(int nefx = 0; nefx < NUM_INS_EFX; ++nefx) { + for(int nefx = 0; nefx < NUM_INS_EFX; ++nefx) if(Pinsparts[nefx] >= 0) { int efxpart = Pinsparts[nefx]; if(part[efxpart]->Penabled) insefx[nefx]->out(part[efxpart]->partoutl, part[efxpart]->partoutr); } - } //Apply the part volumes and pannings (after insertion effects) @@ -292,10 +289,10 @@ void Master::AudioOut(float *outl, float *outr) continue; Stereo newvol(part[npart]->volume), - oldvol(part[npart]->oldvolumel, - part[npart]->oldvolumer); + oldvol(part[npart]->oldvolumel, + part[npart]->oldvolumer); - float pan = part[npart]->panning; + float pan = part[npart]->panning; if(pan < 0.5f) newvol.l *= pan * 2.0f; else @@ -306,21 +303,20 @@ void Master::AudioOut(float *outl, float *outr) || ABOVE_AMPLITUDE_THRESHOLD(oldvol.r, newvol.r)) { for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { Stereo vol(INTERPOLATE_AMPLITUDE(oldvol.l, newvol.l, - i, SOUND_BUFFER_SIZE), - INTERPOLATE_AMPLITUDE(oldvol.r, newvol.r, - i, SOUND_BUFFER_SIZE)); + i, SOUND_BUFFER_SIZE), + INTERPOLATE_AMPLITUDE(oldvol.r, newvol.r, + i, SOUND_BUFFER_SIZE)); part[npart]->partoutl[i] *= vol.l; part[npart]->partoutr[i] *= vol.r; } part[npart]->oldvolumel = newvol.l; part[npart]->oldvolumer = newvol.r; } - else { + else for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { //the volume did not changed part[npart]->partoutl[i] *= newvol.l; part[npart]->partoutr[i] *= newvol.r; } - } } @@ -354,7 +350,7 @@ void Master::AudioOut(float *outl, float *outr) } // system effect send to next ones - for(int nefxfrom = 0; nefxfrom < nefx; ++nefxfrom) { + for(int nefxfrom = 0; nefxfrom < nefx; ++nefxfrom) if(Psysefxsend[nefxfrom][nefx] != 0) { const float vol = sysefxsend[nefxfrom][nefx]; for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { @@ -362,7 +358,6 @@ void Master::AudioOut(float *outl, float *outr) tmpmixr[i] += sysefx[nefxfrom]->efxoutr[i] * vol; } } - } sysefx[nefx]->out(tmpmixl, tmpmixr); @@ -378,14 +373,12 @@ void Master::AudioOut(float *outl, float *outr) } //Mix all parts - for(int npart = 0; npart < NUM_MIDI_PARTS; ++npart) { - if(part[npart]->Penabled) { //only mix active parts + for(int npart = 0; npart < NUM_MIDI_PARTS; ++npart) + if(part[npart]->Penabled) //only mix active parts for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { //the volume did not changed outl[i] += part[npart]->partoutl[i]; outr[i] += part[npart]->partoutr[i]; } - } - } //Insertion effects for Master Out for(int nefx = 0; nefx < NUM_INS_EFX; ++nefx) @@ -429,7 +422,7 @@ void Master::GetAudioOutSamples(size_t nsamples, float *outr) { static float *bufl = new float[SOUND_BUFFER_SIZE], - *bufr = new float[SOUND_BUFFER_SIZE]; + *bufr = new float[SOUND_BUFFER_SIZE]; static off_t off = 0; static size_t smps = 0; @@ -444,21 +437,22 @@ void Master::GetAudioOutSamples(size_t nsamples, while(nsamples) { //use all available samples if(nsamples >= smps) { - memcpy(outl+out_off, bufl+off, sizeof(float) * smps); - memcpy(outr+out_off, bufr+off, sizeof(float) * smps); + memcpy(outl + out_off, bufl + off, sizeof(float) * smps); + memcpy(outr + out_off, bufr + off, sizeof(float) * smps); //generate samples AudioOut(bufl, bufr); - off = 0; + off = 0; smps = SOUND_BUFFER_SIZE; out_off += smps; nsamples -= smps; - } else { //use some samples - memcpy(outl+out_off, bufl+off, sizeof(float) * nsamples); - memcpy(outr+out_off, bufr+off, sizeof(float) * nsamples); - smps -= nsamples; - off += nsamples; + } + else { //use some samples + memcpy(outl + out_off, bufl + off, sizeof(float) * nsamples); + memcpy(outr + out_off, bufr + off, sizeof(float) * nsamples); + smps -= nsamples; + off += nsamples; nsamples = 0; } } @@ -751,4 +745,3 @@ void Master::getfromXML(XMLwrapper *xml) xml->exitbranch(); } } - diff --git a/src/Misc/Master.h b/src/Misc/Master.h index 10d64c9d..0fe289f1 100644 --- a/src/Misc/Master.h +++ b/src/Misc/Master.h @@ -33,13 +33,15 @@ #include "Dump.h" #include "XMLwrapper.h" -typedef enum { MUTEX_TRYLOCK, MUTEX_LOCK, MUTEX_UNLOCK } lockset; +typedef enum { + MUTEX_TRYLOCK, MUTEX_LOCK, MUTEX_UNLOCK +} lockset; extern Dump dump; typedef struct vuData_t { float outpeakl, outpeakr, maxoutpeakl, maxoutpeakr, - rmspeakl, rmspeakr; + rmspeakl, rmspeakr; int clipped; } vuData; @@ -142,15 +144,15 @@ class Master //peaks for part VU-meters /**\todo synchronize this with a mutex*/ - float vuoutpeakpart[NUM_MIDI_PARTS]; + float vuoutpeakpart[NUM_MIDI_PARTS]; unsigned char fakepeakpart[NUM_MIDI_PARTS]; //this is used to compute the "peak" when the part is disabled Controller ctl; - bool swaplr; //if L and R are swapped + bool swaplr; //if L and R are swapped //other objects Microtonal microtonal; - Bank bank; + Bank bank; FFTwrapper *fft; pthread_mutex_t mutex; @@ -158,14 +160,13 @@ class Master private: - bool nullRun; + bool nullRun; vuData vu; - float volume; - float sysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS]; - float sysefxsend[NUM_SYS_EFX][NUM_SYS_EFX]; - int keyshift; + float volume; + float sysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS]; + float sysefxsend[NUM_SYS_EFX][NUM_SYS_EFX]; + int keyshift; }; #endif - diff --git a/src/Misc/Microtonal.cpp b/src/Misc/Microtonal.cpp index c81aa117..83da421d 100644 --- a/src/Misc/Microtonal.cpp +++ b/src/Misc/Microtonal.cpp @@ -37,11 +37,11 @@ void Microtonal::defaults() { Pinvertupdown = 0; Pinvertupdowncenter = 60; - octavesize = 12; - Penabled = 0; - PAnote = 69; - PAfreq = 440.0f; - Pscaleshift = 64; + octavesize = 12; + Penabled = 0; + PAnote = 69; + PAfreq = 440.0f; + Pscaleshift = 64; Pfirstkey = 0; Plastkey = 127; @@ -56,10 +56,10 @@ void Microtonal::defaults() octave[i].tuning = tmpoctave[i].tuning = powf( 2, (i % octavesize - + 1) / 12.0f); - octave[i].type = tmpoctave[i].type = 1; - octave[i].x1 = tmpoctave[i].x1 = (i % octavesize + 1) * 100; - octave[i].x2 = tmpoctave[i].x2 = 0; + + 1) / 12.0f); + octave[i].type = tmpoctave[i].type = 1; + octave[i].x1 = tmpoctave[i].x1 = (i % octavesize + 1) * 100; + octave[i].x2 = tmpoctave[i].x2 = 0; } octave[11].type = 2; octave[11].x1 = 2; @@ -106,12 +106,13 @@ float Microtonal::getnotefreq(int note, int keyshift) const note = (int) Pinvertupdowncenter * 2 - note; //compute global fine detune - float globalfinedetunerap = powf(2.0f, (Pglobalfinedetune - 64.0f) / 1200.0f); //-64.0f .. 63.0f cents + float globalfinedetunerap = powf(2.0f, + (Pglobalfinedetune - 64.0f) / 1200.0f); //-64.0f .. 63.0f cents if(Penabled == 0) return powf(2.0f, - (note - PAnote - + keyshift) / 12.0f) * PAfreq * globalfinedetunerap; //12tET + (note - PAnote + + keyshift) / 12.0f) * PAfreq * globalfinedetunerap; //12tET int scaleshift = ((int)Pscaleshift - 64 + (int) octavesize * 100) % octavesize; @@ -145,7 +146,8 @@ float Microtonal::getnotefreq(int note, int keyshift) const 0) ? (1.0f) : (octave[(deltanote - 1) % octavesize].tuning); if(deltanote != 0) rap_anote_middlenote *= - powf(octave[octavesize - 1].tuning, (deltanote - 1) / octavesize); + powf(octave[octavesize - 1].tuning, + (deltanote - 1) / octavesize); if(minus != 0) rap_anote_middlenote = 1.0f / rap_anote_middlenote; @@ -178,14 +180,14 @@ float Microtonal::getnotefreq(int note, int keyshift) const return freq * rap_keyshift; } else { //if the mapping is disabled - int nt = note - PAnote + scaleshift; - int ntkey = (nt + (int)octavesize * 100) % octavesize; - int ntoct = (nt - ntkey) / octavesize; + int nt = note - PAnote + scaleshift; + int ntkey = (nt + (int)octavesize * 100) % octavesize; + int ntoct = (nt - ntkey) / octavesize; float oct = octave[octavesize - 1].tuning; float freq = octave[(ntkey + octavesize - 1) % octavesize].tuning *powf(oct, - ntoct) + ntoct) * PAfreq; if(ntkey == 0) freq /= oct; @@ -254,7 +256,7 @@ bool Microtonal::operator!=(const Microtonal µ) const */ int Microtonal::linetotunings(unsigned int nline, const char *line) { - int x1 = -1, x2 = -1, type = -1; + int x1 = -1, x2 = -1, type = -1; float x = -1.0f, tmp, tuning = 1.0f; if(strstr(line, "/") == NULL) { if(strstr(line, ".") == NULL) { // M case (M=M/1) @@ -288,16 +290,16 @@ int Microtonal::linetotunings(unsigned int nline, const char *line) x = ((float) x1) / x2; } switch(type) { - case 1: - x1 = (int) floor(x); - tmp = fmod(x, 1.0f); - x2 = (int) (floor(tmp * 1e6)); - tuning = powf(2.0f, x / 1200.0f); - break; - case 2: - x = ((float)x1) / x2; - tuning = x; - break; + case 1: + x1 = (int) floor(x); + tmp = fmod(x, 1.0f); + x2 = (int) (floor(tmp * 1e6)); + tuning = powf(2.0f, x / 1200.0f); + break; + case 2: + x = ((float)x1) / x2; + tuning = x; + break; } tmpoctave[nline].tuning = tuning; @@ -684,4 +686,3 @@ int Microtonal::loadXML(const char *filename) delete (xml); return 0; } - diff --git a/src/Misc/Microtonal.h b/src/Misc/Microtonal.h index 64172c50..638a1590 100644 --- a/src/Misc/Microtonal.h +++ b/src/Misc/Microtonal.h @@ -132,4 +132,3 @@ class Microtonal }; #endif - diff --git a/src/Misc/Part.cpp b/src/Misc/Part.cpp index 0363020d..76c8d70d 100644 --- a/src/Misc/Part.cpp +++ b/src/Misc/Part.cpp @@ -38,10 +38,10 @@ Part::Part(Microtonal *microtonal_, FFTwrapper *fft_, pthread_mutex_t *mutex_) { microtonal = microtonal_; - fft = fft_; - mutex = mutex_; - partoutl = new float [SOUND_BUFFER_SIZE]; - partoutr = new float [SOUND_BUFFER_SIZE]; + fft = fft_; + mutex = mutex_; + partoutl = new float [SOUND_BUFFER_SIZE]; + partoutr = new float [SOUND_BUFFER_SIZE]; for(int n = 0; n < NUM_KIT_ITEMS; ++n) { kit[n].Pname = new unsigned char [PART_MAX_NAME_LEN]; @@ -81,7 +81,7 @@ Part::Part(Microtonal *microtonal_, FFTwrapper *fft_, pthread_mutex_t *mutex_) } cleanup(); - Pname = new unsigned char [PART_MAX_NAME_LEN]; + Pname = new unsigned char [PART_MAX_NAME_LEN]; oldvolumel = oldvolumer = 0.5f; lastnote = -1; @@ -100,12 +100,12 @@ void Part::defaults() Ppolymode = 1; Plegatomode = 0; setPvolume(96); - Pkeyshift = 64; - Prcvchn = 0; + Pkeyshift = 64; + Prcvchn = 0; setPpanning(64); - Pvelsns = 64; - Pveloffs = 64; - Pkeylimit = 15; + Pvelsns = 64; + Pveloffs = 64; + Pkeylimit = 15; defaultsinstrument(); ctl.defaults(); } @@ -162,12 +162,11 @@ void Part::cleanup(bool final) ctl.resetall(); for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx) partefx[nefx]->cleanup(); - for(int n = 0; n < NUM_PART_EFX + 1; ++n) { + for(int n = 0; n < NUM_PART_EFX + 1; ++n) for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { partfxinputl[n][i] = final ? 0.0f : denormalkillbuf[i]; partfxinputr[n][i] = final ? 0.0f : denormalkillbuf[i]; } - } } Part::~Part() @@ -236,17 +235,17 @@ void Part::NoteOn(unsigned char note, lastnote = note; - pos = -1; - for(i = 0; i < POLIPHONY; ++i) { + pos = -1; + for(i = 0; i < POLIPHONY; ++i) if(partnote[i].status == KEY_OFF) { pos = i; break; } - } if((Plegatomode != 0) && (Pdrummode == 0)) { if(Ppolymode != 0) { - fprintf( stderr, + fprintf( + stderr, "ZynAddSubFX WARNING: Poly and Legato modes are both On, that should not happen ! ... Disabling Legato mode ! - (Part.cpp::NoteOn(..))\n"); Plegatomode = 0; } @@ -355,9 +354,15 @@ void Part::NoteOn(unsigned char note, && (partnote[pos].kititem[0].adnote != NULL) && (partnote[posb].kititem[0].adnote != NULL)) { partnote[pos].kititem[0].adnote->legatonote(notebasefreq, - vel, portamento, note, true);//'true' is to tell it it's being called from here. + vel, + portamento, + note, + true); //'true' is to tell it it's being called from here. partnote[posb].kititem[0].adnote->legatonote(notebasefreq, - vel, portamento, note, true); + vel, + portamento, + note, + true); } if((kit[0].Psubenabled != 0) @@ -390,12 +395,14 @@ void Part::NoteOn(unsigned char note, || (lastnotecopy > kit[item].Pmaxkey)) continue; // We will not perform legato across 2 key regions. - partnote[pos].kititem[ci].sendtoparteffect = + partnote[pos].kititem[ci].sendtoparteffect = (kit[item].Psendtoparteffect < - NUM_PART_EFX ? kit[item].Psendtoparteffect : NUM_PART_EFX);//if this parameter is 127 for "unprocessed" + NUM_PART_EFX ? kit[item].Psendtoparteffect : + NUM_PART_EFX); //if this parameter is 127 for "unprocessed" partnote[posb].kititem[ci].sendtoparteffect = (kit[item].Psendtoparteffect < - NUM_PART_EFX ? kit[item].Psendtoparteffect : NUM_PART_EFX); + NUM_PART_EFX ? kit[item].Psendtoparteffect : + NUM_PART_EFX); if((kit[item].Padenabled != 0) && (kit[item].adpars != NULL) && (partnote[pos].kititem[ci].adnote != NULL) @@ -451,13 +458,28 @@ void Part::NoteOn(unsigned char note, partnote[pos].kititem[0].sendtoparteffect = 0; if(kit[0].Padenabled != 0) partnote[pos].kititem[0].adnote = new ADnote(kit[0].adpars, - &ctl, notebasefreq, vel, portamento, note, false); + &ctl, + notebasefreq, + vel, + portamento, + note, + false); if(kit[0].Psubenabled != 0) partnote[pos].kititem[0].subnote = new SUBnote(kit[0].subpars, - &ctl, notebasefreq, vel, portamento, note, false); + &ctl, + notebasefreq, + vel, + portamento, + note, + false); if(kit[0].Ppadenabled != 0) partnote[pos].kititem[0].padnote = new PADnote(kit[0].padpars, - &ctl, notebasefreq, vel, portamento, note, false); + &ctl, + notebasefreq, + vel, + portamento, + note, + false); if((kit[0].Padenabled != 0) || (kit[0].Psubenabled != 0) || (kit[0].Ppadenabled != 0)) partnote[pos].itemsplaying++; @@ -467,19 +489,36 @@ void Part::NoteOn(unsigned char note, partnote[posb].kititem[0].sendtoparteffect = 0; if(kit[0].Padenabled != 0) partnote[posb].kititem[0].adnote = new ADnote(kit[0].adpars, - &ctl, notebasefreq, vel, portamento, note, true);//true for silent. + &ctl, + notebasefreq, + vel, + portamento, + note, + true); //true for silent. if(kit[0].Psubenabled != 0) - partnote[posb].kititem[0].subnote = new SUBnote( kit[0].subpars, - &ctl, notebasefreq, vel, portamento, note, true); + partnote[posb].kititem[0].subnote = new SUBnote( + kit[0].subpars, + &ctl, + notebasefreq, + vel, + portamento, + note, + true); if(kit[0].Ppadenabled != 0) - partnote[posb].kititem[0].padnote = new PADnote( kit[0].padpars, - &ctl, notebasefreq, vel, portamento, note, true); + partnote[posb].kititem[0].padnote = new PADnote( + kit[0].padpars, + &ctl, + notebasefreq, + vel, + portamento, + note, + true); if((kit[0].Padenabled != 0) || (kit[0].Psubenabled != 0) || (kit[0].Ppadenabled != 0)) partnote[posb].itemsplaying++; } } - else { //init the notes for the "kit mode" + else //init the notes for the "kit mode" for(int item = 0; item < NUM_KIT_ITEMS; ++item) { if(kit[item].Pmuted != 0) continue; @@ -491,40 +530,75 @@ void Part::NoteOn(unsigned char note, //if this parameter is 127 for "unprocessed" partnote[pos].kititem[ci].sendtoparteffect = (kit[item].Psendtoparteffect < NUM_PART_EFX ? - kit[item]. Psendtoparteffect : NUM_PART_EFX); + kit[item].Psendtoparteffect : NUM_PART_EFX); if((kit[item].adpars != NULL) && ((kit[item].Padenabled) != 0)) - partnote[pos].kititem[ci].adnote = new ADnote( kit[item].adpars, - &ctl, notebasefreq, vel, portamento, note, false); + partnote[pos].kititem[ci].adnote = new ADnote( + kit[item].adpars, + &ctl, + notebasefreq, + vel, + portamento, + note, + false); if((kit[item].subpars != NULL) && ((kit[item].Psubenabled) != 0)) - partnote[pos].kititem[ci].subnote = new SUBnote( kit[item].subpars, - &ctl, notebasefreq, vel, portamento, note, false); + partnote[pos].kititem[ci].subnote = new SUBnote( + kit[item].subpars, + &ctl, + notebasefreq, + vel, + portamento, + note, + false); if((kit[item].padpars != NULL) && ((kit[item].Ppadenabled) != 0)) - partnote[pos].kititem[ci].padnote = new PADnote( kit[item].padpars, - &ctl, notebasefreq, vel, portamento, note, false); + partnote[pos].kititem[ci].padnote = new PADnote( + kit[item].padpars, + &ctl, + notebasefreq, + vel, + portamento, + note, + false); // Spawn another note (but silent) if legatomodevalid==true if(legatomodevalid) { partnote[posb].kititem[ci].sendtoparteffect = (kit[item].Psendtoparteffect < - NUM_PART_EFX ? kit[item].Psendtoparteffect : NUM_PART_EFX); //if this parameter is 127 for "unprocessed" + NUM_PART_EFX ? kit[item].Psendtoparteffect : + NUM_PART_EFX); //if this parameter is 127 for "unprocessed" if((kit[item].adpars != NULL) && ((kit[item].Padenabled) != 0)) - partnote[posb].kititem[ci].adnote = new ADnote( kit[item].adpars, - &ctl, notebasefreq, vel, portamento, note, true); //true for silent. + partnote[posb].kititem[ci].adnote = new ADnote( + kit[item].adpars, + &ctl, + notebasefreq, + vel, + portamento, + note, + true); //true for silent. if((kit[item].subpars != NULL) && ((kit[item].Psubenabled) != 0)) partnote[posb].kititem[ci].subnote = new SUBnote(kit[item].subpars, - &ctl, notebasefreq, vel, portamento, note, true); + &ctl, + notebasefreq, + vel, + portamento, + note, + true); if((kit[item].padpars != NULL) && ((kit[item].Ppadenabled) != 0)) partnote[posb].kititem[ci].padnote = new PADnote(kit[item].padpars, - &ctl, notebasefreq, vel, portamento, note, true); + &ctl, + notebasefreq, + vel, + portamento, + note, + true); if((kit[item].adpars != NULL) || (kit[item].subpars != NULL)) partnote[posb].itemsplaying++; @@ -539,7 +613,6 @@ void Part::NoteOn(unsigned char note, break; } } - } } //this only relase the keys if there is maximum number of keys allowed @@ -564,7 +637,7 @@ void Part::NoteOff(unsigned char note) //relase the key MonoMemRenote(); // To play most recent still held note. else RelaseNotePos(i); - /// break; + /// break; } else //the sustain pedal is pushed partnote[i].status = KEY_RELASED_AND_SUSTAINED; @@ -577,88 +650,89 @@ void Part::NoteOff(unsigned char note) //relase the key void Part::SetController(unsigned int type, int par) { switch(type) { - case C_pitchwheel: - ctl.setpitchwheel(par); - break; - case C_expression: - ctl.setexpression(par); - setPvolume(Pvolume); //update the volume - break; - case C_portamento: - ctl.setportamento(par); - break; - case C_panning: - ctl.setpanning(par); - setPpanning(Ppanning); //update the panning - break; - case C_filtercutoff: - ctl.setfiltercutoff(par); - break; - case C_filterq: - ctl.setfilterq(par); - break; - case C_bandwidth: - ctl.setbandwidth(par); - break; - case C_modwheel: - ctl.setmodwheel(par); - break; - case C_fmamp: - ctl.setfmamp(par); - break; - case C_volume: - ctl.setvolume(par); - if(ctl.volume.receive != 0) - volume = ctl.volume.volume; - else - setPvolume(Pvolume); - break; - case C_sustain: - ctl.setsustain(par); - if(ctl.sustain.sustain == 0) + case C_pitchwheel: + ctl.setpitchwheel(par); + break; + case C_expression: + ctl.setexpression(par); + setPvolume(Pvolume); //update the volume + break; + case C_portamento: + ctl.setportamento(par); + break; + case C_panning: + ctl.setpanning(par); + setPpanning(Ppanning); //update the panning + break; + case C_filtercutoff: + ctl.setfiltercutoff(par); + break; + case C_filterq: + ctl.setfilterq(par); + break; + case C_bandwidth: + ctl.setbandwidth(par); + break; + case C_modwheel: + ctl.setmodwheel(par); + break; + case C_fmamp: + ctl.setfmamp(par); + break; + case C_volume: + ctl.setvolume(par); + if(ctl.volume.receive != 0) + volume = ctl.volume.volume; + else + setPvolume(Pvolume); + break; + case C_sustain: + ctl.setsustain(par); + if(ctl.sustain.sustain == 0) + RelaseSustainedKeys(); + break; + case C_allsoundsoff: + AllNotesOff(); //Panic + break; + case C_resetallcontrollers: + ctl.resetall(); RelaseSustainedKeys(); - break; - case C_allsoundsoff: - AllNotesOff(); //Panic - break; - case C_resetallcontrollers: - ctl.resetall(); - RelaseSustainedKeys(); - if(ctl.volume.receive != 0) - volume = ctl.volume.volume; - else - setPvolume(Pvolume); - setPvolume(Pvolume); //update the volume - setPpanning(Ppanning); //update the panning + if(ctl.volume.receive != 0) + volume = ctl.volume.volume; + else + setPvolume(Pvolume); + setPvolume(Pvolume); //update the volume + setPpanning(Ppanning); //update the panning - for(int item = 0; item < NUM_KIT_ITEMS; ++item) { - if(kit[item].adpars == NULL) - continue; - kit[item].adpars->GlobalPar.Reson-> - sendcontroller(C_resonance_center, 1.0f); + for(int item = 0; item < NUM_KIT_ITEMS; ++item) { + if(kit[item].adpars == NULL) + continue; + kit[item].adpars->GlobalPar.Reson-> + sendcontroller(C_resonance_center, 1.0f); - kit[item].adpars->GlobalPar.Reson-> - sendcontroller(C_resonance_bandwidth, 1.0f); - } - //more update to add here if I add controllers - break; - case C_allnotesoff: - RelaseAllKeys(); - break; - case C_resonance_center: - ctl.setresonancecenter(par); - for(int item = 0; item < NUM_KIT_ITEMS; ++item) { - if(kit[item].adpars == NULL) - continue; - kit[item].adpars->GlobalPar.Reson-> - sendcontroller(C_resonance_center, ctl.resonancecenter.relcenter); - } - break; - case C_resonance_bandwidth: - ctl.setresonancebw(par); - kit[0].adpars->GlobalPar.Reson-> - sendcontroller(C_resonance_bandwidth, ctl.resonancebandwidth.relbw); - break; + kit[item].adpars->GlobalPar.Reson-> + sendcontroller(C_resonance_bandwidth, 1.0f); + } + //more update to add here if I add controllers + break; + case C_allnotesoff: + RelaseAllKeys(); + break; + case C_resonance_center: + ctl.setresonancecenter(par); + for(int item = 0; item < NUM_KIT_ITEMS; ++item) { + if(kit[item].adpars == NULL) + continue; + kit[item].adpars->GlobalPar.Reson-> + sendcontroller(C_resonance_center, + ctl.resonancecenter.relcenter); + } + break; + case C_resonance_bandwidth: + ctl.setresonancebw(par); + kit[0].adpars->GlobalPar.Reson-> + sendcontroller(C_resonance_bandwidth, ctl.resonancebandwidth.relbw); + break; } } /* @@ -774,7 +848,7 @@ void Part::setkeylimit(unsigned char Pkeylimit) notecount++; int oldestnotepos = -1; - if(notecount > keylimit) { //find out the oldest note + if(notecount > keylimit) //find out the oldest note for(int i = 0; i < POLIPHONY; ++i) { int maxtime = 0; if(((partnote[i].status == KEY_PLAYING) @@ -784,7 +858,6 @@ void Part::setkeylimit(unsigned char Pkeylimit) oldestnotepos = i; } } - } if(oldestnotepos != -1) RelaseNotePos(oldestnotepos); } @@ -810,9 +883,11 @@ void Part::RunNote(unsigned int k) SynthNote **note; if(type == 0) note = &partnote[k].kititem[item].adnote; - else if(type == 1) + else + if(type == 1) note = &partnote[k].kititem[item].subnote; - else if(type == 2) + else + if(type == 2) note = &partnote[k].kititem[item].padnote; //Process if it exists @@ -847,12 +922,11 @@ void Part::RunNote(unsigned int k) */ void Part::ComputePartSmps() { - for(unsigned nefx = 0; nefx < NUM_PART_EFX + 1; ++nefx) { + for(unsigned nefx = 0; nefx < NUM_PART_EFX + 1; ++nefx) for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { partfxinputl[nefx][i] = 0.0f; partfxinputr[nefx][i] = 0.0f; } - } for(unsigned k = 0; k < POLIPHONY; ++k) { if(partnote[k].status == KEY_OFF) @@ -867,12 +941,11 @@ void Part::ComputePartSmps() for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx) { if(!Pefxbypass[nefx]) { partefx[nefx]->out(partfxinputl[nefx], partfxinputr[nefx]); - if(Pefxroute[nefx] == 2) { + if(Pefxroute[nefx] == 2) for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { partfxinputl[nefx + 1][i] += partefx[nefx]->efxoutl[i]; partfxinputr[nefx + 1][i] += partefx[nefx]->efxoutr[i]; } - } } int routeto = ((Pefxroute[nefx] == 0) ? nefx + 1 : NUM_PART_EFX); for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { @@ -898,7 +971,6 @@ void Part::ComputePartSmps() killallnotes = 0; for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx) partefx[nefx]->cleanup(); - } ctl.updateportamento(); } @@ -909,7 +981,8 @@ void Part::ComputePartSmps() void Part::setPvolume(char Pvolume_) { Pvolume = Pvolume_; - volume = dB2rap((Pvolume - 96.0f) / 96.0f * 40.0f) * ctl.expression.relvolume; + volume = + dB2rap((Pvolume - 96.0f) / 96.0f * 40.0f) * ctl.expression.relvolume; } void Part::setPpanning(char Ppanning_) @@ -1073,7 +1146,7 @@ int Part::saveXML(const char *filename) return result; } -int Part::loadXMLinstrument(const char *filename)/*{*/ +int Part::loadXMLinstrument(const char *filename) /*{*/ { XMLwrapper *xml = new XMLwrapper(); if(xml->loadXMLfile(filename) < 0) { @@ -1088,14 +1161,14 @@ int Part::loadXMLinstrument(const char *filename)/*{*/ delete (xml); return 0; -}/*}*/ +} /*}*/ -void Part::applyparameters(bool lockmutex)/*{*/ +void Part::applyparameters(bool lockmutex) /*{*/ { for(int n = 0; n < NUM_KIT_ITEMS; ++n) if((kit[n].padpars != NULL) && (kit[n].Ppadenabled != 0)) kit[n].padpars->applyparameters(lockmutex); -}/*}*/ +} /*}*/ void Part::getfromXMLinstrument(XMLwrapper *xml) { @@ -1169,10 +1242,10 @@ void Part::getfromXMLinstrument(XMLwrapper *xml) xml->exitbranch(); } - Pefxroute[nefx] = xml->getpar("route", - Pefxroute[nefx], - 0, - NUM_PART_EFX); + Pefxroute[nefx] = xml->getpar("route", + Pefxroute[nefx], + 0, + NUM_PART_EFX); partefx[nefx]->setdryonly(Pefxroute[nefx] == 2); Pefxbypass[nefx] = xml->getparbool("bypass", Pefxbypass[nefx]); xml->exitbranch(); @@ -1188,20 +1261,20 @@ void Part::getfromXML(XMLwrapper *xml) setPvolume(xml->getpar127("volume", Pvolume)); setPpanning(xml->getpar127("panning", Ppanning)); - Pminkey = xml->getpar127("min_key", Pminkey); - Pmaxkey = xml->getpar127("max_key", Pmaxkey); - Pkeyshift = xml->getpar127("key_shift", Pkeyshift); - Prcvchn = xml->getpar127("rcv_chn", Prcvchn); + Pminkey = xml->getpar127("min_key", Pminkey); + Pmaxkey = xml->getpar127("max_key", Pmaxkey); + Pkeyshift = xml->getpar127("key_shift", Pkeyshift); + Prcvchn = xml->getpar127("rcv_chn", Prcvchn); - Pvelsns = xml->getpar127("velocity_sensing", Pvelsns); - Pveloffs = xml->getpar127("velocity_offset", Pveloffs); + Pvelsns = xml->getpar127("velocity_sensing", Pvelsns); + Pveloffs = xml->getpar127("velocity_offset", Pveloffs); Pnoteon = xml->getparbool("note_on", Pnoteon); Ppolymode = xml->getparbool("poly_mode", Ppolymode); Plegatomode = xml->getparbool("legato_mode", Plegatomode); //older versions if(!Plegatomode) Plegatomode = xml->getpar127("legato_mode", Plegatomode); - Pkeylimit = xml->getpar127("key_limit", Pkeylimit); + Pkeylimit = xml->getpar127("key_limit", Pkeylimit); if(xml->enterbranch("INSTRUMENT")) { @@ -1214,4 +1287,3 @@ void Part::getfromXML(XMLwrapper *xml) xml->exitbranch(); } } - diff --git a/src/Misc/Part.h b/src/Misc/Part.h index 1bcc5841..25375414 100644 --- a/src/Misc/Part.h +++ b/src/Misc/Part.h @@ -132,7 +132,7 @@ class Part float *partoutr; //Right channel output of the part float *partfxinputl[NUM_PART_EFX + 1], //Left and right signal that pass thru part effects; - *partfxinputr[NUM_PART_EFX + 1]; //partfxinput l/r [NUM_PART_EFX] is for "no effect" buffer + *partfxinputr[NUM_PART_EFX + 1]; //partfxinput l/r [NUM_PART_EFX] is for "no effect" buffer enum NoteStatus { KEY_OFF, KEY_PLAYING, KEY_RELASED_AND_SUSTAINED, KEY_RELASED @@ -165,10 +165,10 @@ class Part int note; //if there is no note playing, the "note"=-1 int itemsplaying; struct { - SynthNote *adnote, - *subnote, - *padnote; - int sendtoparteffect; + SynthNote *adnote, + *subnote, + *padnote; + int sendtoparteffect; } kititem[NUM_KIT_ITEMS]; int time; }; @@ -189,10 +189,9 @@ class Part PartNotes partnote[POLIPHONY]; - float oldfreq; //this is used for portamento + float oldfreq; //this is used for portamento Microtonal *microtonal; FFTwrapper *fft; }; #endif - diff --git a/src/Misc/Recorder.cpp b/src/Misc/Recorder.cpp index 1951b77b..15c42caf 100644 --- a/src/Misc/Recorder.cpp +++ b/src/Misc/Recorder.cpp @@ -46,7 +46,7 @@ int Recorder::preparefile(std::string filename_, int overwrite) return 1; } - OutMgr::getInstance().wave->newFile(new WavFile(filename_, SAMPLE_RATE, 2)); + OutMgr::getInstance(). wave->newFile(new WavFile(filename_, SAMPLE_RATE, 2)); status = 1; //ready @@ -61,15 +61,15 @@ void Recorder::start() void Recorder::stop() { - OutMgr::getInstance().wave->Stop(); - OutMgr::getInstance().wave->destroyFile(); + OutMgr::getInstance(). wave->Stop(); + OutMgr::getInstance(). wave->destroyFile(); status = 0; } void Recorder::pause() { status = 0; - OutMgr::getInstance().wave->Stop(); + OutMgr::getInstance(). wave->Stop(); } int Recorder::recording() @@ -83,9 +83,8 @@ int Recorder::recording() void Recorder::triggernow() { if(status == 2) { - if(notetrigger!=1) { + if(notetrigger != 1) OutMgr::getInstance().wave->Start(); - } notetrigger = 1; } } diff --git a/src/Misc/Recorder.h b/src/Misc/Recorder.h index e501613a..0e3f02f1 100644 --- a/src/Misc/Recorder.h +++ b/src/Misc/Recorder.h @@ -52,4 +52,3 @@ class Recorder }; #endif - diff --git a/src/Misc/Stereo.cpp b/src/Misc/Stereo.cpp index be53e511..ac2f3172 100644 --- a/src/Misc/Stereo.cpp +++ b/src/Misc/Stereo.cpp @@ -36,4 +36,3 @@ Stereo &Stereo::operator=(const Stereo &nstr) r = nstr.r; return *this; } - diff --git a/src/Misc/Stereo.h b/src/Misc/Stereo.h index 06ee63c8..516d3187 100644 --- a/src/Misc/Stereo.h +++ b/src/Misc/Stereo.h @@ -22,8 +22,7 @@ #define STEREO_H template -struct Stereo -{ +struct Stereo { public: Stereo(const T &left, const T &right); @@ -39,4 +38,3 @@ struct Stereo }; #include "Stereo.cpp" #endif - diff --git a/src/Misc/Util.cpp b/src/Misc/Util.cpp index abf20dba..3b5155d6 100644 --- a/src/Misc/Util.cpp +++ b/src/Misc/Util.cpp @@ -35,12 +35,12 @@ #include -int SAMPLE_RATE = 44100; -int SOUND_BUFFER_SIZE = 256; -int OSCIL_SIZE = 1024; -prng_t prng_state = 0x1234; +int SAMPLE_RATE = 44100; +int SOUND_BUFFER_SIZE = 256; +int OSCIL_SIZE = 1024; +prng_t prng_state = 0x1234; -Config config; +Config config; float *denormalkillbuf; @@ -61,12 +61,12 @@ float VelF(float velocity, unsigned char scaling) * Get the detune in cents */ float getdetune(unsigned char type, - unsigned short int coarsedetune, - unsigned short int finedetune) + unsigned short int coarsedetune, + unsigned short int finedetune) { float det = 0.0f, octdet = 0.0f, cdet = 0.0f, findet = 0.0f; //Get Octave - int octave = coarsedetune / 1024; + int octave = coarsedetune / 1024; if(octave >= 8) octave -= 16; octdet = octave * 1200.0f; @@ -80,23 +80,24 @@ float getdetune(unsigned char type, switch(type) { // case 1: is used for the default (see below) - case 2: - cdet = fabs(cdetune * 10.0f); - findet = fabs(fdetune / 8192.0f) * 10.0f; - break; - case 3: - cdet = fabs(cdetune * 100); - findet = powf(10, fabs(fdetune / 8192.0f) * 3.0f) / 10.0f - 0.1f; - break; - case 4: - cdet = fabs(cdetune * 701.95500087f); //perfect fifth - findet = (powf(2, fabs(fdetune / 8192.0f) * 12.0f) - 1.0f) / 4095 * 1200; - break; - //case ...: need to update N_DETUNE_TYPES, if you'll add more - default: - cdet = fabs(cdetune * 50.0f); - findet = fabs(fdetune / 8192.0f) * 35.0f; //almost like "Paul's Sound Designer 2" - break; + case 2: + cdet = fabs(cdetune * 10.0f); + findet = fabs(fdetune / 8192.0f) * 10.0f; + break; + case 3: + cdet = fabs(cdetune * 100); + findet = powf(10, fabs(fdetune / 8192.0f) * 3.0f) / 10.0f - 0.1f; + break; + case 4: + cdet = fabs(cdetune * 701.95500087f); //perfect fifth + findet = + (powf(2, fabs(fdetune / 8192.0f) * 12.0f) - 1.0f) / 4095 * 1200; + break; + //case ...: need to update N_DETUNE_TYPES, if you'll add more + default: + cdet = fabs(cdetune * 50.0f); + findet = fabs(fdetune / 8192.0f) * 35.0f; //almost like "Paul's Sound Designer 2" + break; } if(finedetune < 8192) findet = -findet; @@ -152,26 +153,25 @@ void invSignal(float *sig, size_t len) //Some memory pools for short term buffer use //(avoid the use of new in RT thread(s)) -struct pool_entry{ - bool free; +struct pool_entry { + bool free; float *dat; }; typedef std::vector pool_t; -typedef pool_t::iterator pool_itr_t; +typedef pool_t::iterator pool_itr_t; pool_t pool; float *getTmpBuffer() { - for(pool_itr_t itr = pool.begin(); itr != pool.end(); ++itr) { + for(pool_itr_t itr = pool.begin(); itr != pool.end(); ++itr) if(itr->free) { //Use Pool itr->free = false; return itr->dat; } - } pool_entry p; //Extend Pool p.free = false; - p.dat = new float[SOUND_BUFFER_SIZE]; + p.dat = new float[SOUND_BUFFER_SIZE]; pool.push_back(p); return p.dat; @@ -179,23 +179,24 @@ float *getTmpBuffer() void returnTmpBuffer(float *buf) { - for(pool_itr_t itr = pool.begin(); itr != pool.end(); ++itr) { + for(pool_itr_t itr = pool.begin(); itr != pool.end(); ++itr) if(itr->dat == buf) { //Return to Pool itr->free = true; return; } - } - fprintf(stderr,"ERROR: invalid buffer returned %s %d\n",__FILE__,__LINE__); + fprintf(stderr, + "ERROR: invalid buffer returned %s %d\n", + __FILE__, + __LINE__); } void clearTmpBuffers(void) { for(pool_itr_t itr = pool.begin(); itr != pool.end(); ++itr) { if(!itr->free) //Warn about used buffers - warn("Temporary buffer (%p) about to be freed may be in use", itr->dat); + warn("Temporary buffer (%p) about to be freed may be in use", + itr->dat); delete [] itr->dat; } pool.clear(); } - - diff --git a/src/Misc/Util.h b/src/Misc/Util.h index 2806a521..34fffb6d 100644 --- a/src/Misc/Util.h +++ b/src/Misc/Util.h @@ -36,8 +36,8 @@ bool fileexists(const char *filename); #define N_DETUNE_TYPES 4 //the number of detune types extern float getdetune(unsigned char type, - unsigned short int coarsedetune, - unsigned short int finedetune); + unsigned short int coarsedetune, + unsigned short int finedetune); /**Try to set current thread to realtime priority program priority * \todo see if the right pid is being sent @@ -81,39 +81,38 @@ T stringTo(const char *x) return ans; } -template +template T limit(T val, T min, T max) { - return (val < min ? min : (val > max ? max : val)); -} + return (val max ? max : val)); + } //Random number generator -typedef uint32_t prng_t; -extern prng_t prng_state; + typedef uint32_t prng_t; + extern prng_t prng_state; // Portable Pseudo-Random Number Generator -inline prng_t prng_r(prng_t &p) -{ - return (p = p * 1103515245 + 12345); -} + inline prng_t prng_r(prng_t & p) + { + return p = p * 1103515245 + 12345; + } -inline prng_t prng(void) -{ - return prng_r(prng_state)&0x7fffffff; -} + inline prng_t prng(void) + { + return prng_r(prng_state) & 0x7fffffff; + } -inline void sprng(prng_t p) -{ - prng_state = p; -} + inline void sprng(prng_t p) + { + prng_state = p; + } /* * The random generator (0.0f..1.0f) */ -# define INT32_MAX (2147483647) +# define INT32_MAX (2147483647) #define RND (prng() / (INT32_MAX * 1.0f)) #endif - diff --git a/src/Misc/WavFile.cpp b/src/Misc/WavFile.cpp index 7ec7a30b..78db9d52 100644 --- a/src/Misc/WavFile.cpp +++ b/src/Misc/WavFile.cpp @@ -26,14 +26,14 @@ using namespace std; WavFile::WavFile(string filename, int samplerate, int channels) :sampleswritten(0), samplerate(samplerate), channels(channels), - file(fopen(filename.c_str(), "w")) + file(fopen(filename.c_str(), "w")) { if(file) { cout << "INFO: Making space for wave file header" << endl; //making space for the header written at destruction char tmp[44]; - memset(tmp, 0, 44*sizeof(char)); + memset(tmp, 0, 44 * sizeof(char)); fwrite(tmp, 1, 44, file); } } @@ -53,15 +53,15 @@ WavFile::~WavFile() fwrite("WAVEfmt ", 8, 1, file); chunksize = 16; fwrite(&chunksize, 4, 1, file); - unsigned short int formattag = 1; //uncompresed wave + unsigned short int formattag = 1; //uncompresed wave fwrite(&formattag, 2, 1, file); - unsigned short int nchannels = channels; //stereo + unsigned short int nchannels = channels; //stereo fwrite(&nchannels, 2, 1, file); - unsigned int samplerate_ = samplerate; //samplerate + unsigned int samplerate_ = samplerate; //samplerate fwrite(&samplerate_, 4, 1, file); - unsigned int bytespersec = samplerate * 2 * channels; //bytes/sec + unsigned int bytespersec = samplerate * 2 * channels; //bytes/sec fwrite(&bytespersec, 4, 1, file); - unsigned short int blockalign = 2 * channels; //2 channels * 16 bits/8 + unsigned short int blockalign = 2 * channels; //2 channels * 16 bits/8 fwrite(&blockalign, 2, 1, file); unsigned short int bitspersample = 16; fwrite(&bitspersample, 2, 1, file); @@ -95,4 +95,3 @@ void WavFile::writeMonoSamples(int nsmps, short int *smps) sampleswritten += nsmps; } } - diff --git a/src/Misc/WavFile.h b/src/Misc/WavFile.h index d86437a7..4b29efa0 100644 --- a/src/Misc/WavFile.h +++ b/src/Misc/WavFile.h @@ -42,4 +42,3 @@ class WavFile FILE *file; }; #endif - diff --git a/src/Misc/WaveShapeSmps.cpp b/src/Misc/WaveShapeSmps.cpp index 54a7a8b7..cf281296 100644 --- a/src/Misc/WaveShapeSmps.cpp +++ b/src/Misc/WaveShapeSmps.cpp @@ -28,162 +28,162 @@ void waveShapeSmps(int n, unsigned char type, unsigned char drive) { - int i; + int i; float ws = drive / 127.0f; float tmpv; switch(type) { - case 1: - ws = powf(10, ws * ws * 3.0f) - 1.0f + 0.001f; //Arctangent - for(i = 0; i < n; ++i) - smps[i] = atanf(smps[i] * ws) / atanf(ws); - break; - case 2: - ws = ws * ws * 32.0f + 0.0001f; //Asymmetric - if(ws < 1.0f) - tmpv = sinf(ws) + 0.1f; - else - tmpv = 1.1f; - for(i = 0; i < n; ++i) - smps[i] = sinf(smps[i] * (0.1f + ws - ws * smps[i])) / tmpv; - ; - break; - case 3: - ws = ws * ws * ws * 20.0f + 0.0001f; //Pow - for(i = 0; i < n; ++i) { - smps[i] *= ws; - if(fabs(smps[i]) < 1.0f) { - smps[i] = (smps[i] - powf(smps[i], 3.0f)) * 3.0f; - if(ws < 1.0f) - smps[i] /= ws; - } + case 1: + ws = powf(10, ws * ws * 3.0f) - 1.0f + 0.001f; //Arctangent + for(i = 0; i < n; ++i) + smps[i] = atanf(smps[i] * ws) / atanf(ws); + break; + case 2: + ws = ws * ws * 32.0f + 0.0001f; //Asymmetric + if(ws < 1.0f) + tmpv = sinf(ws) + 0.1f; else - smps[i] = 0.0f; - } - break; - case 4: - ws = ws * ws * ws * 32.0f + 0.0001f; //Sine - if(ws < 1.57f) - tmpv = sinf(ws); - else - tmpv = 1.0f; - for(i = 0; i < n; ++i) - smps[i] = sinf(smps[i] * ws) / tmpv; - break; - case 5: - ws = ws * ws + 0.000001f; //Quantisize - for(i = 0; i < n; ++i) - smps[i] = floor(smps[i] / ws + 0.5f) * ws; - break; - case 6: - ws = ws * ws * ws * 32 + 0.0001f; //Zigzag - if(ws < 1.0f) - tmpv = sinf(ws); - else - tmpv = 1.0f; - for(i = 0; i < n; ++i) - smps[i] = asinf(sinf(smps[i] * ws)) / tmpv; - break; - case 7: - ws = powf(2.0f, -ws * ws * 8.0f); //Limiter - for(i = 0; i < n; ++i) { - float tmp = smps[i]; - if(fabs(tmp) > ws) { - if(tmp >= 0.0f) - smps[i] = 1.0f; + tmpv = 1.1f; + for(i = 0; i < n; ++i) + smps[i] = sinf(smps[i] * (0.1f + ws - ws * smps[i])) / tmpv; + ; + break; + case 3: + ws = ws * ws * ws * 20.0f + 0.0001f; //Pow + for(i = 0; i < n; ++i) { + smps[i] *= ws; + if(fabs(smps[i]) < 1.0f) { + smps[i] = (smps[i] - powf(smps[i], 3.0f)) * 3.0f; + if(ws < 1.0f) + smps[i] /= ws; + } else - smps[i] = -1.0f; + smps[i] = 0.0f; } + break; + case 4: + ws = ws * ws * ws * 32.0f + 0.0001f; //Sine + if(ws < 1.57f) + tmpv = sinf(ws); else - smps[i] /= ws; - } - break; - case 8: - ws = powf(2.0f, -ws * ws * 8.0f); //Upper Limiter - for(i = 0; i < n; ++i) { - float tmp = smps[i]; - if(tmp > ws) - smps[i] = ws; - smps[i] *= 2.0f; - } - break; - case 9: - ws = powf(2.0f, -ws * ws * 8.0f); //Lower Limiter - for(i = 0; i < n; ++i) { - float tmp = smps[i]; - if(tmp < -ws) - smps[i] = -ws; - smps[i] *= 2.0f; - } - break; - case 10: - ws = (powf(2.0f, ws * 6.0f) - 1.0f) / powf(2.0f, 6.0f); //Inverse Limiter - for(i = 0; i < n; ++i) { - float tmp = smps[i]; - if(fabs(tmp) > ws) { - if(tmp >= 0.0f) - smps[i] = tmp - ws; + tmpv = 1.0f; + for(i = 0; i < n; ++i) + smps[i] = sinf(smps[i] * ws) / tmpv; + break; + case 5: + ws = ws * ws + 0.000001f; //Quantisize + for(i = 0; i < n; ++i) + smps[i] = floor(smps[i] / ws + 0.5f) * ws; + break; + case 6: + ws = ws * ws * ws * 32 + 0.0001f; //Zigzag + if(ws < 1.0f) + tmpv = sinf(ws); + else + tmpv = 1.0f; + for(i = 0; i < n; ++i) + smps[i] = asinf(sinf(smps[i] * ws)) / tmpv; + break; + case 7: + ws = powf(2.0f, -ws * ws * 8.0f); //Limiter + for(i = 0; i < n; ++i) { + float tmp = smps[i]; + if(fabs(tmp) > ws) { + if(tmp >= 0.0f) + smps[i] = 1.0f; + else + smps[i] = -1.0f; + } else - smps[i] = tmp + ws; + smps[i] /= ws; } + break; + case 8: + ws = powf(2.0f, -ws * ws * 8.0f); //Upper Limiter + for(i = 0; i < n; ++i) { + float tmp = smps[i]; + if(tmp > ws) + smps[i] = ws; + smps[i] *= 2.0f; + } + break; + case 9: + ws = powf(2.0f, -ws * ws * 8.0f); //Lower Limiter + for(i = 0; i < n; ++i) { + float tmp = smps[i]; + if(tmp < -ws) + smps[i] = -ws; + smps[i] *= 2.0f; + } + break; + case 10: + ws = (powf(2.0f, ws * 6.0f) - 1.0f) / powf(2.0f, 6.0f); //Inverse Limiter + for(i = 0; i < n; ++i) { + float tmp = smps[i]; + if(fabs(tmp) > ws) { + if(tmp >= 0.0f) + smps[i] = tmp - ws; + else + smps[i] = tmp + ws; + } + else + smps[i] = 0; + } + break; + case 11: + ws = powf(5, ws * ws * 1.0f) - 1.0f; //Clip + for(i = 0; i < n; ++i) + smps[i] = smps[i] + * (ws + 0.5f) * 0.9999f - floor( + 0.5f + smps[i] * (ws + 0.5f) * 0.9999f); + break; + case 12: + ws = ws * ws * ws * 30 + 0.001f; //Asym2 + if(ws < 0.3f) + tmpv = ws; else - smps[i] = 0; - } - break; - case 11: - ws = powf(5, ws * ws * 1.0f) - 1.0f; //Clip - for(i = 0; i < n; ++i) - smps[i] = smps[i] - * (ws + 0.5f) * 0.9999f - floor( - 0.5f + smps[i] * (ws + 0.5f) * 0.9999f); - break; - case 12: - ws = ws * ws * ws * 30 + 0.001f; //Asym2 - if(ws < 0.3f) - tmpv = ws; - else - tmpv = 1.0f; - for(i = 0; i < n; ++i) { - float tmp = smps[i] * ws; - if((tmp > -2.0f) && (tmp < 1.0f)) - smps[i] = tmp * (1.0f - tmp) * (tmp + 2.0f) / tmpv; - else - smps[i] = 0.0f; - } - break; - case 13: - ws = ws * ws * ws * 32.0f + 0.0001f; //Pow2 - if(ws < 1.0f) - tmpv = ws * (1 + ws) / 2.0f; - else - tmpv = 1.0f; - for(i = 0; i < n; ++i) { - float tmp = smps[i] * ws; - if((tmp > -1.0f) && (tmp < 1.618034f)) - smps[i] = tmp * (1.0f - tmp) / tmpv; - else - if(tmp > 0.0f) - smps[i] = -1.0f; + tmpv = 1.0f; + for(i = 0; i < n; ++i) { + float tmp = smps[i] * ws; + if((tmp > -2.0f) && (tmp < 1.0f)) + smps[i] = tmp * (1.0f - tmp) * (tmp + 2.0f) / tmpv; + else + smps[i] = 0.0f; + } + break; + case 13: + ws = ws * ws * ws * 32.0f + 0.0001f; //Pow2 + if(ws < 1.0f) + tmpv = ws * (1 + ws) / 2.0f; else - smps[i] = -2.0f; - } - break; - case 14: - ws = powf(ws, 5.0f) * 80.0f + 0.0001f; //sigmoid - if(ws > 10.0f) - tmpv = 0.5f; - else - tmpv = 0.5f - 1.0f / (expf(ws) + 1.0f); - for(i = 0; i < n; ++i) { - float tmp = smps[i] * ws; - if(tmp < -10.0f) - tmp = -10.0f; + tmpv = 1.0f; + for(i = 0; i < n; ++i) { + float tmp = smps[i] * ws; + if((tmp > -1.0f) && (tmp < 1.618034f)) + smps[i] = tmp * (1.0f - tmp) / tmpv; + else + if(tmp > 0.0f) + smps[i] = -1.0f; + else + smps[i] = -2.0f; + } + break; + case 14: + ws = powf(ws, 5.0f) * 80.0f + 0.0001f; //sigmoid + if(ws > 10.0f) + tmpv = 0.5f; else - if(tmp > 10.0f) - tmp = 10.0f; - tmp = 0.5f - 1.0f / (expf(tmp) + 1.0f); - smps[i] = tmp / tmpv; - } - break; + tmpv = 0.5f - 1.0f / (expf(ws) + 1.0f); + for(i = 0; i < n; ++i) { + float tmp = smps[i] * ws; + if(tmp < -10.0f) + tmp = -10.0f; + else + if(tmp > 10.0f) + tmp = 10.0f; + tmp = 0.5f - 1.0f / (expf(tmp) + 1.0f); + smps[i] = tmp / tmpv; + } + break; } } diff --git a/src/Misc/XMLwrapper.cpp b/src/Misc/XMLwrapper.cpp index 054a8dc5..d269246e 100644 --- a/src/Misc/XMLwrapper.cpp +++ b/src/Misc/XMLwrapper.cpp @@ -102,8 +102,8 @@ XMLwrapper::XMLwrapper() minimal = true; - node = tree = mxmlNewElement(MXML_NO_PARENT, - "?xml version=\"1.0f\" encoding=\"UTF-8\"?"); + node = tree = mxmlNewElement(MXML_NO_PARENT, + "?xml version=\"1.0f\" encoding=\"UTF-8\"?"); /* for mxml 2.1f (and older) tree=mxmlNewElement(MXML_NO_PARENT,"?xml"); mxmlElementSetAttr(tree,"version","1.0f"); @@ -315,7 +315,8 @@ int XMLwrapper::loadXMLfile(const string &filename) if(xmldata == NULL) return -1; //the file could not be loaded or uncompressed - root = tree = mxmlLoadString(NULL, trimLeadingWhite(xmldata), MXML_OPAQUE_CALLBACK); + root = tree = mxmlLoadString(NULL, trimLeadingWhite( + xmldata), MXML_OPAQUE_CALLBACK); delete[] xmldata; @@ -384,7 +385,8 @@ bool XMLwrapper::putXMLdata(const char *xmldata) if(xmldata == NULL) return false; - root = tree = mxmlLoadString(NULL, trimLeadingWhite(xmldata), MXML_OPAQUE_CALLBACK); + root = tree = mxmlLoadString(NULL, trimLeadingWhite( + xmldata), MXML_OPAQUE_CALLBACK); if(tree == NULL) return false; @@ -578,9 +580,9 @@ float XMLwrapper::getparreal(const char *name, float defaultpar) const } float XMLwrapper::getparreal(const char *name, - float defaultpar, - float min, - float max) const + float defaultpar, + float min, + float max) const { float result = getparreal(name, defaultpar); @@ -619,4 +621,3 @@ mxml_node_t *XMLwrapper::addparams(const char *name, unsigned int params, } return element; } - diff --git a/src/Misc/XMLwrapper.h b/src/Misc/XMLwrapper.h index 4e4de09e..077c32db 100644 --- a/src/Misc/XMLwrapper.h +++ b/src/Misc/XMLwrapper.h @@ -205,9 +205,9 @@ class XMLwrapper * @param max The maximum value */ float getparreal(const char *name, - float defaultpar, - float min, - float max) const; + float defaultpar, + float min, + float max) const; bool minimal; /**(arg))->AudioThread(); + return (static_cast(arg))->AudioThread(); } void *AlsaEngine::AudioThread() @@ -101,7 +100,7 @@ bool AlsaEngine::getAudioEn() const void *AlsaEngine::_MidiThread(void *arg) { - return static_cast(arg)->MidiThread(); + return static_cast(arg)->MidiThread(); } @@ -110,21 +109,18 @@ void *AlsaEngine::MidiThread(void) snd_seq_event_t *event; MidiEvent ev; set_realtime(); - while(snd_seq_event_input(midi.handle, &event) > 0) - { + while(snd_seq_event_input(midi.handle, &event) > 0) { //ensure ev is empty ev.channel = 0; - ev.num = 0; - ev.value = 0; - ev.type = 0; + ev.num = 0; + ev.value = 0; + ev.type = 0; - if (!event) + if(!event) continue; - switch (event->type) - { + switch(event->type) { case SND_SEQ_EVENT_NOTEON: - if (event->data.note.note) - { + if(event->data.note.note) { ev.type = M_NOTE; ev.channel = event->data.note.channel; ev.num = event->data.note.note; @@ -166,12 +162,12 @@ void *AlsaEngine::MidiThread(void) break; case SND_SEQ_EVENT_PORT_SUBSCRIBED: // ports connected - if (true) + if(true) cout << "Info, alsa midi port connected" << endl; break; case SND_SEQ_EVENT_PORT_UNSUBSCRIBED: // ports disconnected - if (true) + if(true) cout << "Info, alsa midi port disconnected" << endl; break; @@ -180,9 +176,9 @@ void *AlsaEngine::MidiThread(void) break; default: - if (true) + if(true) cout << "Info, other non-handled midi event, type: " - << (int)event->type << endl; + << (int)event->type << endl; break; } snd_seq_free_event(event); @@ -226,7 +222,7 @@ void AlsaEngine::stopMidi() return; snd_seq_t *handle = midi.handle; - if (NULL != midi.handle && midi.pThread) + if((NULL != midi.handle) && midi.pThread) pthread_cancel(midi.pThread); midi.handle = NULL; if(handle) @@ -237,11 +233,10 @@ short *AlsaEngine::interleave(const Stereo &smps) { /**\todo TODO fix repeated allocation*/ short *shortInterleaved = audio.buffer; - memset(shortInterleaved,0,bufferSize*2*sizeof(short)); - int idx = 0;//possible off by one error here + memset(shortInterleaved, 0, bufferSize * 2 * sizeof(short)); + int idx = 0; //possible off by one error here double scaled; - for (int frame = 0; frame < bufferSize; ++frame) - { // with a nod to libsamplerate ... + for(int frame = 0; frame < bufferSize; ++frame) { // with a nod to libsamplerate ... scaled = smps.l[frame] * (8.0f * 0x10000000); shortInterleaved[idx++] = (short int)(lrint(scaled) >> 16); scaled = smps.r[frame] * (8.0f * 0x10000000); @@ -257,10 +252,10 @@ bool AlsaEngine::openAudio() int rc = 0; /* Open PCM device for playback. */ - audio.handle=NULL; + audio.handle = NULL; rc = snd_pcm_open(&audio.handle, "hw:0", - SND_PCM_STREAM_PLAYBACK, 0); - if (rc < 0) { + SND_PCM_STREAM_PLAYBACK, 0); + if(rc < 0) { fprintf(stderr, "unable to open pcm device: %s\n", snd_strerror(rc)); @@ -277,30 +272,30 @@ bool AlsaEngine::openAudio() /* Interleaved mode */ snd_pcm_hw_params_set_access(audio.handle, audio.params, - SND_PCM_ACCESS_RW_INTERLEAVED); + SND_PCM_ACCESS_RW_INTERLEAVED); /* Signed 16-bit little-endian format */ snd_pcm_hw_params_set_format(audio.handle, audio.params, - SND_PCM_FORMAT_S16_LE); + SND_PCM_FORMAT_S16_LE); /* Two channels (stereo) */ snd_pcm_hw_params_set_channels(audio.handle, audio.params, 2); audio.sampleRate = SAMPLE_RATE; snd_pcm_hw_params_set_rate_near(audio.handle, audio.params, - &audio.sampleRate, NULL); + &audio.sampleRate, NULL); audio.frames = 512; snd_pcm_hw_params_set_period_size_near(audio.handle, - audio.params, &audio.frames, NULL); + audio.params, &audio.frames, NULL); audio.periods = 4; snd_pcm_hw_params_set_periods_near(audio.handle, - audio.params, &audio.periods, NULL); + audio.params, &audio.periods, NULL); /* Write the parameters to the driver */ rc = snd_pcm_hw_params(audio.handle, audio.params); - if (rc < 0) { + if(rc < 0) { fprintf(stderr, "unable to set hw parameters: %s\n", snd_strerror(rc)); @@ -309,7 +304,9 @@ bool AlsaEngine::openAudio() /* Set buffer size (in frames). The resulting latency is given by */ /* latency = periodsize * periods / (rate * bytes_per_frame) */ - snd_pcm_hw_params_set_buffer_size(audio.handle, audio.params, SOUND_BUFFER_SIZE); + snd_pcm_hw_params_set_buffer_size(audio.handle, + audio.params, + SOUND_BUFFER_SIZE); //snd_pcm_hw_params_get_period_size(audio.params, &audio.frames, NULL); //snd_pcm_hw_params_get_period_time(audio.params, &val, NULL); @@ -332,21 +329,23 @@ void AlsaEngine::stopAudio() pthread_join(audio.pThread, NULL); snd_pcm_drain(handle); if(snd_pcm_close(handle)) - cout << "Error: in snd_pcm_close " << __LINE__ << ' ' << __FILE__ << endl; + cout << "Error: in snd_pcm_close " << __LINE__ << ' ' << __FILE__ + << endl; } void *AlsaEngine::processAudio() { - while (audio.handle) { + while(audio.handle) { audio.buffer = interleave(getNext()); snd_pcm_t *handle = audio.handle; int rc = snd_pcm_writei(handle, audio.buffer, SOUND_BUFFER_SIZE); - if (rc == -EPIPE) { + if(rc == -EPIPE) { /* EPIPE means underrun */ cerr << "underrun occurred" << endl; snd_pcm_prepare(handle); } - else if (rc < 0) + else + if(rc < 0) cerr << "error from writei: " << snd_strerror(rc) << endl; } return NULL; diff --git a/src/Nio/AlsaEngine.h b/src/Nio/AlsaEngine.h index 3fc9f71e..0b9cc3c1 100644 --- a/src/Nio/AlsaEngine.h +++ b/src/Nio/AlsaEngine.h @@ -31,20 +31,20 @@ #include "OutMgr.h" #include "../Misc/Stereo.h" -class AlsaEngine : public AudioOut, MidiIn +class AlsaEngine:public AudioOut, MidiIn { public: AlsaEngine(); ~AlsaEngine(); - + bool Start(); void Stop(); - + void setAudioEn(bool nval); bool getAudioEn() const; void setMidiEn(bool nval); bool getMidiEn() const; - + protected: void *AudioThread(); static void *_AudioThread(void *arg); @@ -60,20 +60,20 @@ class AlsaEngine : public AudioOut, MidiIn short *interleave(const Stereo &smps); struct { - std::string device; - snd_seq_t *handle; - int alsaId; - pthread_t pThread; + std::string device; + snd_seq_t *handle; + int alsaId; + pthread_t pThread; } midi; struct { snd_pcm_t *handle; snd_pcm_hw_params_t *params; - unsigned int sampleRate; + unsigned int sampleRate; snd_pcm_uframes_t frames; - unsigned int periods; - short *buffer; - pthread_t pThread; + unsigned int periods; + short *buffer; + pthread_t pThread; } audio; void *processAudio(); diff --git a/src/Nio/AudioOut.cpp b/src/Nio/AudioOut.cpp index 718d37b5..ac2579c3 100644 --- a/src/Nio/AudioOut.cpp +++ b/src/Nio/AudioOut.cpp @@ -31,12 +31,11 @@ using namespace std; #include "AudioOut.h" AudioOut::AudioOut() - :samplerate(SAMPLE_RATE),bufferSize(SOUND_BUFFER_SIZE) + :samplerate(SAMPLE_RATE), bufferSize(SOUND_BUFFER_SIZE) {} AudioOut::~AudioOut() -{ -} +{} void AudioOut::setSamplerate(int _samplerate) { diff --git a/src/Nio/AudioOut.h b/src/Nio/AudioOut.h index 1493fb8c..f8e1a97e 100644 --- a/src/Nio/AudioOut.h +++ b/src/Nio/AudioOut.h @@ -27,7 +27,7 @@ #include "../globals.h" #include "Engine.h" -class AudioOut : public virtual Engine +class AudioOut:public virtual Engine { public: AudioOut(); @@ -46,8 +46,8 @@ class AudioOut : public virtual Engine void bufferingSize(int nBuffering); int bufferingSize(); - virtual void setAudioEn(bool nval)=0; - virtual bool getAudioEn() const=0; + virtual void setAudioEn(bool nval) = 0; + virtual bool getAudioEn() const = 0; protected: /**Get the next sample for output. @@ -59,4 +59,3 @@ class AudioOut : public virtual Engine }; #endif - diff --git a/src/Nio/Engine.cpp b/src/Nio/Engine.cpp index 506da8d6..5e846b70 100644 --- a/src/Nio/Engine.cpp +++ b/src/Nio/Engine.cpp @@ -22,8 +22,7 @@ #include "Engine.h" Engine::Engine() -{}; +{} Engine::~Engine() -{}; - +{} diff --git a/src/Nio/Engine.h b/src/Nio/Engine.h index 3df09303..9de4422c 100644 --- a/src/Nio/Engine.h +++ b/src/Nio/Engine.h @@ -32,9 +32,9 @@ class Engine /**Start the Driver with all capabilities * @return true on success*/ - virtual bool Start()=0; + virtual bool Start() = 0; /**Completely stop the Driver*/ - virtual void Stop()=0; + virtual void Stop() = 0; std::string name; }; diff --git a/src/Nio/EngineMgr.cpp b/src/Nio/EngineMgr.cpp index 0ba8814c..7ca0ba16 100644 --- a/src/Nio/EngineMgr.cpp +++ b/src/Nio/EngineMgr.cpp @@ -64,33 +64,30 @@ EngineMgr::EngineMgr() defaultOut = dynamic_cast(defaultEng); - defaultIn = dynamic_cast(defaultEng); -}; + defaultIn = dynamic_cast(defaultEng); +} EngineMgr::~EngineMgr() { - for(list::iterator itr = engines.begin(); - itr != engines.end(); ++itr) { - delete *itr; - } + for(list::iterator itr = engines.begin(); + itr != engines.end(); ++itr) + delete *itr; } Engine *EngineMgr::getEng(string name) { transform(name.begin(), name.end(), name.begin(), ::toupper); - for(list::iterator itr = engines.begin(); - itr != engines.end(); ++itr) { - if((*itr)->name == name) { + for(list::iterator itr = engines.begin(); + itr != engines.end(); ++itr) + if((*itr)->name == name) return *itr; - } - } return NULL; } bool EngineMgr::start() { bool expected = true; - if(!(defaultOut&&defaultIn)) { + if(!(defaultOut && defaultIn)) { cerr << "ERROR: It looks like someone broke the Nio Output\n" << " Attempting to recover by defaulting to the\n" << " Null Engine." << endl; @@ -98,32 +95,31 @@ bool EngineMgr::start() defaultIn = dynamic_cast(getEng("NULL")); } - OutMgr::getInstance().currentOut = defaultOut; - InMgr::getInstance().current = defaultIn; + OutMgr::getInstance(). currentOut = defaultOut; + InMgr::getInstance(). current = defaultIn; //open up the default output(s) cout << "Starting Audio: " << defaultOut->name << endl; defaultOut->setAudioEn(true); - if(defaultOut->getAudioEn()) { + if(defaultOut->getAudioEn()) cout << "Audio Started" << endl; - } - else { + else { expected = false; cerr << "ERROR: The default audio output failed to open!" << endl; - OutMgr::getInstance().currentOut = dynamic_cast(getEng("NULL")); - OutMgr::getInstance().currentOut->setAudioEn(true); + OutMgr::getInstance(). currentOut = + dynamic_cast(getEng("NULL")); + OutMgr::getInstance(). currentOut->setAudioEn(true); } cout << "Starting MIDI: " << defaultIn->name << endl; defaultIn->setMidiEn(true); - if(defaultIn->getMidiEn()) { + if(defaultIn->getMidiEn()) cout << "MIDI Started" << endl; - } else { //recover expected = false; cerr << "ERROR: The default MIDI input failed to open!" << endl; - InMgr::getInstance().current = dynamic_cast(getEng("NULL")); - InMgr::getInstance().current->setMidiEn(true); + InMgr::getInstance(). current = dynamic_cast(getEng("NULL")); + InMgr::getInstance(). current->setMidiEn(true); } //Show if expected drivers were booted @@ -132,29 +128,27 @@ bool EngineMgr::start() void EngineMgr::stop() { - for(list::iterator itr = engines.begin(); - itr != engines.end(); ++itr) + for(list::iterator itr = engines.begin(); + itr != engines.end(); ++itr) (*itr)->Stop(); } bool EngineMgr::setInDefault(string name) { - MidiIn *chosen; - if((chosen = dynamic_cast(getEng(name)))){ //got the input - defaultIn = chosen; - return true; - } - return false; + MidiIn *chosen; + if((chosen = dynamic_cast(getEng(name)))) { //got the input + defaultIn = chosen; + return true; + } + return false; } bool EngineMgr::setOutDefault(string name) { - AudioOut *chosen; - if((chosen = dynamic_cast(getEng(name)))){ //got the output - defaultOut = chosen; - return true; - } - return false; + AudioOut *chosen; + if((chosen = dynamic_cast(getEng(name)))) { //got the output + defaultOut = chosen; + return true; + } + return false; } - - diff --git a/src/Nio/EngineMgr.h b/src/Nio/EngineMgr.h index d545bb58..4d56d299 100644 --- a/src/Nio/EngineMgr.h +++ b/src/Nio/EngineMgr.h @@ -41,4 +41,3 @@ class EngineMgr EngineMgr(); }; #endif - diff --git a/src/Nio/InMgr.cpp b/src/Nio/InMgr.cpp index 95b8d1fc..c3e2f55c 100644 --- a/src/Nio/InMgr.cpp +++ b/src/Nio/InMgr.cpp @@ -6,21 +6,21 @@ using namespace std; -ostream &operator<<(ostream &out, const MidiEvent& ev) +ostream &operator<<(ostream &out, const MidiEvent &ev) { if(ev.type == M_NOTE) - out << "MidiNote: note(" << ev.num << ")\n" - << " channel(" << ev.channel << ")\n" - << " velocity(" << ev.value << ")"; + out << "MidiNote: note(" << ev.num << ")\n" + << " channel(" << ev.channel << ")\n" + << " velocity(" << ev.value << ")"; else - out << "MidiCtl: controller(" << ev.num << ")\n" - << " channel(" << ev.channel << ")\n" - << " value(" << ev.value << ")"; + out << "MidiCtl: controller(" << ev.num << ")\n" + << " channel(" << ev.channel << ")\n" + << " value(" << ev.value << ")"; return out; } MidiEvent::MidiEvent() - :channel(0),type(0),num(0),value(0) + :channel(0), type(0), num(0), value(0) {} InMgr &InMgr::getInstance() @@ -106,4 +106,3 @@ MidiIn *InMgr::getIn(string name) EngineMgr &eng = EngineMgr::getInstance(); return dynamic_cast(eng.getEng(name)); } - diff --git a/src/Nio/InMgr.h b/src/Nio/InMgr.h index 1febe271..e7ddd69e 100644 --- a/src/Nio/InMgr.h +++ b/src/Nio/InMgr.h @@ -5,13 +5,12 @@ #include #include "SafeQueue.h" -enum midi_type{ +enum midi_type { M_NOTE = 1, M_CONTROLLER = 2 }; //type=1 for note, type=2 for controller -struct MidiEvent -{ +struct MidiEvent { MidiEvent(); int channel; //the midi channel for the event int type; //type=1 for note, type=2 for controller @@ -41,11 +40,10 @@ class InMgr class MidiIn *getIn(std::string name); SafeQueue queue; sem_t work; - class MidiIn *current; + class MidiIn * current; /**the link to the rest of zyn*/ - class Master &master; + class Master & master; }; #endif - diff --git a/src/Nio/JackEngine.cpp b/src/Nio/JackEngine.cpp index 0a506c39..34549155 100644 --- a/src/Nio/JackEngine.cpp +++ b/src/Nio/JackEngine.cpp @@ -37,10 +37,9 @@ JackEngine::JackEngine() { name = "JACK"; audio.jackSamplerate = 0; - audio.jackNframes = 0; - for (int i = 0; i < 2; ++i) - { - audio.ports[i] = NULL; + audio.jackNframes = 0; + for(int i = 0; i < 2; ++i) { + audio.ports[i] = NULL; audio.portBuffs[i] = NULL; } midi.inport = NULL; @@ -54,24 +53,26 @@ bool JackEngine::connectServer(string server) string clientname = "zynaddsubfx"; - string postfix = Nio::getInstance().getPostfix(); + string postfix = Nio::getInstance().getPostfix(); if(!postfix.empty()) clientname += "_" + postfix; jack_status_t jackstatus; bool use_server_name = server.size() && server.compare("default") != 0; jack_options_t jopts = (jack_options_t) - (((use_server_name) ? JackServerName : JackNullOption) - | ((autostart_jack) ? JackNullOption : JackNoStartServer)); - if (use_server_name) + (((use_server_name) ? JackServerName : + JackNullOption) + | ((autostart_jack) ? JackNullOption : + JackNoStartServer)); + if(use_server_name) jackClient = jack_client_open(clientname.c_str(), jopts, &jackstatus, - server.c_str()); + server.c_str()); else jackClient = jack_client_open(clientname.c_str(), jopts, &jackstatus); - if (NULL != jackClient) + if(NULL != jackClient) return true; else cerr << "Error, failed to open jack client on server: " << server - << " status " << jackstatus << endl; + << " status " << jackstatus << endl; return false; return true; @@ -80,24 +81,21 @@ bool JackEngine::connectServer(string server) bool JackEngine::connectJack() { connectServer(""); - if (NULL != jackClient) - { + if(NULL != jackClient) { setBufferSize(jack_get_buffer_size(jackClient)); int chk; jack_set_error_function(_errorCallback); jack_set_info_function(_infoCallback); if(jack_set_buffer_size_callback(jackClient, _bufferSizeCallback, this)) cerr << "Error setting the bufferSize callback" << endl; - if ((chk = jack_set_xrun_callback(jackClient, _xrunCallback, this))) + if((chk = jack_set_xrun_callback(jackClient, _xrunCallback, this))) cerr << "Error setting jack xrun callback" << endl; - if (jack_set_process_callback(jackClient, _processCallback, this)) - { + if(jack_set_process_callback(jackClient, _processCallback, this)) { cerr << "Error, JackEngine failed to set process callback" << endl; return false; } - if (jack_activate(jackClient)) - { - cerr << "Error, failed to activate jack client" << endl;; + if(jack_activate(jackClient)) { + cerr << "Error, failed to activate jack client" << endl; return false; } @@ -164,31 +162,38 @@ bool JackEngine::openAudio() const char *portnames[] = { "out_1", "out_2" }; - for (int port = 0; port < 2; ++port) - { - audio.ports[port] = jack_port_register(jackClient, portnames[port], - JACK_DEFAULT_AUDIO_TYPE, - JackPortIsOutput | JackPortIsTerminal, 0); - } - if (NULL != audio.ports[0] && NULL != audio.ports[1]) - { + for(int port = 0; port < 2; ++port) + audio.ports[port] = jack_port_register( + jackClient, + portnames[port], + JACK_DEFAULT_AUDIO_TYPE, + JackPortIsOutput + | JackPortIsTerminal, + 0); + if((NULL != audio.ports[0]) && (NULL != audio.ports[1])) { audio.jackSamplerate = jack_get_sample_rate(jackClient); - audio.jackNframes = jack_get_buffer_size(jackClient); + audio.jackNframes = jack_get_buffer_size(jackClient); //Attempt to autoConnect when specified - if(Nio::getInstance().autoConnect) - { - const char **outPorts = jack_get_ports(jackClient, NULL, NULL, - JackPortIsPhysical|JackPortIsInput); + if(Nio::getInstance().autoConnect) { + const char **outPorts = jack_get_ports( + jackClient, + NULL, + NULL, + JackPortIsPhysical + | JackPortIsInput); if(outPorts != NULL) { //Verify that stereo is available assert(outPorts[0]); assert(outPorts[1]); //Connect to physical outputs - jack_connect(jackClient, jack_port_name(audio.ports[0]), outPorts[0]); - jack_connect(jackClient, jack_port_name(audio.ports[1]), outPorts[1]); - } else + jack_connect(jackClient, jack_port_name( + audio.ports[0]), outPorts[0]); + jack_connect(jackClient, jack_port_name( + audio.ports[1]), outPorts[1]); + } + else cerr << "Warning, No outputs to autoconnect to" << endl; } return true; @@ -200,11 +205,10 @@ bool JackEngine::openAudio() void JackEngine::stopAudio() { - for (int i = 0; i < 2; ++i) - { + for(int i = 0; i < 2; ++i) { jack_port_t *port = audio.ports[i]; audio.ports[i] = NULL; - if (NULL != port) + if(NULL != port) jack_port_unregister(jackClient, port); } if(!getMidiEn()) @@ -238,7 +242,7 @@ void JackEngine::stopMidi() int JackEngine::clientId() { - if (NULL != jackClient) + if(NULL != jackClient) return (long)jack_client_thread_id(jackClient); else return -1; @@ -246,7 +250,7 @@ int JackEngine::clientId() string JackEngine::clientName() { - if (NULL != jackClient) + if(NULL != jackClient) return string(jack_get_client_name(jackClient)); else cerr << "Error, clientName() with null jackClient" << endl; @@ -255,30 +259,28 @@ string JackEngine::clientName() int JackEngine::_processCallback(jack_nframes_t nframes, void *arg) { - return static_cast(arg)->processCallback(nframes); + return static_cast(arg)->processCallback(nframes); } int JackEngine::processCallback(jack_nframes_t nframes) { bool okaudio = true; - if (NULL != audio.ports[0] && NULL != audio.ports[1]) + if((NULL != audio.ports[0]) && (NULL != audio.ports[1])) okaudio = processAudio(nframes); - if (okaudio) - handleMidi(nframes); + if(okaudio) + handleMidi(nframes); return okaudio ? 0 : -1; } bool JackEngine::processAudio(jack_nframes_t nframes) { - for (int port = 0; port < 2; ++port) - { + for(int port = 0; port < 2; ++port) { audio.portBuffs[port] = - (jsample_t*)jack_port_get_buffer(audio.ports[port], nframes); - if (NULL == audio.portBuffs[port]) - { + (jsample_t *)jack_port_get_buffer(audio.ports[port], nframes); + if(NULL == audio.portBuffs[port]) { cerr << "Error, failed to get jack audio port buffer: " - << port << endl; + << port << endl; return false; } } @@ -286,10 +288,9 @@ bool JackEngine::processAudio(jack_nframes_t nframes) Stereo smp = getNext(); //Assumes size of smp.l == nframes - memcpy(audio.portBuffs[0], smp.l, bufferSize*sizeof(float)); - memcpy(audio.portBuffs[1], smp.r, bufferSize*sizeof(float)); + memcpy(audio.portBuffs[0], smp.l, bufferSize * sizeof(float)); + memcpy(audio.portBuffs[1], smp.r, bufferSize * sizeof(float)); return true; - } int JackEngine::_xrunCallback(void * /*/arg*/) @@ -310,7 +311,7 @@ void JackEngine::_infoCallback(const char *msg) int JackEngine::_bufferSizeCallback(jack_nframes_t nframes, void *arg) { - return static_cast(arg)->bufferSizeCallback(nframes); + return static_cast(arg)->bufferSizeCallback(nframes); } int JackEngine::bufferSizeCallback(jack_nframes_t nframes) @@ -331,7 +332,7 @@ void JackEngine::handleMidi(unsigned long frames) unsigned char type; while(jack_midi_event_get(&jack_midi_event, midi_buf, - event_index++) == 0) { + event_index++) == 0) { MidiEvent ev; midi_data = jack_midi_event.buffer; type = midi_data[0] & 0xF0; @@ -339,30 +340,30 @@ void JackEngine::handleMidi(unsigned long frames) switch(type) { case 0x80: /* note-off */ - ev.type = M_NOTE; - ev.num = midi_data[1]; - ev.value = 0; + ev.type = M_NOTE; + ev.num = midi_data[1]; + ev.value = 0; InMgr::getInstance().putEvent(ev); break; case 0x90: /* note-on */ - ev.type = M_NOTE; - ev.num = midi_data[1]; - ev.value = midi_data[2]; + ev.type = M_NOTE; + ev.num = midi_data[1]; + ev.value = midi_data[2]; InMgr::getInstance().putEvent(ev); break; case 0xB0: /* controller */ - ev.type = M_CONTROLLER; - ev.num = midi_data[1]; - ev.value = midi_data[2]; + ev.type = M_CONTROLLER; + ev.num = midi_data[1]; + ev.value = midi_data[2]; InMgr::getInstance().putEvent(ev); break; case 0xE0: /* pitch bend */ - ev.type = M_CONTROLLER; - ev.num = C_pitchwheel; - ev.value = ((midi_data[2] << 7) | midi_data[1]) - 8192; + ev.type = M_CONTROLLER; + ev.num = C_pitchwheel; + ev.value = ((midi_data[2] << 7) | midi_data[1]) - 8192; InMgr::getInstance().putEvent(ev); break; @@ -370,4 +371,3 @@ void JackEngine::handleMidi(unsigned long frames) } } } - diff --git a/src/Nio/JackEngine.h b/src/Nio/JackEngine.h index dc1ab7a4..fe60a0c3 100644 --- a/src/Nio/JackEngine.h +++ b/src/Nio/JackEngine.h @@ -31,11 +31,11 @@ typedef jack_default_audio_sample_t jsample_t; -class JackEngine : public AudioOut, MidiIn +class JackEngine:public AudioOut, MidiIn { public: JackEngine(); - ~JackEngine() { }; + ~JackEngine() { } bool Start(); void Stop(); @@ -46,8 +46,8 @@ class JackEngine : public AudioOut, MidiIn void setAudioEn(bool nval); bool getAudioEn() const; - unsigned int getSamplerate() { return audio.jackSamplerate; }; - unsigned int getBuffersize() { return audio.jackNframes; }; + unsigned int getSamplerate() { return audio.jackSamplerate; } + unsigned int getBuffersize() { return audio.jackNframes; } std::string clientName(); int clientId(); @@ -72,14 +72,14 @@ class JackEngine : public AudioOut, MidiIn bool openMidi(); void stopMidi(); - jack_client_t *jackClient; - struct audio{ - unsigned int jackSamplerate; - unsigned int jackNframes; - jack_port_t *ports[2]; - jsample_t *portBuffs[2]; + jack_client_t *jackClient; + struct audio { + unsigned int jackSamplerate; + unsigned int jackNframes; + jack_port_t *ports[2]; + jsample_t *portBuffs[2]; } audio; - struct midi{ + struct midi { jack_port_t *inport; } midi; diff --git a/src/Nio/MidiIn.cpp b/src/Nio/MidiIn.cpp index 22d6702d..5cc9767b 100644 --- a/src/Nio/MidiIn.cpp +++ b/src/Nio/MidiIn.cpp @@ -24,12 +24,13 @@ #include "../globals.h" #include "InMgr.h" -void MidiIn::midiProcess(unsigned char head, unsigned char num, unsigned char value) +void MidiIn::midiProcess(unsigned char head, + unsigned char num, + unsigned char value) { - MidiEvent ev; + MidiEvent ev; unsigned char chan = head & 0x0f; - switch(head & 0xf0) - { + switch(head & 0xf0) { case 0x80: //Note Off ev.type = M_NOTE; ev.channel = chan; diff --git a/src/Nio/MidiIn.h b/src/Nio/MidiIn.h index a4f15be3..780a67ff 100644 --- a/src/Nio/MidiIn.h +++ b/src/Nio/MidiIn.h @@ -28,15 +28,16 @@ #include "Engine.h" /**This class is inherited by all the Midi input classes*/ -class MidiIn : public virtual Engine +class MidiIn:public virtual Engine { public: /**Enables or disables driver based upon value*/ - virtual void setMidiEn(bool nval)=0; + virtual void setMidiEn(bool nval) = 0; /**Returns if driver is initialized*/ - virtual bool getMidiEn() const=0; - static void midiProcess(unsigned char head, unsigned char num, unsigned char value); + virtual bool getMidiEn() const = 0; + static void midiProcess(unsigned char head, + unsigned char num, + unsigned char value); }; #endif - diff --git a/src/Nio/Nio.cpp b/src/Nio/Nio.cpp index aa3230e4..181ae28e 100644 --- a/src/Nio/Nio.cpp +++ b/src/Nio/Nio.cpp @@ -14,11 +14,11 @@ Nio &Nio::getInstance() } Nio::Nio() -:autoConnect(false), - in(InMgr::getInstance()),//Enable input wrapper - out(OutMgr::getInstance()),//Initialize the Output Systems - eng(EngineMgr::getInstance()),//Initialize The Engines - postfix("")//no default postfix + :autoConnect(false), + in(InMgr::getInstance()), //Enable input wrapper + out(OutMgr::getInstance()), //Initialize the Output Systems + eng(EngineMgr::getInstance()), //Initialize The Engines + postfix("") //no default postfix {} Nio::~Nio() @@ -28,14 +28,14 @@ Nio::~Nio() bool Nio::start() { - return eng.start();//Drivers start your engines! + return eng.start(); //Drivers start your engines! } void Nio::stop() { eng.stop(); } - + int Nio::setDefaultSource(string name) { if(name.empty()) @@ -47,27 +47,26 @@ int Nio::setDefaultSource(string name) } return 0; } - + int Nio::setDefaultSink(string name) { if(name.empty()) return 0; - if(!eng.setOutDefault(name)) { + if(!eng.setOutDefault(name)) cerr << "There is no output for " << name << endl; - } return 0; } bool Nio::setSource(string name) { - return in.setSource(name); + return in.setSource(name); } bool Nio::setSink(string name) { - return out.setSink(name); + return out.setSink(name); } void Nio::setPostfix(std::string post) @@ -80,12 +79,12 @@ std::string Nio::getPostfix(void) const return postfix; } - + set Nio::getSources() const { set sources; for(list::iterator itr = eng.engines.begin(); - itr != eng.engines.end(); ++itr) + itr != eng.engines.end(); ++itr) if(dynamic_cast(*itr)) sources.insert((*itr)->name); return sources; @@ -95,19 +94,18 @@ set Nio::getSinks() const { set sinks; for(list::iterator itr = eng.engines.begin(); - itr != eng.engines.end(); ++itr) + itr != eng.engines.end(); ++itr) if(dynamic_cast(*itr)) sinks.insert((*itr)->name); return sinks; } - + string Nio::getSource() const { - return in.getSource(); + return in.getSource(); } string Nio::getSink() const { - return out.getSink(); + return out.getSink(); } - diff --git a/src/Nio/Nio.h b/src/Nio/Nio.h index 74aac439..0ac5ac42 100644 --- a/src/Nio/Nio.h +++ b/src/Nio/Nio.h @@ -1,10 +1,10 @@ -#ifndef NIO_H +#ifndef NIO_H #define NIO_H #include #include /**Interface to Nio Subsystem - * + * * Should be only externally included header */ class Nio { @@ -34,11 +34,10 @@ class Nio private: Nio(); - class InMgr ∈ - class OutMgr &out; - class EngineMgr ŋ + class InMgr & in; + class OutMgr & out; + class EngineMgr & eng; std::string postfix; }; #endif - diff --git a/src/Nio/NulEngine.cpp b/src/Nio/NulEngine.cpp index 745c4b1d..a8630b02 100644 --- a/src/Nio/NulEngine.cpp +++ b/src/Nio/NulEngine.cpp @@ -37,7 +37,7 @@ NulEngine::NulEngine() void *NulEngine::_AudioThread(void *arg) { - return (static_cast(arg))->AudioThread(); + return (static_cast(arg))->AudioThread(); } void *NulEngine::AudioThread() @@ -52,9 +52,9 @@ void *NulEngine::AudioThread() playing_until.tv_usec = now.tv_usec; playing_until.tv_sec = now.tv_sec; } - else { + else { remaining = (playing_until.tv_usec - now.tv_usec) - + (playing_until.tv_sec - now.tv_sec) * 1000000; + + (playing_until.tv_sec - now.tv_sec) * 1000000; if(remaining > 10000) //Don't sleep() less than 10ms. //This will add latency... usleep(remaining - 10000); @@ -71,8 +71,7 @@ void *NulEngine::AudioThread() } NulEngine::~NulEngine() -{ -} +{} bool NulEngine::Start() { @@ -89,7 +88,7 @@ void NulEngine::setAudioEn(bool nval) { if(nval) { if(!getAudioEn()) { - pthread_t *thread = new pthread_t; + pthread_t *thread = new pthread_t; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); @@ -97,13 +96,12 @@ void NulEngine::setAudioEn(bool nval) pthread_create(pThread, &attr, _AudioThread, this); } } - else { - if(getAudioEn()) { - pthread_t *thread = pThread; - pThread = NULL; - pthread_join(*thread, NULL); - delete thread; - } + else + if(getAudioEn()) { + pthread_t *thread = pThread; + pThread = NULL; + pthread_join(*thread, NULL); + delete thread; } } @@ -111,4 +109,3 @@ bool NulEngine::getAudioEn() const { return pThread; } - diff --git a/src/Nio/NulEngine.h b/src/Nio/NulEngine.h index 240b68f7..1ee817d3 100644 --- a/src/Nio/NulEngine.h +++ b/src/Nio/NulEngine.h @@ -29,7 +29,7 @@ #include "AudioOut.h" #include "MidiIn.h" -class NulEngine: public AudioOut, MidiIn +class NulEngine:public AudioOut, MidiIn { public: NulEngine(); @@ -41,8 +41,8 @@ class NulEngine: public AudioOut, MidiIn void setAudioEn(bool nval); bool getAudioEn() const; - void setMidiEn(bool){}; - bool getMidiEn() const{return true;}; + void setMidiEn(bool) {} + bool getMidiEn() const {return true;} protected: void *AudioThread(); @@ -50,8 +50,7 @@ class NulEngine: public AudioOut, MidiIn private: struct timeval playing_until; - pthread_t *pThread; + pthread_t *pThread; }; #endif - diff --git a/src/Nio/OssEngine.cpp b/src/Nio/OssEngine.cpp index c3c59ed9..15031c2e 100644 --- a/src/Nio/OssEngine.cpp +++ b/src/Nio/OssEngine.cpp @@ -65,7 +65,7 @@ bool OssEngine::openAudio() int snd_fragment = 0x00080009; //fragment size (?); int snd_stereo = 1; //stereo; int snd_format = AFMT_S16_LE; - int snd_samplerate = SAMPLE_RATE;; + int snd_samplerate = SAMPLE_RATE; audio.handle = open(config.cfg.LinuxOSSWaveOutDev, O_WRONLY, 0); if(audio.handle == -1) { @@ -79,7 +79,7 @@ bool OssEngine::openAudio() ioctl(audio.handle, SNDCTL_DSP_SPEED, &snd_samplerate); ioctl(audio.handle, SNDCTL_DSP_SAMPLESIZE, &snd_bitsize); ioctl(audio.handle, SNDCTL_DSP_SETFRAGMENT, &snd_fragment); - + if(!getMidiEn()) { pthread_attr_t attr; pthread_attr_init(&attr); @@ -102,7 +102,7 @@ void OssEngine::stopAudio() pthread_join(*engThread, NULL); delete engThread; engThread = NULL; - + close(handle); } @@ -159,15 +159,14 @@ bool OssEngine::openMidi() { int handle = midi.handle; if(handle != -1) - return true;//already open + return true; //already open handle = open(config.cfg.LinuxOSSSeqInDev, O_RDONLY, 0); - if(-1 == handle) { + if(-1 == handle) return false; - } midi.handle = handle; - + if(!getAudioEn()) { pthread_attr_t attr; pthread_attr_init(&attr); @@ -186,29 +185,27 @@ void OssEngine::stopMidi() return; midi.handle = -1; - + if(!getAudioEn() && engThread) { pthread_join(*engThread, NULL); delete engThread; engThread = NULL; } - + close(handle); } void *OssEngine::_thread(void *arg) { - return (static_cast(arg))->thread(); + return (static_cast(arg))->thread(); } void *OssEngine::thread() { unsigned char tmp[4] = {0, 0, 0, 0}; set_realtime(); - while (getAudioEn() || getMidiEn()) - { - if(getAudioEn()) - { + while(getAudioEn() || getMidiEn()) { + if(getAudioEn()) { const Stereo smps = getNext(); float l, r; @@ -219,13 +216,13 @@ void *OssEngine::thread() if(l < -1.0f) l = -1.0f; else - if(l > 1.0f) - l = 1.0f; + if(l > 1.0f) + l = 1.0f; if(r < -1.0f) r = -1.0f; else - if(r > 1.0f) - r = 1.0f; + if(r > 1.0f) + r = 1.0f; audio.smps[i * 2] = (short int) (l * 32767.0f); audio.smps[i * 2 + 1] = (short int) (r * 32767.0f); @@ -238,33 +235,36 @@ void *OssEngine::thread() } //Collect up to 30 midi events - for (int k = 0; k < 30 && getMidiEn(); ++k) { + for(int k = 0; k < 30 && getMidiEn(); ++k) { static char escaped; memset(tmp, 0, 4); - if (escaped) { - tmp[0] = escaped; + if(escaped) { + tmp[0] = escaped; escaped = 0; - } else { + } + else { getMidi(tmp); - if (!(tmp[0] & 0x80)) + if(!(tmp[0] & 0x80)) continue; } getMidi(tmp + 1); - if (tmp[1] & 0x80) { + if(tmp[1] & 0x80) { escaped = tmp[1]; - tmp[1] = 0; - } else { + tmp[1] = 0; + } + else { getMidi(tmp + 2); - if (tmp[2] & 0x80) { + if(tmp[2] & 0x80) { escaped = tmp[2]; - tmp[2] = 0; - } else { + tmp[2] = 0; + } + else { getMidi(tmp + 3); - if (tmp[3] & 0x80) { + if(tmp[3] & 0x80) { escaped = tmp[3]; - tmp[3] = 0; + tmp[3] = 0; } } } @@ -279,4 +279,3 @@ void OssEngine::getMidi(unsigned char *midiPtr) { read(midi.handle, midiPtr, 1); } - diff --git a/src/Nio/OssEngine.h b/src/Nio/OssEngine.h index 5033418c..cdccc812 100644 --- a/src/Nio/OssEngine.h +++ b/src/Nio/OssEngine.h @@ -28,7 +28,7 @@ #include "AudioOut.h" #include "MidiIn.h" -class OssEngine: public AudioOut, MidiIn +class OssEngine:public AudioOut, MidiIn { public: OssEngine(); @@ -55,7 +55,7 @@ class OssEngine: public AudioOut, MidiIn bool openAudio(); void stopAudio(); - struct audio{ + struct audio { int handle; short int *smps; //Samples to be sent to soundcard bool en; @@ -66,12 +66,11 @@ class OssEngine: public AudioOut, MidiIn void stopMidi(); void getMidi(unsigned char *midiPtr); - struct midi{ - int handle; + struct midi { + int handle; bool en; bool run; } midi; }; #endif - diff --git a/src/Nio/OutMgr.cpp b/src/Nio/OutMgr.cpp index a706968b..c63e76df 100644 --- a/src/Nio/OutMgr.cpp +++ b/src/Nio/OutMgr.cpp @@ -7,8 +7,8 @@ #include "InMgr.h" #include "WavEngine.h" #include "../Misc/Master.h" -#include "../Misc/Util.h"//for set_realtime() -#include "../Samples/Sample.h"//for resampling +#include "../Misc/Util.h" //for set_realtime() +#include "../Samples/Sample.h" //for resampling using namespace std; @@ -20,16 +20,18 @@ OutMgr &OutMgr::getInstance() OutMgr::OutMgr() :wave(new WavEngine()), - priBuf(new float[4096],new float[4096]),priBuffCurrent(priBuf),master(Master::getInstance()) + priBuf(new float[4096], + new float[4096]), priBuffCurrent(priBuf), + master(Master::getInstance()) { currentOut = NULL; - stales = 0; - master = Master::getInstance(); + stales = 0; + master = Master::getInstance(); //init samples outr = new float[SOUND_BUFFER_SIZE]; outl = new float[SOUND_BUFFER_SIZE]; -}; +} OutMgr::~OutMgr() { @@ -62,7 +64,7 @@ const Stereo OutMgr::tick(unsigned int frameSize) pthread_mutex_lock(&(master.mutex)); master.AudioOut(outl, outr); pthread_mutex_unlock(&(master.mutex)); - addSmps(outl,outr); + addSmps(outl, outr); } Stereo ans = priBuffCurrent; ans.l -= frameSize; @@ -117,19 +119,23 @@ string OutMgr::getSink() const void OutMgr::addSmps(float *l, float *r) { //allow wave file to syphon off stream - wave->push(Stereo(l,r),SOUND_BUFFER_SIZE); + wave->push(Stereo(l, r), SOUND_BUFFER_SIZE); if(currentOut->getSampleRate() != SAMPLE_RATE) { //we need to resample //cout << "BAD RESAMPLING" << endl; - Stereo smps(Sample(SOUND_BUFFER_SIZE, l), Sample(SOUND_BUFFER_SIZE, r)); - smps.l.resample(SAMPLE_RATE,currentOut->getSampleRate()); - smps.r.resample(SAMPLE_RATE,currentOut->getSampleRate()); - memcpy(priBuffCurrent.l, smps.l.c_buf(), SOUND_BUFFER_SIZE*sizeof(float)); - memcpy(priBuffCurrent.r, smps.r.c_buf(), SOUND_BUFFER_SIZE*sizeof(float)); + Stereo smps(Sample(SOUND_BUFFER_SIZE, l), Sample( + SOUND_BUFFER_SIZE, + r)); + smps.l.resample(SAMPLE_RATE, currentOut->getSampleRate()); + smps.r.resample(SAMPLE_RATE, currentOut->getSampleRate()); + memcpy(priBuffCurrent.l, smps.l.c_buf(), SOUND_BUFFER_SIZE + * sizeof(float)); + memcpy(priBuffCurrent.r, smps.r.c_buf(), SOUND_BUFFER_SIZE + * sizeof(float)); } else { //just copy the samples - memcpy(priBuffCurrent.l, l, SOUND_BUFFER_SIZE*sizeof(float)); - memcpy(priBuffCurrent.r, r, SOUND_BUFFER_SIZE*sizeof(float)); + memcpy(priBuffCurrent.l, l, SOUND_BUFFER_SIZE * sizeof(float)); + memcpy(priBuffCurrent.r, r, SOUND_BUFFER_SIZE * sizeof(float)); } priBuffCurrent.l += SOUND_BUFFER_SIZE; priBuffCurrent.r += SOUND_BUFFER_SIZE; @@ -142,9 +148,8 @@ void OutMgr::removeStaleSmps() return; //memset is possibly unneeded - memset(priBuf.l, '0', 4096*sizeof(float)); - memset(priBuf.r, '0', 4096*sizeof(float)); + memset(priBuf.l, '0', 4096 * sizeof(float)); + memset(priBuf.r, '0', 4096 * sizeof(float)); priBuffCurrent = priBuf; stales = 0; } - diff --git a/src/Nio/OutMgr.h b/src/Nio/OutMgr.h index 56c3d754..e5037b58 100644 --- a/src/Nio/OutMgr.h +++ b/src/Nio/OutMgr.h @@ -21,7 +21,7 @@ class OutMgr /**Request a new set of samples * @param n number of requested samples (defaults to 1) * @return -1 for locking issues 0 for valid request*/ - void requestSamples(unsigned int n=1); + void requestSamples(unsigned int n = 1); /**Gets requested driver * @param name case unsensitive name of driver @@ -39,15 +39,15 @@ class OutMgr std::string getSink() const; - class WavEngine *wave; /**defaultLowOutputLatency; outputParameters.hostApiSpecificStreamInfo = NULL; @@ -82,10 +82,12 @@ bool PaEngine::getAudioEn() const return stream; } -int PaEngine::PAprocess(const void *inputBuffer, void *outputBuffer, - unsigned long framesPerBuffer, - const PaStreamCallbackTimeInfo *outTime, PaStreamCallbackFlags flags, - void *userData) +int PaEngine::PAprocess(const void *inputBuffer, + void *outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo *outTime, + PaStreamCallbackFlags flags, + void *userData) { (void) inputBuffer; (void) outTime; @@ -114,4 +116,3 @@ void PaEngine::Stop() stream = NULL; Pa_Terminate(); } - diff --git a/src/Nio/PaEngine.h b/src/Nio/PaEngine.h index 88d4ef10..12fd766a 100644 --- a/src/Nio/PaEngine.h +++ b/src/Nio/PaEngine.h @@ -27,7 +27,7 @@ #include "../globals.h" #include "AudioOut.h" -class PaEngine: public AudioOut +class PaEngine:public AudioOut { public: PaEngine(); @@ -40,10 +40,12 @@ class PaEngine: public AudioOut bool getAudioEn() const; protected: - static int PAprocess(const void *inputBuffer, void *outputBuffer, - unsigned long framesPerBuffer, - const PaStreamCallbackTimeInfo *outTime, PaStreamCallbackFlags flags, - void *userData); + static int PAprocess(const void *inputBuffer, + void *outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo *outTime, + PaStreamCallbackFlags flags, + void *userData); int process(float *out, unsigned long framesPerBuffer); private: PaStream *stream; @@ -53,4 +55,3 @@ class PaEngine: public AudioOut void PAfinish(); #endif - diff --git a/src/Nio/SafeQueue.cpp b/src/Nio/SafeQueue.cpp index 3df68fd0..734413c6 100644 --- a/src/Nio/SafeQueue.cpp +++ b/src/Nio/SafeQueue.cpp @@ -1,9 +1,9 @@ template SafeQueue::SafeQueue(size_t maxlen) - :writePtr(0),readPtr(0),bufSize(maxlen) + :writePtr(0), readPtr(0), bufSize(maxlen) { - sem_init(&w_space, PTHREAD_PROCESS_PRIVATE, maxlen-1); + sem_init(&w_space, PTHREAD_PROCESS_PRIVATE, maxlen - 1); sem_init(&r_space, PTHREAD_PROCESS_PRIVATE, 0); buffer = new T[maxlen]; } @@ -47,10 +47,10 @@ int SafeQueue::push(const T &in) //ok, there is space to write size_t w = (writePtr + 1) % bufSize; buffer[w] = in; - writePtr = w; + writePtr = w; //adjust ranges - sem_wait(&w_space);//guaranteed not to wait + sem_wait(&w_space); //guaranteed not to wait sem_post(&r_space); return 0; } @@ -63,11 +63,11 @@ int SafeQueue::pop(T &out) //ok, there is space to read size_t r = (readPtr + 1) % bufSize; - out = buffer[r]; + out = buffer[r]; readPtr = r; //adjust ranges - sem_wait(&r_space);//guaranteed not to wait + sem_wait(&r_space); //guaranteed not to wait sem_post(&w_space); return 0; } diff --git a/src/Nio/SafeQueue.h b/src/Nio/SafeQueue.h index 99cfb2e8..7b41166b 100644 --- a/src/Nio/SafeQueue.h +++ b/src/Nio/SafeQueue.h @@ -7,7 +7,7 @@ /** * C++ thread safe lockless queue * Based off of jack's ringbuffer*/ -template +template class SafeQueue { public: diff --git a/src/Nio/WavEngine.cpp b/src/Nio/WavEngine.cpp index a2c7f0ec..8eb9c4b2 100644 --- a/src/Nio/WavEngine.cpp +++ b/src/Nio/WavEngine.cpp @@ -26,7 +26,7 @@ using namespace std; WavEngine::WavEngine() - :AudioOut(), file(NULL), buffer(SAMPLE_RATE*4), pThread(NULL) + :AudioOut(), file(NULL), buffer(SAMPLE_RATE * 4), pThread(NULL) { sem_init(&work, PTHREAD_PROCESS_PRIVATE, 0); } @@ -92,7 +92,9 @@ void WavEngine::newFile(WavFile *_file) //check state if(!file->good()) - cerr << "ERROR: WavEngine handed bad file output WavEngine::newFile()" << endl; + cerr + << "ERROR: WavEngine handed bad file output WavEngine::newFile()" + << endl; } void WavEngine::destroyFile() @@ -104,21 +106,24 @@ void WavEngine::destroyFile() void *WavEngine::_AudioThread(void *arg) { - return (static_cast(arg))->AudioThread(); + return (static_cast(arg))->AudioThread(); } void *WavEngine::AudioThread() { - short *recordbuf_16bit = new short[2*SOUND_BUFFER_SIZE]; + short *recordbuf_16bit = new short[2 * SOUND_BUFFER_SIZE]; - while(!sem_wait(&work) && pThread) - { + while(!sem_wait(&work) && pThread) { for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { - float left=0.0f, right=0.0f; + float left = 0.0f, right = 0.0f; buffer.pop(left); buffer.pop(right); - recordbuf_16bit[2*i] = limit((int)(left * 32767.0f), -32768, 32767); - recordbuf_16bit[2*i+1] = limit((int)(right * 32767.0f), -32768, 32767); + recordbuf_16bit[2 * i] = limit((int)(left * 32767.0f), + -32768, + 32767); + recordbuf_16bit[2 * i + 1] = limit((int)(right * 32767.0f), + -32768, + 32767); } file->writeStereoSamples(SOUND_BUFFER_SIZE, recordbuf_16bit); } @@ -127,4 +132,3 @@ void *WavEngine::AudioThread() return NULL; } - diff --git a/src/Nio/WavEngine.h b/src/Nio/WavEngine.h index 904dd86d..01fcd131 100644 --- a/src/Nio/WavEngine.h +++ b/src/Nio/WavEngine.h @@ -29,7 +29,7 @@ #include "SafeQueue.h" class WavFile; -class WavEngine: public AudioOut +class WavEngine:public AudioOut { public: WavEngine(); @@ -39,8 +39,8 @@ class WavEngine: public AudioOut bool Start(); void Stop(); - void setAudioEn(bool /*nval*/){}; - bool getAudioEn() const{return true;}; + void setAudioEn(bool /*nval*/) {} + bool getAudioEn() const {return true;} void push(Stereo smps, size_t len); @@ -53,10 +53,9 @@ class WavEngine: public AudioOut private: WavFile *file; - sem_t work; + sem_t work; SafeQueue buffer; pthread_t *pThread; }; #endif - diff --git a/src/Output/DSSIaudiooutput.cpp b/src/Output/DSSIaudiooutput.cpp index 9a0503b9..dac97b9c 100644 --- a/src/Output/DSSIaudiooutput.cpp +++ b/src/Output/DSSIaudiooutput.cpp @@ -43,7 +43,9 @@ using std::vector; // LADSPA is essentially a C handle based API; This plug-in implementation is // a C++ OO one so we need stub functions to map from C API calls to C++ object // method calls. -void DSSIaudiooutput::stub_connectPort(LADSPA_Handle instance, unsigned long port, LADSPA_Data * data) +void DSSIaudiooutput::stub_connectPort(LADSPA_Handle instance, + unsigned long port, + LADSPA_Data *data) { getInstance(instance)->connectPort(port, data); } @@ -53,7 +55,8 @@ void DSSIaudiooutput::stub_activate(LADSPA_Handle instance) getInstance(instance)->activate(); } -void DSSIaudiooutput::stub_run(LADSPA_Handle instance, unsigned long sample_count) +void DSSIaudiooutput::stub_run(LADSPA_Handle instance, + unsigned long sample_count) { getInstance(instance)->run(sample_count); } @@ -66,7 +69,7 @@ void DSSIaudiooutput::stub_deactivate(LADSPA_Handle instance) void DSSIaudiooutput::stub_cleanup(LADSPA_Handle instance) { - DSSIaudiooutput* plugin_instance = getInstance(instance); + DSSIaudiooutput *plugin_instance = getInstance(instance); plugin_instance->cleanup(); delete plugin_instance; } @@ -83,23 +86,30 @@ const LADSPA_Descriptor *ladspa_descriptor(unsigned long index) // DSSI is essentially a C handle based API; This plug-in implementation is // a C++ OO one so we need stub functions to map from C API calls to C++ object // method calls. -const DSSI_Program_Descriptor* DSSIaudiooutput::stub_getProgram (LADSPA_Handle instance, unsigned long index) +const DSSI_Program_Descriptor *DSSIaudiooutput::stub_getProgram( + LADSPA_Handle instance, + unsigned long index) { return getInstance(instance)->getProgram(index); } -void DSSIaudiooutput::stub_selectProgram(LADSPA_Handle instance, unsigned long bank, unsigned long program) +void DSSIaudiooutput::stub_selectProgram(LADSPA_Handle instance, + unsigned long bank, + unsigned long program) { getInstance(instance)->selectProgram(bank, program); } -int DSSIaudiooutput::stub_getMidiControllerForPort(LADSPA_Handle instance, unsigned long port) +int DSSIaudiooutput::stub_getMidiControllerForPort(LADSPA_Handle instance, + unsigned long port) { return getInstance(instance)->getMidiControllerForPort(port); } -void DSSIaudiooutput::stub_runSynth(LADSPA_Handle instance, unsigned long sample_count, - snd_seq_event_t *events, unsigned long event_count) +void DSSIaudiooutput::stub_runSynth(LADSPA_Handle instance, + unsigned long sample_count, + snd_seq_event_t *events, + unsigned long event_count) { getInstance(instance)->runSynth(sample_count, events, event_count); } @@ -129,16 +139,13 @@ const DSSI_Descriptor *dssi_descriptor(unsigned long index) * @param s_rate [in] the sample rate * @return the plug-in instance handle if successful else NULL */ -LADSPA_Handle DSSIaudiooutput::instantiate(const LADSPA_Descriptor * descriptor, unsigned long s_rate) +LADSPA_Handle DSSIaudiooutput::instantiate(const LADSPA_Descriptor *descriptor, + unsigned long s_rate) { if(descriptor->UniqueID == dssiDescriptor->LADSPA_Plugin->UniqueID) - { return (LADSPA_Handle)(new DSSIaudiooutput(s_rate)); - } else - { return NULL; - } } /** @@ -159,15 +166,15 @@ LADSPA_Handle DSSIaudiooutput::instantiate(const LADSPA_Descriptor * descriptor, * @param port [in] the port to be connected * @param data [in] the data buffer to write to / read from */ -void DSSIaudiooutput::connectPort(unsigned long port, LADSPA_Data * data) +void DSSIaudiooutput::connectPort(unsigned long port, LADSPA_Data *data) { - switch (port) { - case 0: - outl = data; - break; - case 1: - outr = data; - break; + switch(port) { + case 0: + outl = data; + break; + case 1: + outr = data; + break; } } @@ -188,8 +195,7 @@ void DSSIaudiooutput::connectPort(unsigned long port, LADSPA_Data * data) * too much code here seems to cause time-out problems in jack-dssi-host. */ void DSSIaudiooutput::activate() -{ -} +{} /** * Runs an instance of a plug-in for a block. @@ -208,7 +214,7 @@ void DSSIaudiooutput::activate() */ void DSSIaudiooutput::run(unsigned long sample_count) { - runSynth(sample_count,NULL,(unsigned long)0); + runSynth(sample_count, NULL, (unsigned long)0); } /** @@ -223,9 +229,7 @@ void DSSIaudiooutput::run(unsigned long sample_count) * Currently this function does nothing. */ void DSSIaudiooutput::deactivate() -{ - -} +{} /** * Deletes a plug-in instance that is no longer required. @@ -242,8 +246,7 @@ void DSSIaudiooutput::deactivate() * Currently cleanup is deferred to the destructor that is invoked after cleanup() */ void DSSIaudiooutput::cleanup() -{ -} +{} /** * Initial entry point for the LADSPA plug-in library. @@ -263,9 +266,10 @@ void DSSIaudiooutput::cleanup() * @param index [in] the index number of the plug-in within the library. * @return if index is in range, a pointer to the plug-in descriptor is returned, else NULL */ -const LADSPA_Descriptor* DSSIaudiooutput::getLadspaDescriptor(unsigned long index) +const LADSPA_Descriptor *DSSIaudiooutput::getLadspaDescriptor( + unsigned long index) { - if(index > 0 || dssiDescriptor == NULL) + if((index > 0) || (dssiDescriptor == NULL)) return NULL; else return dssiDescriptor->LADSPA_Plugin; @@ -302,7 +306,7 @@ const LADSPA_Descriptor* DSSIaudiooutput::getLadspaDescriptor(unsigned long inde * guaranteed to be valid only until the next call to get_program, * deactivate, or configure, on the same plug-in instance, or NULL if index is out of range. */ -const DSSI_Program_Descriptor* DSSIaudiooutput::getProgram (unsigned long index) +const DSSI_Program_Descriptor *DSSIaudiooutput::getProgram(unsigned long index) { static DSSI_Program_Descriptor retVal; @@ -310,20 +314,17 @@ const DSSI_Program_Descriptor* DSSIaudiooutput::getProgram (unsigned long index) initBanks(); /* Make sure that the bank containing the instrument has been mapped */ - while (index >= programMap.size() && mapNextBank()) + while(index >= programMap.size() && mapNextBank()) /* DO NOTHING MORE */; if(index >= programMap.size()) - { /* No more instruments */ return NULL; - } - else - { + else { /* OK, return the instrument */ - retVal.Name = programMap[index].name.c_str(); + retVal.Name = programMap[index].name.c_str(); retVal.Program = programMap[index].program; - retVal.Bank = programMap[index].bank; + retVal.Bank = programMap[index].bank; return &retVal; } } @@ -349,11 +350,9 @@ void DSSIaudiooutput::selectProgram(unsigned long bank, unsigned long program) { initBanks(); // cerr << "selectProgram(" << (bank & 0x7F) << ':' << ((bank >> 7) & 0x7F) << "," << program << ")" << '\n'; - if(bank < master->bank.banks.size() && program < BANK_SIZE) - { - const std::string bankdir = master->bank.banks[ bank ].dir; - if(!bankdir.empty()) - { + if((bank < master->bank.banks.size()) && (program < BANK_SIZE)) { + const std::string bankdir = master->bank.banks[bank].dir; + if(!bankdir.empty()) { pthread_mutex_lock(&master->mutex); /* We have to turn off the CheckPADsynth functionality, else @@ -422,55 +421,58 @@ int DSSIaudiooutput::getMidiControllerForPort(unsigned long port) * events. * @param event_count [in] the number of entries in the `events` block */ -void DSSIaudiooutput::runSynth(unsigned long sample_count, snd_seq_event_t *events, unsigned long event_count) +void DSSIaudiooutput::runSynth(unsigned long sample_count, + snd_seq_event_t *events, + unsigned long event_count) { - unsigned long from_frame = 0; - unsigned long event_index = 0; + unsigned long from_frame = 0; + unsigned long event_index = 0; unsigned long next_event_frame = 0; unsigned long to_frame = 0; pthread_mutex_lock(&master->mutex); do { /* Find the time of the next event, if any */ - if(events == NULL || event_index >= event_count) + if((events == NULL) || (event_index >= event_count)) next_event_frame = ULONG_MAX; else next_event_frame = events[event_index].time.tick; /* find the end of the sub-sample to be processed this time round... */ /* if the next event falls within the desired sample interval... */ - if(next_event_frame < sample_count && next_event_frame >= to_frame) + if((next_event_frame < sample_count) && (next_event_frame >= to_frame)) /* set the end to be at that event */ to_frame = next_event_frame; else /* ...else go for the whole remaining sample */ to_frame = sample_count; - if(from_frameGetAudioOutSamples(to_frame - from_frame, (int)sampleRate, &(outl[from_frame]), &(outr[from_frame])); + master->GetAudioOutSamples(to_frame - from_frame, + (int)sampleRate, + &(outl[from_frame]), + &(outr[from_frame])); // next sub-sample please... from_frame = to_frame; } // Now process any event(s) at the current timing point - while(events != NULL && event_index < event_count && events[event_index].time.tick == to_frame) - { + while(events != NULL && event_index < event_count + && events[event_index].time.tick == to_frame) { if(events[event_index].type == SND_SEQ_EVENT_NOTEON) - { - master->noteOn(events[event_index].data.note.channel, events[event_index].data.note.note, events[event_index].data.note.velocity); - } - else if(events[event_index].type == SND_SEQ_EVENT_NOTEOFF) - { - master->noteOff(events[event_index].data.note.channel, events[event_index].data.note.note); - } - else if(events[event_index].type == SND_SEQ_EVENT_CONTROLLER) - { - master->setController(events[event_index].data.control.channel, events[event_index].data.control.param, events[event_index].data.control.value); - } + master->noteOn(events[event_index].data.note.channel, + events[event_index].data.note.note, + events[event_index].data.note.velocity); + else + if(events[event_index].type == SND_SEQ_EVENT_NOTEOFF) + master->noteOff(events[event_index].data.note.channel, + events[event_index].data.note.note); else - { - } + if(events[event_index].type == SND_SEQ_EVENT_CONTROLLER) + master->setController(events[event_index].data.control.channel, + events[event_index].data.control.param, + events[event_index].data.control.value); + else {} event_index++; } @@ -497,9 +499,9 @@ void DSSIaudiooutput::runSynth(unsigned long sample_count, snd_seq_event_t *even * @param index [in] the index number of the plug-in within the library. * @return if index is in range, a pointer to the plug-in descriptor is returned, else NULL */ -const DSSI_Descriptor* DSSIaudiooutput::getDssiDescriptor(unsigned long index) +const DSSI_Descriptor *DSSIaudiooutput::getDssiDescriptor(unsigned long index) { - if(index > 0 || dssiDescriptor == NULL) + if((index > 0) || (dssiDescriptor == NULL)) return NULL; else return dssiDescriptor; @@ -510,64 +512,67 @@ const DSSI_Descriptor* DSSIaudiooutput::getDssiDescriptor(unsigned long index) // // Initialise the DSSI descriptor, statically: -DSSI_Descriptor* DSSIaudiooutput::dssiDescriptor = DSSIaudiooutput::initDssiDescriptor(); +DSSI_Descriptor *DSSIaudiooutput:: dssiDescriptor = + DSSIaudiooutput::initDssiDescriptor(); /** * Initializes the DSSI (and LADSPA) descriptor, returning it is an object. */ -DSSI_Descriptor* DSSIaudiooutput::initDssiDescriptor() +DSSI_Descriptor *DSSIaudiooutput::initDssiDescriptor() { - DSSI_Descriptor* newDssiDescriptor = new DSSI_Descriptor; - - LADSPA_PortDescriptor* newPortDescriptors; - const char** newPortNames; - LADSPA_PortRangeHint* newPortRangeHints; - - if (newDssiDescriptor) - { - LADSPA_Descriptor* newLadspaDescriptor = new LADSPA_Descriptor; - if (newLadspaDescriptor) - { - newLadspaDescriptor->UniqueID = 100; - newLadspaDescriptor->Label = "ZASF"; + DSSI_Descriptor *newDssiDescriptor = new DSSI_Descriptor; + + LADSPA_PortDescriptor *newPortDescriptors; + const char **newPortNames; + LADSPA_PortRangeHint *newPortRangeHints; + + if(newDssiDescriptor) { + LADSPA_Descriptor *newLadspaDescriptor = new LADSPA_Descriptor; + if(newLadspaDescriptor) { + newLadspaDescriptor->UniqueID = 100; + newLadspaDescriptor->Label = "ZASF"; newLadspaDescriptor->Properties = 0; - newLadspaDescriptor->Name = "ZynAddSubFX"; - newLadspaDescriptor->Maker = "Nasca Octavian Paul "; + newLadspaDescriptor->Name = "ZynAddSubFX"; + newLadspaDescriptor->Maker = + "Nasca Octavian Paul "; newLadspaDescriptor->Copyright = "GNU General Public License v.2"; newLadspaDescriptor->PortCount = 2; - newPortNames = new const char *[newLadspaDescriptor->PortCount]; + newPortNames = new const char *[newLadspaDescriptor->PortCount]; newPortNames[0] = "Output L"; newPortNames[1] = "Output R"; newLadspaDescriptor->PortNames = newPortNames; - newPortDescriptors = new LADSPA_PortDescriptor[newLadspaDescriptor->PortCount]; + newPortDescriptors = + new LADSPA_PortDescriptor[newLadspaDescriptor->PortCount]; newPortDescriptors[0] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO; newPortDescriptors[1] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO; newLadspaDescriptor->PortDescriptors = newPortDescriptors; - newPortRangeHints = new LADSPA_PortRangeHint[newLadspaDescriptor->PortCount]; + newPortRangeHints = + new LADSPA_PortRangeHint[newLadspaDescriptor->PortCount]; newPortRangeHints[0].HintDescriptor = 0; newPortRangeHints[1].HintDescriptor = 0; newLadspaDescriptor->PortRangeHints = newPortRangeHints; - newLadspaDescriptor->activate = stub_activate; - newLadspaDescriptor->cleanup = stub_cleanup; + newLadspaDescriptor->activate = stub_activate; + newLadspaDescriptor->cleanup = stub_cleanup; newLadspaDescriptor->connect_port = stub_connectPort; - newLadspaDescriptor->deactivate = stub_deactivate; - newLadspaDescriptor->instantiate = instantiate; + newLadspaDescriptor->deactivate = stub_deactivate; + newLadspaDescriptor->instantiate = instantiate; newLadspaDescriptor->run = stub_run; newLadspaDescriptor->run_adding = NULL; newLadspaDescriptor->set_run_adding_gain = NULL; } - newDssiDescriptor->LADSPA_Plugin = newLadspaDescriptor; + newDssiDescriptor->LADSPA_Plugin = newLadspaDescriptor; newDssiDescriptor->DSSI_API_Version = 1; - newDssiDescriptor->configure = NULL; + newDssiDescriptor->configure = NULL; newDssiDescriptor->get_program = stub_getProgram; - newDssiDescriptor->get_midi_controller_for_port = stub_getMidiControllerForPort; - newDssiDescriptor->select_program = stub_selectProgram; - newDssiDescriptor->run_synth = stub_runSynth; - newDssiDescriptor->run_synth_adding = NULL; + newDssiDescriptor->get_midi_controller_for_port = + stub_getMidiControllerForPort; + newDssiDescriptor->select_program = stub_selectProgram; + newDssiDescriptor->run_synth = stub_runSynth; + newDssiDescriptor->run_synth_adding = NULL; newDssiDescriptor->run_multiple_synths = NULL; newDssiDescriptor->run_multiple_synths_adding = NULL; } @@ -583,9 +588,9 @@ DSSI_Descriptor* DSSIaudiooutput::initDssiDescriptor() * @param instance [in] * @return the instance */ -DSSIaudiooutput* DSSIaudiooutput::getInstance(LADSPA_Handle instance) +DSSIaudiooutput *DSSIaudiooutput::getInstance(LADSPA_Handle instance) { - return (DSSIaudiooutput*)(instance); + return (DSSIaudiooutput *)(instance); } /** @@ -597,16 +602,17 @@ DSSIaudiooutput* DSSIaudiooutput::getInstance(LADSPA_Handle instance) */ DSSIaudiooutput::DSSIaudiooutput(unsigned long sampleRate) { - SAMPLE_RATE = sampleRate; + SAMPLE_RATE = sampleRate; - this->sampleRate = sampleRate; + this->sampleRate = sampleRate; this->banksInited = false; config.init(); sprng(time(NULL)); - denormalkillbuf=new float [SOUND_BUFFER_SIZE]; - for (int i=0;imaster = new Master(); } @@ -616,16 +622,14 @@ DSSIaudiooutput::DSSIaudiooutput(unsigned long sampleRate) * @return */ DSSIaudiooutput::~DSSIaudiooutput() -{ -} +{} /** * Ensures the list of bank (directories) has been initialised. */ void DSSIaudiooutput::initBanks(void) { - if(!banksInited) - { + if(!banksInited) { pthread_mutex_lock(&master->mutex); master->bank.rescanforbanks(); banksInited = true; @@ -641,20 +645,22 @@ void DSSIaudiooutput::initBanks(void) * @param _name [in] instrument / sample name * @return */ -DSSIaudiooutput::ProgramDescriptor::ProgramDescriptor(unsigned long _bank, unsigned long _program, char* _name) : - bank(_bank), program(_program), name(_name) -{ -} +DSSIaudiooutput::ProgramDescriptor::ProgramDescriptor(unsigned long _bank, + unsigned long _program, + char *_name) + :bank(_bank), program(_program), name(_name) +{} /** * The map of programs available; held as a single shared statically allocated object. */ -vector DSSIaudiooutput::programMap = vector(); +vector DSSIaudiooutput:: programMap = + vector(); /** * Index controlling the map of banks */ -long DSSIaudiooutput::bankNoToMap = 1; +long DSSIaudiooutput:: bankNoToMap = 1; /** * Queries and maps the next available bank of instruments. @@ -666,25 +672,22 @@ long DSSIaudiooutput::bankNoToMap = 1; bool DSSIaudiooutput::mapNextBank() { pthread_mutex_lock(&master->mutex); - Bank& bank = master->bank; - bool retval; - if(bankNoToMap >= (int)bank.banks.size() || bank.banks[bankNoToMap].dir.empty()) - { + Bank &bank = master->bank; + bool retval; + if((bankNoToMap >= (int)bank.banks.size()) + || bank.banks[bankNoToMap].dir.empty()) retval = false; - } - else - { + else { bank.loadbank(bank.banks[bankNoToMap].dir); - for(unsigned long instrument = 0; instrument < BANK_SIZE; ++instrument) - { + for(unsigned long instrument = 0; instrument < BANK_SIZE; + ++instrument) { string insName = bank.getname(instrument); - if(!insName.empty() && insName[0] != '\0' && insName[0] != ' ') - { - programMap.push_back(ProgramDescriptor(bankNoToMap,instrument, - const_cast(insName.c_str()))); - } + if(!insName.empty() && (insName[0] != '\0') && (insName[0] != ' ')) + programMap.push_back(ProgramDescriptor(bankNoToMap, instrument, + const_cast( + insName.c_str()))); } - bankNoToMap ++; + bankNoToMap++; retval = true; } pthread_mutex_unlock(&master->mutex); diff --git a/src/Output/DSSIaudiooutput.h b/src/Output/DSSIaudiooutput.h index be6b19b6..f7eaaf35 100644 --- a/src/Output/DSSIaudiooutput.h +++ b/src/Output/DSSIaudiooutput.h @@ -33,79 +33,91 @@ class DSSIaudiooutput { -public: - // - // Static stubs for LADSPA member functions - // - static void stub_connectPort(LADSPA_Handle instance, unsigned long port, LADSPA_Data * data); - static void stub_activate(LADSPA_Handle instance); - static void stub_run(LADSPA_Handle instance, unsigned long sample_count); - static void stub_deactivate(LADSPA_Handle Instance); - static void stub_cleanup(LADSPA_Handle instance); - - // - // Static stubs for DSSI member functions - // - static const DSSI_Program_Descriptor* stub_getProgram (LADSPA_Handle instance, unsigned long Index); - static void stub_selectProgram(LADSPA_Handle instance, unsigned long bank, unsigned long program); - static int stub_getMidiControllerForPort(LADSPA_Handle instance, unsigned long port); - static void stub_runSynth(LADSPA_Handle instance, unsigned long sample_count, - snd_seq_event_t *events, unsigned long event_count); - - /* - * LADSPA member functions - */ - static LADSPA_Handle instantiate(const LADSPA_Descriptor * descriptor, unsigned long s_rate); - void connectPort(unsigned long port, LADSPA_Data * data); - void activate(); - void run(unsigned long sample_count); - void deactivate(); - void cleanup(); - static const LADSPA_Descriptor* getLadspaDescriptor(unsigned long index); - - /* - * DSSI member functions - */ - const DSSI_Program_Descriptor* getProgram (unsigned long Index); - void selectProgram(unsigned long bank, unsigned long program); - int getMidiControllerForPort(unsigned long port); - void runSynth(unsigned long sample_count, snd_seq_event_t *events, unsigned long event_count); - static const DSSI_Descriptor* getDssiDescriptor(unsigned long index); - - struct ProgramDescriptor - { - unsigned long bank; - unsigned long program; - std::string name; - ProgramDescriptor(unsigned long _bank, unsigned long _program, char* _name); - }; - -private: - - DSSIaudiooutput(unsigned long sampleRate); - ~DSSIaudiooutput(); - static DSSI_Descriptor* initDssiDescriptor(); - static DSSIaudiooutput* getInstance(LADSPA_Handle instance); - void initBanks(); - bool mapNextBank(); - - LADSPA_Data *outl; - LADSPA_Data *outr; - long sampleRate; - Master* master; - static DSSI_Descriptor* dssiDescriptor; - static std::string bankDirNames[]; - static - std::vector programMap; - - /** - * Flag controlling the list of bank directories - */ - bool banksInited; - - static - long bankNoToMap; + public: + // + // Static stubs for LADSPA member functions + // + static void stub_connectPort(LADSPA_Handle instance, + unsigned long port, + LADSPA_Data *data); + static void stub_activate(LADSPA_Handle instance); + static void stub_run(LADSPA_Handle instance, unsigned long sample_count); + static void stub_deactivate(LADSPA_Handle Instance); + static void stub_cleanup(LADSPA_Handle instance); + + // + // Static stubs for DSSI member functions + // + static const DSSI_Program_Descriptor *stub_getProgram( + LADSPA_Handle instance, + unsigned long Index); + static void stub_selectProgram(LADSPA_Handle instance, + unsigned long bank, + unsigned long program); + static int stub_getMidiControllerForPort(LADSPA_Handle instance, + unsigned long port); + static void stub_runSynth(LADSPA_Handle instance, + unsigned long sample_count, + snd_seq_event_t *events, + unsigned long event_count); + + /* + * LADSPA member functions + */ + static LADSPA_Handle instantiate(const LADSPA_Descriptor *descriptor, + unsigned long s_rate); + void connectPort(unsigned long port, LADSPA_Data *data); + void activate(); + void run(unsigned long sample_count); + void deactivate(); + void cleanup(); + static const LADSPA_Descriptor *getLadspaDescriptor(unsigned long index); + + /* + * DSSI member functions + */ + const DSSI_Program_Descriptor *getProgram(unsigned long Index); + void selectProgram(unsigned long bank, unsigned long program); + int getMidiControllerForPort(unsigned long port); + void runSynth(unsigned long sample_count, + snd_seq_event_t *events, + unsigned long event_count); + static const DSSI_Descriptor *getDssiDescriptor(unsigned long index); + + struct ProgramDescriptor { + unsigned long bank; + unsigned long program; + std::string name; + ProgramDescriptor(unsigned long _bank, + unsigned long _program, + char *_name); + }; + + private: + + DSSIaudiooutput(unsigned long sampleRate); + ~DSSIaudiooutput(); + static DSSI_Descriptor *initDssiDescriptor(); + static DSSIaudiooutput *getInstance(LADSPA_Handle instance); + void initBanks(); + bool mapNextBank(); + + LADSPA_Data *outl; + LADSPA_Data *outr; + long sampleRate; + Master *master; + static DSSI_Descriptor *dssiDescriptor; + static std::string bankDirNames[]; + static + std::vector programMap; + + /** + * Flag controlling the list of bank directories + */ + bool banksInited; + + static + long bankNoToMap; }; #endif - diff --git a/src/Params/ADnoteParameters.cpp b/src/Params/ADnoteParameters.cpp index cb79dedb..adb937f6 100644 --- a/src/Params/ADnoteParameters.cpp +++ b/src/Params/ADnoteParameters.cpp @@ -53,17 +53,17 @@ ADnoteGlobalParam::ADnoteGlobalParam() { FreqEnvelope = new EnvelopeParams(0, 0); FreqEnvelope->ASRinit(64, 50, 64, 60); - FreqLfo = new LFOParams(70, 0, 64, 0, 0, 0, 0, 0); + FreqLfo = new LFOParams(70, 0, 64, 0, 0, 0, 0, 0); - AmpEnvelope = new EnvelopeParams(64, 1); + AmpEnvelope = new EnvelopeParams(64, 1); AmpEnvelope->ADSRinit_dB(0, 40, 127, 25); AmpLfo = new LFOParams(80, 0, 64, 0, 0, 0, 0, 1); GlobalFilter = new FilterParams(2, 94, 40); FilterEnvelope = new EnvelopeParams(0, 1); FilterEnvelope->ADSRinit_filter(64, 40, 64, 70, 60, 64); - FilterLfo = new LFOParams(80, 0, 64, 0, 0, 0, 0, 2); - Reson = new Resonance(); + FilterLfo = new LFOParams(80, 0, 64, 0, 0, 0, 0, 2); + Reson = new Resonance(); } void ADnoteParameters::defaults() @@ -98,7 +98,7 @@ void ADnoteGlobalParam::defaults() PPunchTime = 60; PPunchStretch = 64; PPunchVelocitySensing = 72; - Hrandgrouping = 0; + Hrandgrouping = 0; /* Filter Global Parameters*/ PFilterVelocityScale = 64; @@ -119,14 +119,14 @@ void ADnoteParameters::defaults(int n) void ADnoteVoiceParam::defaults() { - Enabled = 0; + Enabled = 0; Unison_size = 1; Unison_frequency_spread = 60; Unison_stereo_spread = 64; Unison_vibratto = 64; - Unison_vibratto_speed = 64; - Unison_invert_phase = 0; + Unison_vibratto_speed = 64; + Unison_invert_phase = 0; Type = 0; Pfixedfreq = 0; @@ -137,14 +137,14 @@ void ADnoteVoiceParam::defaults() PextFMoscil = -1; Poscilphase = 64; PFMoscilphase = 64; - PDelay = 0; - PVolume = 100; - PVolumeminus = 0; - PPanning = 64; //center - PDetune = 8192; //8192=0 - PCoarseDetune = 0; - PDetuneType = 0; - PFreqLfoEnabled = 0; + PDelay = 0; + PVolume = 100; + PVolumeminus = 0; + PPanning = 64; //center + PDetune = 8192; //8192=0 + PCoarseDetune = 0; + PDetuneType = 0; + PFreqLfoEnabled = 0; PFreqEnvelopeEnabled = 0; PAmpEnvelopeEnabled = 0; PAmpLfoEnabled = 0; @@ -155,9 +155,9 @@ void ADnoteVoiceParam::defaults() PFMEnabled = 0; //I use the internal oscillator (-1) - PFMVoice = -1; + PFMVoice = -1; - PFMVolume = 90; + PFMVolume = 90; PFMVolumeDamp = 64; PFMDetune = 8192; PFMCoarseDetune = 0; @@ -198,22 +198,22 @@ void ADnoteVoiceParam::enable(FFTwrapper *fft, Resonance *Reson) OscilSmp = new OscilGen(fft, Reson); FMSmp = new OscilGen(fft, NULL); - AmpEnvelope = new EnvelopeParams(64, 1); + AmpEnvelope = new EnvelopeParams(64, 1); AmpEnvelope->ADSRinit_dB(0, 100, 127, 100); - AmpLfo = new LFOParams(90, 32, 64, 0, 0, 30, 0, 1); + AmpLfo = new LFOParams(90, 32, 64, 0, 0, 30, 0, 1); - FreqEnvelope = new EnvelopeParams(0, 0); + FreqEnvelope = new EnvelopeParams(0, 0); FreqEnvelope->ASRinit(30, 40, 64, 60); - FreqLfo = new LFOParams(50, 40, 0, 0, 0, 0, 0, 0); + FreqLfo = new LFOParams(50, 40, 0, 0, 0, 0, 0, 0); VoiceFilter = new FilterParams(2, 50, 60); FilterEnvelope = new EnvelopeParams(0, 0); FilterEnvelope->ADSRinit_filter(90, 70, 40, 70, 10, 40); - FilterLfo = new LFOParams(50, 20, 64, 0, 0, 0, 0, 2); + FilterLfo = new LFOParams(50, 20, 64, 0, 0, 0, 0, 2); FMFreqEnvelope = new EnvelopeParams(0, 0); FMFreqEnvelope->ASRinit(20, 90, 40, 80); - FMAmpEnvelope = new EnvelopeParams(64, 1); + FMAmpEnvelope = new EnvelopeParams(64, 1); FMAmpEnvelope->ADSRinit(80, 90, 127, 100); } @@ -285,7 +285,7 @@ ADnoteParameters::~ADnoteParameters() } int ADnoteParameters::get_unison_size_index(int nvoice) { - int index = 0; + int index = 0; if(nvoice >= NUM_VOICES) return 0; int unison = VoicePar[nvoice].Unison_size; @@ -337,7 +337,7 @@ void ADnoteParameters::add2XMLsection(XMLwrapper *xml, int n) && (fmoscilused == 0)) && (xml->minimal)) return; - VoicePar[nvoice].add2XML(xml,fmoscilused); + VoicePar[nvoice].add2XML(xml, fmoscilused); } void ADnoteVoiceParam::add2XML(XMLwrapper *xml, bool fmoscilused) @@ -560,15 +560,15 @@ void ADnoteGlobalParam::getfromXML(XMLwrapper *xml) PVolume = xml->getpar127("volume", PVolume); PPanning = xml->getpar127("panning", PPanning); PAmpVelocityScaleFunction = xml->getpar127("velocity_sensing", - PAmpVelocityScaleFunction); + PAmpVelocityScaleFunction); PPunchStrength = xml->getpar127("punch_strength", PPunchStrength); PPunchTime = xml->getpar127("punch_time", PPunchTime); PPunchStretch = xml->getpar127("punch_stretch", PPunchStretch); PPunchVelocitySensing = xml->getpar127("punch_velocity_sensing", - PPunchVelocitySensing); - Hrandgrouping = xml->getpar127("harmonic_randomness_grouping", - Hrandgrouping); + PPunchVelocitySensing); + Hrandgrouping = xml->getpar127("harmonic_randomness_grouping", + Hrandgrouping); if(xml->enterbranch("AMPLITUDE_ENVELOPE")) { AmpEnvelope->getfromXML(xml); @@ -603,8 +603,9 @@ void ADnoteGlobalParam::getfromXML(XMLwrapper *xml) if(xml->enterbranch("FILTER_PARAMETERS")) { PFilterVelocityScale = xml->getpar127("velocity_sensing_amplitude", - PFilterVelocityScale); - PFilterVelocityScaleFunction = xml->getpar127("velocity_sensing", + PFilterVelocityScale); + PFilterVelocityScaleFunction = xml->getpar127( + "velocity_sensing", PFilterVelocityScaleFunction); xml->enterbranch("FILTER"); @@ -654,20 +655,22 @@ void ADnoteVoiceParam::getfromXML(XMLwrapper *xml, unsigned nvoice) { Enabled = xml->getparbool("enabled", 0); Unison_size = xml->getpar127("unison_size", Unison_size); - Unison_frequency_spread = xml->getpar127( "unison_frequency_spread", - Unison_frequency_spread); - Unison_stereo_spread = xml->getpar127( "unison_stereo_spread", - Unison_stereo_spread); - Unison_vibratto = xml->getpar127( "unison_vibratto", Unison_vibratto); - Unison_vibratto_speed = xml->getpar127( "unison_vibratto_speed", Unison_vibratto_speed); - Unison_invert_phase = xml->getpar127( "unison_invert_phase", Unison_invert_phase); - - Type = xml->getpar127("type", Type); - PDelay = xml->getpar127("delay", PDelay); + Unison_frequency_spread = xml->getpar127("unison_frequency_spread", + Unison_frequency_spread); + Unison_stereo_spread = xml->getpar127("unison_stereo_spread", + Unison_stereo_spread); + Unison_vibratto = xml->getpar127("unison_vibratto", Unison_vibratto); + Unison_vibratto_speed = xml->getpar127("unison_vibratto_speed", + Unison_vibratto_speed); + Unison_invert_phase = xml->getpar127("unison_invert_phase", + Unison_invert_phase); + + Type = xml->getpar127("type", Type); + PDelay = xml->getpar127("delay", PDelay); Presonance = xml->getparbool("resonance", Presonance); - Pextoscil = xml->getpar("ext_oscil", -1, -1, nvoice - 1); - PextFMoscil = xml->getpar("ext_fm_oscil", -1, -1, nvoice - 1); + Pextoscil = xml->getpar("ext_oscil", -1, -1, nvoice - 1); + PextFMoscil = xml->getpar("ext_fm_oscil", -1, -1, nvoice - 1); Poscilphase = xml->getpar127("oscil_phase", Poscilphase); PFMoscilphase = xml->getpar127("oscil_fm_phase", PFMoscilphase); @@ -685,9 +688,11 @@ void ADnoteVoiceParam::getfromXML(XMLwrapper *xml, unsigned nvoice) PPanning = xml->getpar127("panning", PPanning); PVolume = xml->getpar127("volume", PVolume); PVolumeminus = xml->getparbool("volume_minus", PVolumeminus); - PAmpVelocityScaleFunction = xml->getpar127("velocity_sensing", PAmpVelocityScaleFunction); + PAmpVelocityScaleFunction = xml->getpar127("velocity_sensing", + PAmpVelocityScaleFunction); - PAmpEnvelopeEnabled = xml->getparbool("amp_envelope_enabled", PAmpEnvelopeEnabled); + PAmpEnvelopeEnabled = xml->getparbool("amp_envelope_enabled", + PAmpEnvelopeEnabled); if(xml->enterbranch("AMPLITUDE_ENVELOPE")) { AmpEnvelope->getfromXML(xml); xml->exitbranch(); @@ -702,13 +707,13 @@ void ADnoteVoiceParam::getfromXML(XMLwrapper *xml, unsigned nvoice) } if(xml->enterbranch("FREQUENCY_PARAMETERS")) { - Pfixedfreq = xml->getparbool("fixed_freq", Pfixedfreq); - PfixedfreqET = xml->getpar127("fixed_freq_et", PfixedfreqET); - PDetune = xml->getpar("detune", PDetune, 0, 16383); + Pfixedfreq = xml->getparbool("fixed_freq", Pfixedfreq); + PfixedfreqET = xml->getpar127("fixed_freq_et", PfixedfreqET); + PDetune = xml->getpar("detune", PDetune, 0, 16383); PCoarseDetune = xml->getpar("coarse_detune", PCoarseDetune, 0, 16383); - PDetuneType = xml->getpar127( "detune_type", PDetuneType); - PFreqEnvelopeEnabled = xml->getparbool( "freq_envelope_enabled", - PFreqEnvelopeEnabled); + PDetuneType = xml->getpar127("detune_type", PDetuneType); + PFreqEnvelopeEnabled = xml->getparbool("freq_envelope_enabled", + PFreqEnvelopeEnabled); if(xml->enterbranch("FREQUENCY_ENVELOPE")) { FreqEnvelope->getfromXML(xml); @@ -730,13 +735,15 @@ void ADnoteVoiceParam::getfromXML(XMLwrapper *xml, unsigned nvoice) xml->exitbranch(); } - PFilterEnvelopeEnabled = xml->getparbool("filter_envelope_enabled", PFilterEnvelopeEnabled); + PFilterEnvelopeEnabled = xml->getparbool("filter_envelope_enabled", + PFilterEnvelopeEnabled); if(xml->enterbranch("FILTER_ENVELOPE")) { FilterEnvelope->getfromXML(xml); xml->exitbranch(); } - PFilterLfoEnabled = xml->getparbool("filter_lfo_enabled", PFilterLfoEnabled); + PFilterLfoEnabled = xml->getparbool("filter_lfo_enabled", + PFilterLfoEnabled); if(xml->enterbranch("FILTER_LFO")) { FilterLfo->getfromXML(xml); xml->exitbranch(); @@ -745,12 +752,14 @@ void ADnoteVoiceParam::getfromXML(XMLwrapper *xml, unsigned nvoice) } if(xml->enterbranch("FM_PARAMETERS")) { - PFMVoice = xml->getpar("input_voice", PFMVoice, -1, nvoice - 1); + PFMVoice = xml->getpar("input_voice", PFMVoice, -1, nvoice - 1); PFMVolume = xml->getpar127("volume", PFMVolume); PFMVolumeDamp = xml->getpar127("volume_damp", PFMVolumeDamp); - PFMVelocityScaleFunction = xml->getpar127("velocity_sensing", PFMVelocityScaleFunction); + PFMVelocityScaleFunction = xml->getpar127("velocity_sensing", + PFMVelocityScaleFunction); - PFMAmpEnvelopeEnabled = xml->getparbool("amp_envelope_enabled", PFMAmpEnvelopeEnabled); + PFMAmpEnvelopeEnabled = xml->getparbool("amp_envelope_enabled", + PFMAmpEnvelopeEnabled); if(xml->enterbranch("AMPLITUDE_ENVELOPE")) { FMAmpEnvelope->getfromXML(xml); xml->exitbranch(); @@ -758,11 +767,14 @@ void ADnoteVoiceParam::getfromXML(XMLwrapper *xml, unsigned nvoice) if(xml->enterbranch("MODULATOR")) { PFMDetune = xml->getpar("detune", PFMDetune, 0, 16383); - PFMCoarseDetune = xml->getpar("coarse_detune", PFMCoarseDetune, 0, 16383); - PFMDetuneType = xml->getpar127("detune_type", PFMDetuneType); + PFMCoarseDetune = xml->getpar("coarse_detune", + PFMCoarseDetune, + 0, + 16383); + PFMDetuneType = xml->getpar127("detune_type", PFMDetuneType); PFMFreqEnvelopeEnabled = xml->getparbool("freq_envelope_enabled", - PFMFreqEnvelopeEnabled); + PFMFreqEnvelopeEnabled); if(xml->enterbranch("FREQUENCY_ENVELOPE")) { FMFreqEnvelope->getfromXML(xml); xml->exitbranch(); @@ -778,4 +790,3 @@ void ADnoteVoiceParam::getfromXML(XMLwrapper *xml, unsigned nvoice) xml->exitbranch(); } } - diff --git a/src/Params/ADnoteParameters.h b/src/Params/ADnoteParameters.h index 05e3422a..291d5b42 100644 --- a/src/Params/ADnoteParameters.h +++ b/src/Params/ADnoteParameters.h @@ -64,9 +64,9 @@ struct ADnoteGlobalParam { unsigned short int PCoarseDetune; //coarse detune+octave unsigned char PDetuneType; //detune type - unsigned char PBandwidth; //how much the relative fine detunes of the voices are changed + unsigned char PBandwidth; //how much the relative fine detunes of the voices are changed - EnvelopeParams *FreqEnvelope; //Frequency Envelope + EnvelopeParams *FreqEnvelope; //Frequency Envelope LFOParams *FreqLfo; //Frequency LFO @@ -78,18 +78,18 @@ struct ADnoteGlobalParam { 1 - left 64 - center 127 - right */ - unsigned char PPanning; + unsigned char PPanning; - unsigned char PVolume; + unsigned char PVolume; - unsigned char PAmpVelocityScaleFunction; + unsigned char PAmpVelocityScaleFunction; EnvelopeParams *AmpEnvelope; - LFOParams *AmpLfo; + LFOParams *AmpLfo; - unsigned char PPunchStrength, PPunchTime, PPunchStretch, - PPunchVelocitySensing; + unsigned char PPunchStrength, PPunchTime, PPunchStretch, + PPunchVelocitySensing; /****************************************** * FILTER GLOBAL PARAMETERS * @@ -100,11 +100,11 @@ struct ADnoteGlobalParam { unsigned char PFilterVelocityScale; // filter velocity sensing - unsigned char PFilterVelocityScaleFunction; + unsigned char PFilterVelocityScaleFunction; EnvelopeParams *FilterEnvelope; - LFOParams *FilterLfo; + LFOParams *FilterLfo; // RESONANCE Resonance *Reson; @@ -120,7 +120,7 @@ struct ADnoteGlobalParam { /***********************************************************/ struct ADnoteVoiceParam { void getfromXML(XMLwrapper *xml, unsigned nvoice); - void add2XML(XMLwrapper *xml,bool fmoscilused); + void add2XML(XMLwrapper *xml, bool fmoscilused); void defaults(); void enable(FFTwrapper *fft, Resonance *Reson); void kill(); @@ -285,7 +285,7 @@ struct ADnoteVoiceParam { EnvelopeParams *FMAmpEnvelope; }; -class ADnoteParameters : public PresetsArray +class ADnoteParameters:public PresetsArray { public: ADnoteParameters(FFTwrapper *fft_); @@ -314,4 +314,3 @@ class ADnoteParameters : public PresetsArray }; #endif - diff --git a/src/Params/Controller.cpp b/src/Params/Controller.cpp index 06fc2f63..b79e42a0 100644 --- a/src/Params/Controller.cpp +++ b/src/Params/Controller.cpp @@ -51,17 +51,17 @@ void Controller::defaults() portamento.portamento = 0; portamento.used = 0; - portamento.proportional = 0; - portamento.propRate = 80; - portamento.propDepth = 90; - portamento.receive = 1; + portamento.proportional = 0; + portamento.propRate = 80; + portamento.propDepth = 90; + portamento.receive = 1; portamento.time = 64; portamento.updowntimestretch = 64; - portamento.pitchthresh = 3; - portamento.pitchthreshtype = 1; - portamento.noteusing = -1; - resonancecenter.depth = 64; - resonancebandwidth.depth = 64; + portamento.pitchthresh = 3; + portamento.pitchthreshtype = 1; + portamento.noteusing = -1; + resonancecenter.depth = 64; + resonancebandwidth.depth = 64; initportamento(440.0f, 440.0f, false); // Now has a third argument setportamento(0); @@ -152,7 +152,8 @@ void Controller::setmodwheel(int value) { modwheel.data = value; if(modwheel.exponential == 0) { - float tmp = powf(25.0f, powf(modwheel.depth / 127.0f, 1.5f) * 2.0f) / 25.0f; + float tmp = + powf(25.0f, powf(modwheel.depth / 127.0f, 1.5f) * 2.0f) / 25.0f; if((value < 64) && (modwheel.depth >= 64)) tmp = 1.0f; modwheel.relmod = (value / 64.0f - 1.0f) * tmp + 1.0f; @@ -222,23 +223,27 @@ int Controller::initportamento(float oldfreq, //Linear functors could also make this nicer if(oldfreq > newfreq) //2 is the center of propRate portamentotime *= - powf(oldfreq / newfreq / (portamento.propRate / 127.0f * 3 + .05), - (portamento.propDepth / 127.0f * 1.6f + .2)); + powf(oldfreq / newfreq + / (portamento.propRate / 127.0f * 3 + .05), + (portamento.propDepth / 127.0f * 1.6f + .2)); else //1 is the center of propDepth portamentotime *= - powf(newfreq / oldfreq / (portamento.propRate / 127.0f * 3 + .05), - (portamento.propDepth / 127.0f * 1.6f + .2)); + powf(newfreq / oldfreq + / (portamento.propRate / 127.0f * 3 + .05), + (portamento.propDepth / 127.0f * 1.6f + .2)); } if((portamento.updowntimestretch >= 64) && (newfreq < oldfreq)) { if(portamento.updowntimestretch == 127) return 0; - portamentotime *= powf(0.1f, (portamento.updowntimestretch - 64) / 63.0f); + portamentotime *= powf(0.1f, + (portamento.updowntimestretch - 64) / 63.0f); } if((portamento.updowntimestretch < 64) && (newfreq > oldfreq)) { if(portamento.updowntimestretch == 0) return 0; - portamentotime *= powf(0.1f, (64.0f - portamento.updowntimestretch) / 64.0f); + portamentotime *= powf(0.1f, + (64.0f - portamento.updowntimestretch) / 64.0f); } //printf("%f->%f : Time %f\n",oldfreq,newfreq,portamentotime); @@ -247,8 +252,8 @@ int Controller::initportamento(float oldfreq, portamento.origfreqrap = oldfreq / newfreq; float tmprap = ((portamento.origfreqrap > 1.0f) ? - (portamento.origfreqrap) : - (1.0f / portamento.origfreqrap)); + (portamento.origfreqrap) : + (1.0f / portamento.origfreqrap)); float thresholdrap = powf(2.0f, portamento.pitchthresh / 12.0f); if((portamento.pitchthreshtype == 0) && (tmprap - 0.00001f > thresholdrap)) @@ -310,24 +315,24 @@ int Controller::getnrpn(int *parhi, int *parlo, int *valhi, int *vallo) void Controller::setparameternumber(unsigned int type, int value) { switch(type) { - case C_nrpnhi: - NRPN.parhi = value; - NRPN.valhi = -1; - NRPN.vallo = -1; //clear the values - break; - case C_nrpnlo: - NRPN.parlo = value; - NRPN.valhi = -1; - NRPN.vallo = -1; //clear the values - break; - case C_dataentryhi: - if((NRPN.parhi >= 0) && (NRPN.parlo >= 0)) - NRPN.valhi = value; - break; - case C_dataentrylo: - if((NRPN.parhi >= 0) && (NRPN.parlo >= 0)) - NRPN.vallo = value; - break; + case C_nrpnhi: + NRPN.parhi = value; + NRPN.valhi = -1; + NRPN.vallo = -1; //clear the values + break; + case C_nrpnlo: + NRPN.parlo = value; + NRPN.valhi = -1; + NRPN.vallo = -1; //clear the values + break; + case C_dataentryhi: + if((NRPN.parhi >= 0) && (NRPN.parlo >= 0)) + NRPN.valhi = value; + break; + case C_dataentrylo: + if((NRPN.parhi >= 0) && (NRPN.parlo >= 0)) + NRPN.vallo = value; + break; } } @@ -369,14 +374,14 @@ void Controller::getfromXML(XMLwrapper *xml) -6400, 6400); - expression.receive = xml->getparbool("expression_receive", - expression.receive); - panning.depth = xml->getpar127("panning_depth", panning.depth); - filtercutoff.depth = xml->getpar127("filter_cutoff_depth", - filtercutoff.depth); - filterq.depth = xml->getpar127("filter_q_depth", filterq.depth); + expression.receive = xml->getparbool("expression_receive", + expression.receive); + panning.depth = xml->getpar127("panning_depth", panning.depth); + filtercutoff.depth = xml->getpar127("filter_cutoff_depth", + filtercutoff.depth); + filterq.depth = xml->getpar127("filter_q_depth", filterq.depth); bandwidth.depth = xml->getpar127("bandwidth_depth", bandwidth.depth); - modwheel.depth = xml->getpar127("mod_wheel_depth", modwheel.depth); + modwheel.depth = xml->getpar127("mod_wheel_depth", modwheel.depth); modwheel.exponential = xml->getparbool("mod_wheel_exponential", modwheel.exponential); fmamp.receive = xml->getparbool("fm_amp_receive", @@ -392,24 +397,23 @@ void Controller::getfromXML(XMLwrapper *xml) portamento.time); portamento.pitchthresh = xml->getpar127("portamento_pitchthresh", portamento.pitchthresh); - portamento.pitchthreshtype = xml->getpar127("portamento_pitchthreshtype", - portamento.pitchthreshtype); - portamento.portamento = xml->getpar127("portamento_portamento", - portamento.portamento); + portamento.pitchthreshtype = xml->getpar127("portamento_pitchthreshtype", + portamento.pitchthreshtype); + portamento.portamento = xml->getpar127("portamento_portamento", + portamento.portamento); portamento.updowntimestretch = xml->getpar127( "portamento_updowntimestretch", portamento.updowntimestretch); - portamento.proportional = xml->getpar127("portamento_proportional", - portamento.proportional); - portamento.propRate = xml->getpar127("portamento_proprate", - portamento.propRate); - portamento.propDepth = xml->getpar127("portamento_propdepth", - portamento.propDepth); + portamento.proportional = xml->getpar127("portamento_proportional", + portamento.proportional); + portamento.propRate = xml->getpar127("portamento_proprate", + portamento.propRate); + portamento.propDepth = xml->getpar127("portamento_propdepth", + portamento.propDepth); - resonancecenter.depth = xml->getpar127("resonance_center_depth", - resonancecenter.depth); + resonancecenter.depth = xml->getpar127("resonance_center_depth", + resonancecenter.depth); resonancebandwidth.depth = xml->getpar127("resonance_bandwidth_depth", resonancebandwidth.depth); } - diff --git a/src/Params/Controller.h b/src/Params/Controller.h index b811f821..22483eaa 100644 --- a/src/Params/Controller.h +++ b/src/Params/Controller.h @@ -74,59 +74,59 @@ class Controller // Controllers values struct { //Pitch Wheel - int data; + int data; short int bendrange; //bendrange is in cents - float relfreq; //the relative frequency (default is 1.0f) + float relfreq; //the relative frequency (default is 1.0f) } pitchwheel; struct { //Expression - int data; - float relvolume; + int data; + float relvolume; unsigned char receive; } expression; struct { //Panning - int data; - float pan; + int data; + float pan; unsigned char depth; } panning; struct { //Filter cutoff - int data; - float relfreq; + int data; + float relfreq; unsigned char depth; } filtercutoff; struct { //Filter Q - int data; - float relq; + int data; + float relq; unsigned char depth; } filterq; struct { //Bandwidth - int data; - float relbw; + int data; + float relbw; unsigned char depth; unsigned char exponential; } bandwidth; struct { //Modulation Wheel - int data; - float relmod; + int data; + float relmod; unsigned char depth; unsigned char exponential; } modwheel; struct { //FM amplitude - int data; - float relamp; + int data; + float relamp; unsigned char receive; } fmamp; struct { //Volume - int data; - float volume; + int data; + float volume; unsigned char receive; } volume; @@ -179,7 +179,7 @@ class Controller * This will be linear with respect to x.*/ float freqrap; /**this is used by the Part for knowing which note uses the portamento*/ - int noteusing; + int noteusing; /**if a the portamento is used by a note * \todo see if this can be a bool*/ int used; @@ -195,14 +195,14 @@ class Controller } portamento; struct { //Resonance Center Frequency - int data; - float relcenter; + int data; + float relcenter; unsigned char depth; } resonancecenter; struct { //Resonance Bandwidth - int data; - float relbw; + int data; + float relbw; unsigned char depth; } resonancebandwidth; @@ -218,4 +218,3 @@ class Controller }; #endif - diff --git a/src/Params/EnvelopeParams.cpp b/src/Params/EnvelopeParams.cpp index fe41b114..a06704d6 100644 --- a/src/Params/EnvelopeParams.cpp +++ b/src/Params/EnvelopeParams.cpp @@ -43,7 +43,7 @@ EnvelopeParams::EnvelopeParams(unsigned char Penvstretch_, Penvdt[i] = 32; Penvval[i] = 64; } - Penvdt[0] = 0; //no used + Penvdt[0] = 0; //no used Penvsustain = 1; Penvpoints = 1; Envmode = 1; @@ -149,57 +149,57 @@ void EnvelopeParams::ASRinit_bw(char A_val, char A_dt, char R_val, char R_dt) void EnvelopeParams::converttofree() { switch(Envmode) { - case 1: - Penvpoints = 4; - Penvsustain = 2; - Penvval[0] = 0; - Penvdt[1] = PA_dt; - Penvval[1] = 127; - Penvdt[2] = PD_dt; - Penvval[2] = PS_val; - Penvdt[3] = PR_dt; - Penvval[3] = 0; - break; - case 2: - Penvpoints = 4; - Penvsustain = 2; - Penvval[0] = 0; - Penvdt[1] = PA_dt; - Penvval[1] = 127; - Penvdt[2] = PD_dt; - Penvval[2] = PS_val; - Penvdt[3] = PR_dt; - Penvval[3] = 0; - break; - case 3: - Penvpoints = 3; - Penvsustain = 1; - Penvval[0] = PA_val; - Penvdt[1] = PA_dt; - Penvval[1] = 64; - Penvdt[2] = PR_dt; - Penvval[2] = PR_val; - break; - case 4: - Penvpoints = 4; - Penvsustain = 2; - Penvval[0] = PA_val; - Penvdt[1] = PA_dt; - Penvval[1] = PD_val; - Penvdt[2] = PD_dt; - Penvval[2] = 64; - Penvdt[3] = PR_dt; - Penvval[3] = PR_val; - break; - case 5: - Penvpoints = 3; - Penvsustain = 1; - Penvval[0] = PA_val; - Penvdt[1] = PA_dt; - Penvval[1] = 64; - Penvdt[2] = PR_dt; - Penvval[2] = PR_val; - break; + case 1: + Penvpoints = 4; + Penvsustain = 2; + Penvval[0] = 0; + Penvdt[1] = PA_dt; + Penvval[1] = 127; + Penvdt[2] = PD_dt; + Penvval[2] = PS_val; + Penvdt[3] = PR_dt; + Penvval[3] = 0; + break; + case 2: + Penvpoints = 4; + Penvsustain = 2; + Penvval[0] = 0; + Penvdt[1] = PA_dt; + Penvval[1] = 127; + Penvdt[2] = PD_dt; + Penvval[2] = PS_val; + Penvdt[3] = PR_dt; + Penvval[3] = 0; + break; + case 3: + Penvpoints = 3; + Penvsustain = 1; + Penvval[0] = PA_val; + Penvdt[1] = PA_dt; + Penvval[1] = 64; + Penvdt[2] = PR_dt; + Penvval[2] = PR_val; + break; + case 4: + Penvpoints = 4; + Penvsustain = 2; + Penvval[0] = PA_val; + Penvdt[1] = PA_dt; + Penvval[1] = PD_val; + Penvdt[2] = PD_dt; + Penvval[2] = 64; + Penvdt[3] = PR_dt; + Penvval[3] = PR_val; + break; + case 5: + Penvpoints = 3; + Penvsustain = 1; + Penvval[0] = PA_val; + Penvdt[1] = PA_dt; + Penvval[1] = 64; + Penvdt[2] = PR_dt; + Penvval[2] = PR_val; + break; } } @@ -222,7 +222,7 @@ void EnvelopeParams::add2XML(XMLwrapper *xml) xml->addpar("S_val", PS_val); xml->addpar("R_val", PR_val); - if((Pfreemode != 0) || (!xml->minimal)) { + if((Pfreemode != 0) || (!xml->minimal)) for(int i = 0; i < Penvpoints; ++i) { xml->beginbranch("POINT", i); if(i != 0) @@ -230,14 +230,13 @@ void EnvelopeParams::add2XML(XMLwrapper *xml) xml->addpar("val", Penvval[i]); xml->endbranch(); } - } } void EnvelopeParams::getfromXML(XMLwrapper *xml) { - Pfreemode = xml->getparbool("free_mode", Pfreemode); + Pfreemode = xml->getparbool("free_mode", Pfreemode); Penvpoints = xml->getpar127("env_points", Penvpoints); Penvsustain = xml->getpar127("env_sustain", Penvsustain); Penvstretch = xml->getpar127("env_stretch", Penvstretch); @@ -295,4 +294,3 @@ void EnvelopeParams::store2defaults() DS_val = PS_val; DR_val = PR_val; } - diff --git a/src/Params/EnvelopeParams.h b/src/Params/EnvelopeParams.h index 8f1a6275..0b3e99c9 100644 --- a/src/Params/EnvelopeParams.h +++ b/src/Params/EnvelopeParams.h @@ -87,4 +87,3 @@ class EnvelopeParams:public Presets }; #endif - diff --git a/src/Params/FilterParams.cpp b/src/Params/FilterParams.cpp index 2d4609b1..9cd21876 100644 --- a/src/Params/FilterParams.cpp +++ b/src/Params/FilterParams.cpp @@ -29,12 +29,12 @@ FilterParams::FilterParams(unsigned char Ptype_, unsigned char Pfreq_, unsigned char Pq_) - : PresetsArray() + :PresetsArray() { setpresettype("Pfilter"); - Dtype = Ptype_; - Dfreq = Pfreq_; - Dq = Pq_; + Dtype = Ptype_; + Dfreq = Pfreq_; + Dq = Pq_; changed = false; defaults(); @@ -46,14 +46,14 @@ FilterParams::~FilterParams() void FilterParams::defaults() { - Ptype = Dtype; - Pfreq = Dfreq; - Pq = Dq; + Ptype = Dtype; + Pfreq = Dfreq; + Pq = Dq; Pstages = 0; Pfreqtrack = 64; - Pgain = 64; - Pcategory = 0; + Pgain = 64; + Pcategory = 0; Pnumformants = 3; Pformantslowness = 64; @@ -67,9 +67,9 @@ void FilterParams::defaults() Psequencestretch = 40; Psequencereversed = 0; - Pcenterfreq = 64; //1 kHz - Poctavesfreq = 64; - Pvowelclearness = 64; + Pcenterfreq = 64; //1 kHz + Poctavesfreq = 64; + Pvowelclearness = 64; } void FilterParams::defaults(int n) @@ -94,24 +94,23 @@ void FilterParams::getfromFilterParams(FilterParams *pars) if(pars == NULL) return; - Ptype = pars->Ptype; - Pfreq = pars->Pfreq; - Pq = pars->Pq; + Ptype = pars->Ptype; + Pfreq = pars->Pfreq; + Pq = pars->Pq; Pstages = pars->Pstages; Pfreqtrack = pars->Pfreqtrack; - Pgain = pars->Pgain; - Pcategory = pars->Pcategory; + Pgain = pars->Pgain; + Pcategory = pars->Pcategory; Pnumformants = pars->Pnumformants; Pformantslowness = pars->Pformantslowness; - for(int j = 0; j < FF_MAX_VOWELS; ++j) { + for(int j = 0; j < FF_MAX_VOWELS; ++j) for(int i = 0; i < FF_MAX_FORMANTS; ++i) { Pvowels[j].formants[i].freq = pars->Pvowels[j].formants[i].freq; Pvowels[j].formants[i].q = pars->Pvowels[j].formants[i].q; Pvowels[j].formants[i].amp = pars->Pvowels[j].formants[i].amp; } - } Psequencesize = pars->Psequencesize; for(int i = 0; i < FF_MAX_SEQUENCE; ++i) @@ -119,9 +118,9 @@ void FilterParams::getfromFilterParams(FilterParams *pars) Psequencestretch = pars->Psequencestretch; Psequencereversed = pars->Psequencereversed; - Pcenterfreq = pars->Pcenterfreq; - Poctavesfreq = pars->Poctavesfreq; - Pvowelclearness = pars->Pvowelclearness; + Pcenterfreq = pars->Pcenterfreq; + Poctavesfreq = pars->Poctavesfreq; + Pvowelclearness = pars->Pvowelclearness; } @@ -202,7 +201,8 @@ void FilterParams::formantfilterH(int nvowel, int nfreqs, float *freqs) filter_q = getformantq(Pvowels[nvowel].formants[nformant].q) * getq(); if(Pstages > 0) filter_q = - (filter_q > 1.0f ? powf(filter_q, 1.0f / (Pstages + 1)) : filter_q); + (filter_q > + 1.0f ? powf(filter_q, 1.0f / (Pstages + 1)) : filter_q); filter_amp = getformantamp(Pvowels[nvowel].formants[nformant].amp); @@ -213,11 +213,11 @@ void FilterParams::formantfilterH(int nvowel, int nfreqs, float *freqs) cs = cosf(omega); alpha = sn / (2 * filter_q); float tmp = 1 + alpha; - c[0] = alpha / tmp *sqrt(filter_q + 1); - c[1] = 0; - c[2] = -alpha / tmp *sqrt(filter_q + 1); - d[1] = -2 * cs / tmp * (-1); - d[2] = (1 - alpha) / tmp * (-1); + c[0] = alpha / tmp *sqrt(filter_q + 1); + c[1] = 0; + c[2] = -alpha / tmp *sqrt(filter_q + 1); + d[1] = -2 * cs / tmp * (-1); + d[2] = (1 - alpha) / tmp * (-1); } else continue; @@ -339,11 +339,11 @@ void FilterParams::getfromXMLsection(XMLwrapper *xml, int n) "freq", Pvowels[nvowel ].formants[nformant].freq); - Pvowels[nvowel].formants[nformant].amp = xml->getpar127( + Pvowels[nvowel].formants[nformant].amp = xml->getpar127( "amp", Pvowels[nvowel ].formants[nformant].amp); - Pvowels[nvowel].formants[nformant].q = + Pvowels[nvowel].formants[nformant].q = xml->getpar127("q", Pvowels[nvowel].formants[nformant].q); xml->exitbranch(); } @@ -352,10 +352,10 @@ void FilterParams::getfromXMLsection(XMLwrapper *xml, int n) void FilterParams::getfromXML(XMLwrapper *xml) { //filter parameters - Pcategory = xml->getpar127("category", Pcategory); - Ptype = xml->getpar127("type", Ptype); - Pfreq = xml->getpar127("freq", Pfreq); - Pq = xml->getpar127("q", Pq); + Pcategory = xml->getpar127("category", Pcategory); + Ptype = xml->getpar127("type", Ptype); + Pfreq = xml->getpar127("freq", Pfreq); + Pq = xml->getpar127("q", Pq); Pstages = xml->getpar127("stages", Pstages); Pfreqtrack = xml->getpar127("freq_track", Pfreqtrack); Pgain = xml->getpar127("gain", Pgain); @@ -390,4 +390,3 @@ void FilterParams::getfromXML(XMLwrapper *xml) xml->exitbranch(); } } - diff --git a/src/Params/FilterParams.h b/src/Params/FilterParams.h index 42f8e60b..22a1a94f 100644 --- a/src/Params/FilterParams.h +++ b/src/Params/FilterParams.h @@ -27,7 +27,7 @@ #include "../Misc/XMLwrapper.h" #include "PresetsArray.h" -class FilterParams : public PresetsArray +class FilterParams:public PresetsArray { public: FilterParams(unsigned char Ptype_, @@ -100,4 +100,3 @@ class FilterParams : public PresetsArray }; #endif - diff --git a/src/Params/LFOParams.cpp b/src/Params/LFOParams.cpp index ccbe0997..a90ee731 100644 --- a/src/Params/LFOParams.cpp +++ b/src/Params/LFOParams.cpp @@ -25,7 +25,7 @@ #include "../globals.h" #include "LFOParams.h" -int LFOParams::time; +int LFOParams:: time; LFOParams::LFOParams(char Pfreq_, char Pintensity_, @@ -37,17 +37,17 @@ LFOParams::LFOParams(char Pfreq_, char fel_):Presets() { switch(fel_) { - case 0: - setpresettype("Plfofrequency"); - break; - case 1: - setpresettype("Plfoamplitude"); - break; - case 2: - setpresettype("Plfofilter"); - break; + case 0: + setpresettype("Plfofrequency"); + break; + case 1: + setpresettype("Plfoamplitude"); + break; + case 2: + setpresettype("Plfofilter"); + break; } - Dfreq = Pfreq_; + Dfreq = Pfreq_; Dintensity = Pintensity_; Dstartphase = Pstartphase_; DLFOtype = PLFOtype_; @@ -65,7 +65,7 @@ LFOParams::~LFOParams() void LFOParams::defaults() { - Pfreq = Dfreq / 127.0f; + Pfreq = Dfreq / 127.0f; Pintensity = Dintensity; Pstartphase = Dstartphase; PLFOtype = DLFOtype; @@ -92,7 +92,7 @@ void LFOParams::add2XML(XMLwrapper *xml) void LFOParams::getfromXML(XMLwrapper *xml) { - Pfreq = xml->getparreal("freq", Pfreq, 0.0f, 1.0f); + Pfreq = xml->getparreal("freq", Pfreq, 0.0f, 1.0f); Pintensity = xml->getpar127("intensity", Pintensity); Pstartphase = xml->getpar127("start_phase", Pstartphase); PLFOtype = xml->getpar127("lfo_type", PLFOtype); @@ -102,4 +102,3 @@ void LFOParams::getfromXML(XMLwrapper *xml) Pstretch = xml->getpar127("stretch", Pstretch); Pcontinous = xml->getparbool("continous", Pcontinous); } - diff --git a/src/Params/LFOParams.h b/src/Params/LFOParams.h index 4378e651..6ca30719 100644 --- a/src/Params/LFOParams.h +++ b/src/Params/LFOParams.h @@ -45,7 +45,7 @@ class LFOParams:public Presets void getfromXML(XMLwrapper *xml); /* MIDI Parameters*/ - float Pfreq; /**ADvsPAD = true; - FreqEnvelope = new EnvelopeParams(0, 0); + FreqEnvelope = new EnvelopeParams(0, 0); FreqEnvelope->ASRinit(64, 50, 64, 60); - FreqLfo = new LFOParams(70, 0, 64, 0, 0, 0, 0, 0); + FreqLfo = new LFOParams(70, 0, 64, 0, 0, 0, 0, 0); - AmpEnvelope = new EnvelopeParams(64, 1); + AmpEnvelope = new EnvelopeParams(64, 1); AmpEnvelope->ADSRinit_dB(0, 40, 127, 25); - AmpLfo = new LFOParams(80, 0, 64, 0, 0, 0, 0, 1); + AmpLfo = new LFOParams(80, 0, 64, 0, 0, 0, 0, 1); GlobalFilter = new FilterParams(2, 94, 40); FilterEnvelope = new EnvelopeParams(0, 1); FilterEnvelope->ADSRinit_filter(64, 40, 64, 70, 60, 64); - FilterLfo = new LFOParams(80, 0, 64, 0, 0, 0, 0, 2); + FilterLfo = new LFOParams(80, 0, 64, 0, 0, 0, 0, 2); for(int i = 0; i < PAD_MAX_SAMPLES; ++i) sample[i].smp = NULL; @@ -78,13 +78,13 @@ void PADnoteParameters::defaults() Php.freqmult = 0; Php.modulator.par1 = 0; Php.modulator.freq = 30; - Php.width = 127; - Php.amp.type = 0; - Php.amp.mode = 0; - Php.amp.par1 = 80; - Php.amp.par2 = 64; - Php.autoscale = true; - Php.onehalf = 0; + Php.width = 127; + Php.amp.type = 0; + Php.amp.mode = 0; + Php.amp.par1 = 80; + Php.amp.par2 = 64; + Php.autoscale = true; + Php.onehalf = 0; setPbandwidth(500); Pbwscale = 0; @@ -99,8 +99,8 @@ void PADnoteParameters::defaults() Pquality.samplesize = 3; Pquality.basenote = 4; - Pquality.oct = 3; - Pquality.smpoct = 2; + Pquality.oct = 3; + Pquality.smpoct = 2; PStereo = 1; //stereo /* Frequency Global Parameters */ @@ -159,23 +159,24 @@ float PADnoteParameters::getprofile(float *smp, int size) for(int i = 0; i < size; ++i) smp[i] = 0.0f; const int supersample = 16; - float basepar = powf(2.0f, (1.0f - Php.base.par1 / 127.0f) * 12.0f); - float freqmult = floor(powf(2.0f, - Php.freqmult / 127.0f * 5.0f) + 0.000001f); - - float modfreq = floor(powf(2.0f, - Php.modulator.freq / 127.0f - * 5.0f) + 0.000001f); - float modpar1 = powf(Php.modulator.par1 / 127.0f, 4.0f) * 5.0f / sqrt( + float basepar = powf(2.0f, (1.0f - Php.base.par1 / 127.0f) * 12.0f); + float freqmult = floor(powf(2.0f, + Php.freqmult / 127.0f + * 5.0f) + 0.000001f); + + float modfreq = floor(powf(2.0f, + Php.modulator.freq / 127.0f + * 5.0f) + 0.000001f); + float modpar1 = powf(Php.modulator.par1 / 127.0f, 4.0f) * 5.0f / sqrt( modfreq); - float amppar1 = + float amppar1 = powf(2.0f, powf(Php.amp.par1 / 127.0f, 2.0f) * 10.0f) - 0.999f; - float amppar2 = (1.0f - Php.amp.par2 / 127.0f) * 0.998f + 0.001f; - float width = powf(150.0f / (Php.width + 22.0f), 2.0f); + float amppar2 = (1.0f - Php.amp.par2 / 127.0f) * 0.998f + 0.001f; + float width = powf(150.0f / (Php.width + 22.0f), 2.0f); for(int i = 0; i < size * supersample; ++i) { - bool makezero = false; - float x = i * 1.0f / (size * (float) supersample); + bool makezero = false; + float x = i * 1.0f / (size * (float) supersample); float origx = x; @@ -185,21 +186,20 @@ float PADnoteParameters::getprofile(float *smp, int size) x = 0.0f; makezero = true; } - else { - if(x > 1.0f) { - x = 1.0f; - makezero = true; - } + else + if(x > 1.0f) { + x = 1.0f; + makezero = true; } //compute the full profile or one half switch(Php.onehalf) { - case 1: - x = x * 0.5f + 0.5f; - break; - case 2: - x = x * 0.5f; - break; + case 1: + x = x * 0.5f + 0.5f; + break; + case 2: + x = x * 0.5f; + break; } float x_before_freq_mult = x; @@ -215,19 +215,19 @@ float PADnoteParameters::getprofile(float *smp, int size) //this is the base function of the profile float f; switch(Php.base.type) { - case 1: - f = expf(-(x * x) * basepar); - if(f < 0.4f) - f = 0.0f; - else - f = 1.0f; - break; - case 2: - f = expf(-(fabs(x)) * sqrt(basepar)); - break; - default: - f = expf(-(x * x) * basepar); - break; + case 1: + f = expf(-(x * x) * basepar); + if(f < 0.4f) + f = 0.0f; + else + f = 1.0f; + break; + case 2: + f = expf(-(fabs(x)) * sqrt(basepar)); + break; + default: + f = expf(-(x * x) * basepar); + break; } if(makezero) f = 0.0f; @@ -237,33 +237,39 @@ float PADnoteParameters::getprofile(float *smp, int size) //compute the amplitude multiplier switch(Php.amp.type) { - case 1: - amp = expf(-(origx * origx) * 10.0f * amppar1); - break; - case 2: - amp = 0.5f * (1.0f + cosf(3.1415926f * origx * sqrt(amppar1 * 4.0f + 1.0f))); - break; - case 3: - amp = 1.0f / (powf(origx * (amppar1 * 2.0f + 0.8f), 14.0f) + 1.0f); - break; - } - - //apply the amplitude multiplier - float finalsmp = f; - if(Php.amp.type != 0) - switch(Php.amp.mode) { - case 0: - finalsmp = amp * (1.0f - amppar2) + finalsmp * amppar2; - break; case 1: - finalsmp *= amp * (1.0f - amppar2) + amppar2; + amp = expf(-(origx * origx) * 10.0f * amppar1); break; case 2: - finalsmp = finalsmp / (amp + powf(amppar2, 4.0f) * 20.0f + 0.0001f); + amp = 0.5f + * (1.0f + + cosf(3.1415926f * origx * sqrt(amppar1 * 4.0f + 1.0f))); break; case 3: - finalsmp = amp / (finalsmp + powf(amppar2, 4.0f) * 20.0f + 0.0001f); + amp = 1.0f + / (powf(origx * (amppar1 * 2.0f + 0.8f), 14.0f) + 1.0f); break; + } + + //apply the amplitude multiplier + float finalsmp = f; + if(Php.amp.type != 0) + switch(Php.amp.mode) { + case 0: + finalsmp = amp * (1.0f - amppar2) + finalsmp * amppar2; + break; + case 1: + finalsmp *= amp * (1.0f - amppar2) + amppar2; + break; + case 2: + finalsmp = finalsmp + / (amp + powf(amppar2, 4.0f) * 20.0f + 0.0001f); + break; + case 3: + finalsmp = amp + / (finalsmp + + powf(amppar2, 4.0f) * 20.0f + 0.0001f); + break; } ; @@ -288,7 +294,7 @@ float PADnoteParameters::getprofile(float *smp, int size) //compute the estimated perceived bandwidth float sum = 0.0f; - int i; + int i; for(i = 0; i < size / 2 - 2; ++i) { sum += smp[i] * smp[i] + smp[size - i - 1] * smp[size - i - 1]; if(sum >= 4.0f) @@ -322,46 +328,48 @@ float PADnoteParameters::getNhr(int n) float n0 = n - 1.0f; float tmp = 0.0f; - int thresh = 0; + int thresh = 0; switch(Phrpos.type) { - case 1: - thresh = (int)(par2 * par2 * 100.0f) + 1; - if(n < thresh) - result = n; - else - result = 1.0f + n0 + (n0 - thresh + 1.0f) * par1 * 8.0f; - break; - case 2: - thresh = (int)(par2 * par2 * 100.0f) + 1; - if(n < thresh) + case 1: + thresh = (int)(par2 * par2 * 100.0f) + 1; + if(n < thresh) + result = n; + else + result = 1.0f + n0 + (n0 - thresh + 1.0f) * par1 * 8.0f; + break; + case 2: + thresh = (int)(par2 * par2 * 100.0f) + 1; + if(n < thresh) + result = n; + else + result = 1.0f + n0 - (n0 - thresh + 1.0f) * par1 * 0.90f; + break; + case 3: + tmp = par1 * 100.0f + 1.0f; + result = powf(n0 / tmp, 1.0f - par2 * 0.8f) * tmp + 1.0f; + break; + case 4: + result = n0 + * (1.0f + - par1) + + powf(n0 * 0.1f, par2 * 3.0f + + 1.0f) * par1 * 10.0f + 1.0f; + break; + case 5: + result = n0 + + sinf(n0 * par2 * par2 * PI + * 0.999f) * sqrt(par1) * 2.0f + 1.0f; + break; + case 6: + tmp = powf(par2 * 2.0f, 2.0f) + 0.1f; + result = n0 * powf(1.0f + par1 * powf(n0 * 0.8f, tmp), tmp) + 1.0f; + break; + default: result = n; - else - result = 1.0f + n0 - (n0 - thresh + 1.0f) * par1 * 0.90f; - break; - case 3: - tmp = par1 * 100.0f + 1.0f; - result = powf(n0 / tmp, 1.0f - par2 * 0.8f) * tmp + 1.0f; - break; - case 4: - result = n0 - * (1.0f - - par1) - + powf(n0 * 0.1f, par2 * 3.0f + 1.0f) * par1 * 10.0f + 1.0f; - break; - case 5: - result = n0 - + sinf(n0 * par2 * par2 * PI * 0.999f) * sqrt(par1) * 2.0f + 1.0f; - break; - case 6: - tmp = powf(par2 * 2.0f, 2.0f) + 0.1f; - result = n0 * powf(1.0f + par1 * powf(n0 * 0.8f, tmp), tmp) + 1.0f; - break; - default: - result = n; - break; + break; } - float par3 = Phrpos.par3 / 255.0f; + float par3 = Phrpos.par3 / 255.0f; float iresult = floor(result + 0.5f); float dresult = result - iresult; @@ -411,37 +419,37 @@ void PADnoteParameters::generatespectrum_bandwidthMode(float *spectrum, //compute the bandwidth of each harmonic float bandwidthcents = setPbandwidth(Pbandwidth); - float bw = + float bw = (powf(2.0f, bandwidthcents / 1200.0f) - 1.0f) * basefreq / bwadjust; float power = 1.0f; switch(Pbwscale) { - case 0: - power = 1.0f; - break; - case 1: - power = 0.0f; - break; - case 2: - power = 0.25f; - break; - case 3: - power = 0.5f; - break; - case 4: - power = 0.75f; - break; - case 5: - power = 1.5f; - break; - case 6: - power = 2.0f; - break; - case 7: - power = -0.5f; - break; + case 0: + power = 1.0f; + break; + case 1: + power = 0.0f; + break; + case 2: + power = 0.25f; + break; + case 3: + power = 0.5f; + break; + case 4: + power = 0.75f; + break; + case 5: + power = 1.5f; + break; + case 6: + power = 2.0f; + break; + case 7: + power = -0.5f; + break; } bw = bw * powf(realfreq / basefreq, power); - int ibw = (int)((bw / (SAMPLE_RATE * 0.5f) * size)) + 1; + int ibw = (int)((bw / (SAMPLE_RATE * 0.5f) * size)) + 1; float amp = harmonics[nh - 1]; if(resonance->Penabled) @@ -449,7 +457,7 @@ void PADnoteParameters::generatespectrum_bandwidthMode(float *spectrum, if(ibw > profilesize) { //if the bandwidth is larger than the profilesize float rap = sqrt((float)profilesize / (float)ibw); - int cfreq = + int cfreq = (int) (realfreq / (SAMPLE_RATE * 0.5f) * size) - ibw / 2; for(int i = 0; i < ibw; ++i) { int src = (int)(i * rap * rap); @@ -465,15 +473,16 @@ void PADnoteParameters::generatespectrum_bandwidthMode(float *spectrum, float rap = sqrt((float)ibw / (float)profilesize); float ibasefreq = realfreq / (SAMPLE_RATE * 0.5f) * size; for(int i = 0; i < profilesize; ++i) { - float idfreq = i / (float)profilesize - 0.5f; + float idfreq = i / (float)profilesize - 0.5f; idfreq *= ibw; - int spfreq = (int) (idfreq + ibasefreq); + int spfreq = (int) (idfreq + ibasefreq); float fspfreq = fmod((double)idfreq + ibasefreq, 1.0f); if(spfreq <= 0) continue; if(spfreq >= size - 1) break; - spectrum[spfreq] += amp * profile[i] * rap * (1.0f - fspfreq); + spectrum[spfreq] += amp * profile[i] * rap + * (1.0f - fspfreq); spectrum[spfreq + 1] += amp * profile[i] * rap * fspfreq; } } @@ -521,16 +530,16 @@ void PADnoteParameters::generatespectrum_otherModes(float *spectrum, float amp = harmonics[nh - 1]; if(resonance->Penabled) amp *= resonance->getfreqresponse(realfreq); - int cfreq = (int) (realfreq / (SAMPLE_RATE * 0.5f) * size); + int cfreq = (int) (realfreq / (SAMPLE_RATE * 0.5f) * size); spectrum[cfreq] = amp + 1e-9; } if(Pmode != 1) { int old = 0; - for(int k = 1; k < size; ++k) { + for(int k = 1; k < size; ++k) if((spectrum[k] > 1e-10) || (k == (size - 1))) { - int delta = k - old; + int delta = k - old; float val1 = spectrum[old]; float val2 = spectrum[k]; float idelta = 1.0f / delta; @@ -540,7 +549,6 @@ void PADnoteParameters::generatespectrum_otherModes(float *spectrum, } old = k; } - } } } @@ -550,10 +558,10 @@ void PADnoteParameters::generatespectrum_otherModes(float *spectrum, void PADnoteParameters::applyparameters(bool lockmutex) { const int samplesize = (((int) 1) << (Pquality.samplesize + 14)); - int spectrumsize = samplesize / 2; - float spectrum[spectrumsize]; - int profilesize = 512; - float profile[profilesize]; + int spectrumsize = samplesize / 2; + float spectrum[spectrumsize]; + int profilesize = 512; + float profile[profilesize]; float bwadjust = getprofile(profile, profilesize); @@ -598,7 +606,7 @@ void PADnoteParameters::applyparameters(bool lockmutex) basefreq * basefreqadjust); const int extra_samples = 5; //the last samples contains the first samples (used for linear/cubic interpolation) - newsample.smp = new float[samplesize + extra_samples]; + newsample.smp = new float[samplesize + extra_samples]; newsample.smp[0] = 0.0f; for(int i = 1; i < spectrumsize; ++i) //randomize the phases @@ -610,7 +618,7 @@ void PADnoteParameters::applyparameters(bool lockmutex) float rms = 0.0f; for(int i = 0; i < samplesize; ++i) rms += newsample.smp[i] * newsample.smp[i]; - rms = sqrt(rms); + rms = sqrt(rms); if(rms < 0.000001f) rms = 1.0f; rms *= sqrt(262144.0f / samplesize); @@ -664,7 +672,7 @@ void PADnoteParameters::export2wav(std::string basefilename) char tmpstr[20]; snprintf(tmpstr, 20, "_%02d", k + 1); std::string filename = basefilename + std::string(tmpstr) + ".wav"; - WavFile wav(filename, SAMPLE_RATE, 1); + WavFile wav(filename, SAMPLE_RATE, 1); if(wav.good()) { int nsmps = sample[k].size; short int *smps = new short int[nsmps]; @@ -782,25 +790,25 @@ void PADnoteParameters::getfromXML(XMLwrapper *xml) Pbwscale = xml->getpar127("bandwidth_scale", Pbwscale); if(xml->enterbranch("HARMONIC_PROFILE")) { - Php.base.type = xml->getpar127("base_type", Php.base.type); - Php.base.par1 = xml->getpar127("base_par1", Php.base.par1); - Php.freqmult = xml->getpar127("frequency_multiplier", - Php.freqmult); + Php.base.type = xml->getpar127("base_type", Php.base.type); + Php.base.par1 = xml->getpar127("base_par1", Php.base.par1); + Php.freqmult = xml->getpar127("frequency_multiplier", + Php.freqmult); Php.modulator.par1 = xml->getpar127("modulator_par1", Php.modulator.par1); Php.modulator.freq = xml->getpar127("modulator_frequency", Php.modulator.freq); - Php.width = xml->getpar127("width", Php.width); - Php.amp.type = xml->getpar127("amplitude_multiplier_type", - Php.amp.type); - Php.amp.mode = xml->getpar127("amplitude_multiplier_mode", - Php.amp.mode); - Php.amp.par1 = xml->getpar127("amplitude_multiplier_par1", - Php.amp.par1); - Php.amp.par2 = xml->getpar127("amplitude_multiplier_par2", - Php.amp.par2); - Php.autoscale = xml->getparbool("autoscale", Php.autoscale); - Php.onehalf = xml->getpar127("one_half", Php.onehalf); + Php.width = xml->getpar127("width", Php.width); + Php.amp.type = xml->getpar127("amplitude_multiplier_type", + Php.amp.type); + Php.amp.mode = xml->getpar127("amplitude_multiplier_mode", + Php.amp.mode); + Php.amp.par1 = xml->getpar127("amplitude_multiplier_par1", + Php.amp.par1); + Php.amp.par2 = xml->getpar127("amplitude_multiplier_par2", + Php.amp.par2); + Php.autoscale = xml->getparbool("autoscale", Php.autoscale); + Php.onehalf = xml->getpar127("one_half", Php.onehalf); xml->exitbranch(); } @@ -825,9 +833,9 @@ void PADnoteParameters::getfromXML(XMLwrapper *xml) if(xml->enterbranch("SAMPLE_QUALITY")) { Pquality.samplesize = xml->getpar127("samplesize", Pquality.samplesize); Pquality.basenote = xml->getpar127("basenote", Pquality.basenote); - Pquality.oct = xml->getpar127("octaves", Pquality.oct); - Pquality.smpoct = xml->getpar127("samples_per_octave", - Pquality.smpoct); + Pquality.oct = xml->getpar127("octaves", Pquality.oct); + Pquality.smpoct = xml->getpar127("samples_per_octave", + Pquality.smpoct); xml->exitbranch(); } @@ -891,4 +899,3 @@ void PADnoteParameters::getfromXML(XMLwrapper *xml) xml->exitbranch(); } } - diff --git a/src/Params/PADnoteParameters.h b/src/Params/PADnoteParameters.h index b0fcdc8a..b3283216 100644 --- a/src/Params/PADnoteParameters.h +++ b/src/Params/PADnoteParameters.h @@ -100,7 +100,7 @@ class PADnoteParameters:public Presets /* Equal temperate (this is used only if the Pfixedfreq is enabled) If this parameter is 0, the frequency is fixed (to 440 Hz); if this parameter is 64, 1 MIDI halftone -> 1 frequency halftone */ - unsigned char PfixedfreqET; + unsigned char PfixedfreqET; unsigned short int PDetune; //fine detune unsigned short int PCoarseDetune; //coarse detune+octave unsigned char PDetuneType; //detune type @@ -152,7 +152,7 @@ class PADnoteParameters:public Presets Resonance *resonance; struct { - int size; + int size; float basefreq; float *smp; } sample[PAD_MAX_SAMPLES], newsample; @@ -170,11 +170,10 @@ class PADnoteParameters:public Presets void deletesamples(); void deletesample(int n); - FFTwrapper *fft; + FFTwrapper *fft; pthread_mutex_t *mutex; }; #endif - diff --git a/src/Params/Presets.cpp b/src/Params/Presets.cpp index 228964aa..d96fc536 100644 --- a/src/Params/Presets.cpp +++ b/src/Params/Presets.cpp @@ -26,7 +26,7 @@ Presets::Presets() { - type[0] = 0; + type[0] = 0; } Presets::~Presets() @@ -85,16 +85,14 @@ void Presets::paste(int npreset) return; } } - else { - if(!presetsstore.pastepreset(xml, npreset)) { - delete (xml); - return; - } + else + if(!presetsstore.pastepreset(xml, npreset)) { + delete (xml); + return; } - if(xml->enterbranch(type) == 0) { + if(xml->enterbranch(type) == 0) return; - } defaults(); getfromXML(xml); @@ -119,4 +117,3 @@ void Presets::deletepreset(int npreset) { presetsstore.deletepreset(npreset); } - diff --git a/src/Params/Presets.h b/src/Params/Presets.h index d8000fe3..a64d25e7 100644 --- a/src/Params/Presets.h +++ b/src/Params/Presets.h @@ -54,4 +54,3 @@ class Presets }; #endif - diff --git a/src/Params/PresetsArray.cpp b/src/Params/PresetsArray.cpp index b1c9a2e0..420b6818 100644 --- a/src/Params/PresetsArray.cpp +++ b/src/Params/PresetsArray.cpp @@ -95,12 +95,11 @@ void PresetsArray::paste(int npreset) return; } } - else { - if(!presetsstore.pastepreset(xml, npreset)) { - delete (xml); - nelement = -1; - return; - } + else + if(!presetsstore.pastepreset(xml, npreset)) { + delete (xml); + nelement = -1; + return; } if(xml->enterbranch(type) == 0) { @@ -135,4 +134,3 @@ void PresetsArray::setelement(int n) { nelement = n; } - diff --git a/src/Params/PresetsArray.h b/src/Params/PresetsArray.h index aea7ed36..1b17e40e 100644 --- a/src/Params/PresetsArray.h +++ b/src/Params/PresetsArray.h @@ -28,7 +28,7 @@ #include "Presets.h" /**PresetsArray and Clipboard management*/ -class PresetsArray : public Presets +class PresetsArray:public Presets { public: PresetsArray(); @@ -51,10 +51,9 @@ class PresetsArray : public Presets virtual void getfromXML(XMLwrapper *xml) = 0; virtual void defaults() = 0; virtual void add2XMLsection(XMLwrapper *xml, int n) = 0; - virtual void getfromXMLsection(XMLwrapper *xml, int n) = 0; + virtual void getfromXMLsection(XMLwrapper *xml, int n) = 0; virtual void defaults(int n) = 0; int nelement; }; #endif - diff --git a/src/Params/PresetsStore.cpp b/src/Params/PresetsStore.cpp index 4bbb1cf0..b37c123a 100644 --- a/src/Params/PresetsStore.cpp +++ b/src/Params/PresetsStore.cpp @@ -101,8 +101,8 @@ void PresetsStore::rescanforpresets(const string &type) continue; //open directory - string dirname = config.cfg.presetsDirList[i]; - DIR *dir = opendir(dirname.c_str()); + string dirname = config.cfg.presetsDirList[i]; + DIR *dir = opendir(dirname.c_str()); if(dir == NULL) continue; struct dirent *fn; @@ -168,7 +168,7 @@ bool PresetsStore::pastepreset(XMLwrapper *xml, unsigned int npreset) string filename = presets[npreset].file; if(filename.empty()) return false; - bool result = (xml->loadXMLfile(filename) >= 0); + bool result = (xml->loadXMLfile(filename) >= 0); return result; } @@ -182,4 +182,3 @@ void PresetsStore::deletepreset(unsigned int npreset) return; remove(filename.c_str()); } - diff --git a/src/Params/PresetsStore.h b/src/Params/PresetsStore.h index acf07373..355ed522 100644 --- a/src/Params/PresetsStore.h +++ b/src/Params/PresetsStore.h @@ -45,7 +45,7 @@ class PresetsStore struct presetstruct { presetstruct(std::string _file, std::string _name) - :file(_file),name(_name){}; + :file(_file), name(_name) {} bool operator<(const presetstruct &b) const; std::string file; std::string name; @@ -64,4 +64,3 @@ class PresetsStore }; extern PresetsStore presetsstore; - diff --git a/src/Params/SUBnoteParameters.cpp b/src/Params/SUBnoteParameters.cpp index 4e73fae4..f4e6db99 100644 --- a/src/Params/SUBnoteParameters.cpp +++ b/src/Params/SUBnoteParameters.cpp @@ -29,7 +29,7 @@ SUBnoteParameters::SUBnoteParameters():Presets() setpresettype("Psubsyth"); AmpEnvelope = new EnvelopeParams(64, 1); AmpEnvelope->ADSRinit_dB(0, 40, 127, 25); - FreqEnvelope = new EnvelopeParams(64, 0); + FreqEnvelope = new EnvelopeParams(64, 0); FreqEnvelope->ASRinit(30, 50, 64, 60); BandWidthEnvelope = new EnvelopeParams(64, 0); BandWidthEnvelope->ASRinit_bw(100, 70, 64, 60); @@ -48,16 +48,16 @@ void SUBnoteParameters::defaults() PPanning = 64; PAmpVelocityScaleFunction = 90; - Pfixedfreq = 0; - PfixedfreqET = 0; - Pnumstages = 2; - Pbandwidth = 40; - Phmagtype = 0; - Pbwscale = 64; - Pstereo = 1; - Pstart = 1; + Pfixedfreq = 0; + PfixedfreqET = 0; + Pnumstages = 2; + Pbandwidth = 40; + Phmagtype = 0; + Pbwscale = 64; + Pstereo = 1; + Pstart = 1; - PDetune = 8192; + PDetune = 8192; PCoarseDetune = 0; PDetuneType = 1; PFreqEnvelopeEnabled = 0; @@ -198,15 +198,15 @@ void SUBnoteParameters::getfromXML(XMLwrapper *xml) } if(xml->enterbranch("FREQUENCY_PARAMETERS")) { - Pfixedfreq = xml->getparbool("fixed_freq", Pfixedfreq); - PfixedfreqET = xml->getpar127("fixed_freq_et", PfixedfreqET); + Pfixedfreq = xml->getparbool("fixed_freq", Pfixedfreq); + PfixedfreqET = xml->getpar127("fixed_freq_et", PfixedfreqET); - PDetune = xml->getpar("detune", PDetune, 0, 16383); + PDetune = xml->getpar("detune", PDetune, 0, 16383); PCoarseDetune = xml->getpar("coarse_detune", PCoarseDetune, 0, 16383); PDetuneType = xml->getpar127("detune_type", PDetuneType); - Pbandwidth = xml->getpar127("bandwidth", Pbandwidth); - Pbwscale = xml->getpar127("bandwidth_scale", Pbwscale); + Pbandwidth = xml->getpar127("bandwidth", Pbandwidth); + Pbwscale = xml->getpar127("bandwidth_scale", Pbwscale); PFreqEnvelopeEnabled = xml->getparbool("freq_envelope_enabled", PFreqEnvelopeEnabled); @@ -248,4 +248,3 @@ void SUBnoteParameters::getfromXML(XMLwrapper *xml) xml->exitbranch(); } } - diff --git a/src/Params/SUBnoteParameters.h b/src/Params/SUBnoteParameters.h index f564b1f7..111841e5 100644 --- a/src/Params/SUBnoteParameters.h +++ b/src/Params/SUBnoteParameters.h @@ -101,4 +101,3 @@ class SUBnoteParameters:public Presets }; #endif - diff --git a/src/Samples/Sample.cpp b/src/Samples/Sample.cpp index 465965f2..b85247ea 100644 --- a/src/Samples/Sample.cpp +++ b/src/Samples/Sample.cpp @@ -19,7 +19,7 @@ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include -#include //for memcpy/memset +#include //for memcpy/memset #include #include "Sample.h" @@ -30,7 +30,7 @@ using namespace std; /**\TODO start using pointer math here as these will be Frequency called * functions throughout the code*/ Sample::Sample() - :bufferSize(1),buffer(new float[1]) + :bufferSize(1), buffer(new float[1]) { buffer[0] = 0.0f; } @@ -105,7 +105,11 @@ bool Sample::operator==(const Sample &smp) const * @param xb X of point b * @return estimated Y of test point */ -float linearEstimate(float ya, float yb, float xt, float xa = 0.0f, float xb =1.0f) +float linearEstimate(float ya, + float yb, + float xt, + float xa = 0.0f, + float xb = 1.0f) { #warning TODO this could be done with a good bit less computation //Lets make this simple by normalizing the x axis @@ -121,7 +125,7 @@ float linearEstimate(float ya, float yb, float xt, float xa = 0.0f, float xb =1. //Now xa=0 xb=1 0<=xt<=1 //simpily use y=mx+b - return (yb-ya) * xt + ya; + return (yb - ya) * xt + ya; } @@ -129,7 +133,7 @@ void Sample::resample(const unsigned int rate, const unsigned int nrate) { if(rate == nrate) return; //no resampling here - else {//resampling occurs here + else { //resampling occurs here float ratio = (nrate * 1.0f) / (rate * 1.0f); int nBufferSize = (int)bufferSize * ratio; @@ -137,11 +141,11 @@ void Sample::resample(const unsigned int rate, const unsigned int nrate) //addition is done to avoid 0 edge case for(int i = 0; i < nBufferSize; ++i) - nBuffer[i] = linearEstimate(buffer[(int)floor(i/ratio)], - buffer[(int)ceil((i+1)/ratio)], + nBuffer[i] = linearEstimate(buffer[(int)floor(i / ratio)], + buffer[(int)ceil((i + 1) / ratio)], i, - floor(i/ratio), - ceil((i+1)/ratio)); + floor(i / ratio), + ceil((i + 1) / ratio)); //put the new data in delete[] buffer; @@ -152,8 +156,8 @@ void Sample::resample(const unsigned int rate, const unsigned int nrate) Sample &Sample::append(const Sample &smp) { - int nbufferSize = bufferSize + smp.bufferSize; - float *nbuffer = new float[nbufferSize]; + int nbufferSize = bufferSize + smp.bufferSize; + float *nbuffer = new float[nbufferSize]; memcpy(nbuffer, buffer, bufferSize * sizeof(float)); memcpy(nbuffer + bufferSize, smp.buffer, smp.bufferSize * sizeof(float)); @@ -166,7 +170,7 @@ Sample &Sample::append(const Sample &smp) Sample Sample::subSample(int a, int b) const { - return Sample(b-a, buffer+a); + return Sample(b - a, buffer + a); } float Sample::max() const @@ -195,4 +199,3 @@ float Sample::absMax() const max = fabs(buffer[i]); return max; } - diff --git a/src/Samples/Sample.h b/src/Samples/Sample.h index d74c8bfc..a3e11a1f 100644 --- a/src/Samples/Sample.h +++ b/src/Samples/Sample.h @@ -76,4 +76,3 @@ class Sample float *buffer; }; #endif - diff --git a/src/Synth/ADnote.cpp b/src/Synth/ADnote.cpp index b3fae7cf..31004fdd 100644 --- a/src/Synth/ADnote.cpp +++ b/src/Synth/ADnote.cpp @@ -38,29 +38,28 @@ ADnote::ADnote(ADnoteParameters *pars, int portamento_, int midinote_, bool besilent) -:SynthNote(freq, velocity, portamento_, midinote, besilent) + :SynthNote(freq, velocity, portamento_, midinote, besilent) { - tmpwavel = new float [SOUND_BUFFER_SIZE]; tmpwaver = new float [SOUND_BUFFER_SIZE]; bypassl = new float [SOUND_BUFFER_SIZE]; bypassr = new float [SOUND_BUFFER_SIZE]; - partparams = pars; + partparams = pars; ctl = ctl_; - portamento = portamento_; - midinote = midinote_; - NoteEnabled = ON; - basefreq = freq; + portamento = portamento_; + midinote = midinote_; + NoteEnabled = ON; + basefreq = freq; if(velocity > 1.0f) velocity = 1.0f; this->velocity = velocity; time = 0.0f; stereo = pars->GlobalPar.PStereo; - NoteGlobalPar.Detune = getdetune(pars->GlobalPar.PDetuneType, - pars->GlobalPar.PCoarseDetune, - pars->GlobalPar.PDetune); + NoteGlobalPar.Detune = getdetune(pars->GlobalPar.PDetuneType, + pars->GlobalPar.PCoarseDetune, + pars->GlobalPar.PDetune); bandwidthDetuneMultiplier = pars->getBandwidthDetuneMultiplier(); if(pars->GlobalPar.PPanning == 0) @@ -77,16 +76,16 @@ ADnote::ADnote(ADnoteParameters *pars, PFilterVelocityScaleFunction) - 1); if(pars->GlobalPar.PPunchStrength != 0) { - NoteGlobalPar.Punch.Enabled = 1; + NoteGlobalPar.Punch.Enabled = 1; NoteGlobalPar.Punch.t = 1.0f; //start from 1.0f and to 0.0f NoteGlobalPar.Punch.initialvalue = ((powf(10, 1.5f * pars->GlobalPar.PPunchStrength / 127.0f) - 1.0f) * VelF(velocity, pars->GlobalPar.PPunchVelocitySensing)); - float time = + float time = powf(10, 3.0f * pars->GlobalPar.PPunchTime / 127.0f) / 10000.0f; //0.1f .. 100 ms float stretch = powf(440.0f / freq, - pars->GlobalPar.PPunchStretch / 64.0f); + pars->GlobalPar.PPunchStretch / 64.0f); NoteGlobalPar.Punch.dt = 1.0f / (time * SAMPLE_RATE * stretch); } else @@ -98,7 +97,7 @@ ADnote::ADnote(ADnoteParameters *pars, NoteVoicePar[nvoice].FMSmp = NULL; NoteVoicePar[nvoice].VoiceOut = NULL; - NoteVoicePar[nvoice].FMVoice = -1; + NoteVoicePar[nvoice].FMVoice = -1; unison_size[nvoice] = 1; if(pars->VoicePar[nvoice].Enabled == 0) { @@ -118,64 +117,66 @@ ADnote::ADnote(ADnoteParameters *pars, unison_base_freq_rap[nvoice] = new float[unison]; unison_freq_rap[nvoice] = new float[unison]; unison_invert_phase[nvoice] = new bool[unison]; - float unison_spread = pars->getUnisonFrequencySpreadCents( + float unison_spread = pars->getUnisonFrequencySpreadCents( nvoice); float unison_real_spread = powf(2.0f, (unison_spread * 0.5f) / 1200.0f); float unison_vibratto_a = pars->VoicePar[nvoice].Unison_vibratto - / 127.0f; //0.0f .. 1.0f + / 127.0f; //0.0f .. 1.0f switch(unison) { - case 1: - unison_base_freq_rap[nvoice][0] = 1.0f; //if the unison is not used, always make the only subvoice to have the default note - break; - case 2: { //unison for 2 subvoices - unison_base_freq_rap[nvoice][0] = 1.0f / unison_real_spread; - unison_base_freq_rap[nvoice][1] = unison_real_spread; - }; - break; - default: { //unison for more than 2 subvoices - float unison_values[unison]; - float min = -1e-6, max = 1e-6; - for(int k = 0; k < unison; ++k) { - float step = (k / (float) (unison - 1)) * 2.0f - 1.0f; //this makes the unison spread more uniform - float val = step + (RND * 2.0f - 1.0f) / (unison - 1); - unison_values[k] = limit(val, min, max); - } - float diff = max - min; - for(int k = 0; k < unison; ++k) { - unison_values[k] = - (unison_values[k] - (max + min) * 0.5f) / diff; //the lowest value will be -1 and the highest will be 1 - unison_base_freq_rap[nvoice][k] = - powf(2.0f, (unison_spread * unison_values[k]) / 1200); - } - }; + case 1: + unison_base_freq_rap[nvoice][0] = 1.0f; //if the unison is not used, always make the only subvoice to have the default note + break; + case 2: { //unison for 2 subvoices + unison_base_freq_rap[nvoice][0] = 1.0f / unison_real_spread; + unison_base_freq_rap[nvoice][1] = unison_real_spread; + }; + break; + default: { //unison for more than 2 subvoices + float unison_values[unison]; + float min = -1e-6, max = 1e-6; + for(int k = 0; k < unison; ++k) { + float step = (k / (float) (unison - 1)) * 2.0f - 1.0f; //this makes the unison spread more uniform + float val = step + (RND * 2.0f - 1.0f) / (unison - 1); + unison_values[k] = limit(val, min, max); + } + float diff = max - min; + for(int k = 0; k < unison; ++k) { + unison_values[k] = + (unison_values[k] - (max + min) * 0.5f) / diff; //the lowest value will be -1 and the highest will be 1 + unison_base_freq_rap[nvoice][k] = + powf(2.0f, (unison_spread * unison_values[k]) / 1200); + } + }; } //unison vibrattos - if(unison > 1) { + if(unison > 1) for(int k = 0; k < unison; ++k) //reduce the frequency difference for larger vibrattos unison_base_freq_rap[nvoice][k] = 1.0f - + (unison_base_freq_rap[nvoice][k] - 1.0f) - * (1.0f - unison_vibratto_a); - } + + (unison_base_freq_rap[ + nvoice][k] - 1.0f) + * (1.0f - unison_vibratto_a); unison_vibratto[nvoice].step = new float[unison]; unison_vibratto[nvoice].position = new float[unison]; unison_vibratto[nvoice].amplitude = (unison_real_spread - 1.0f) * unison_vibratto_a; float increments_per_second = SAMPLE_RATE - / (float)SOUND_BUFFER_SIZE; - float vibratto_base_period = 0.25f - * powf(2.0f, - (1.0f - - pars->VoicePar[nvoice]. - Unison_vibratto_speed / 127.0f) * 4.0f); + / (float)SOUND_BUFFER_SIZE; + float vibratto_base_period = 0.25f + * powf( + 2.0f, + (1.0f + - pars->VoicePar[nvoice]. + Unison_vibratto_speed + / 127.0f) * 4.0f); for(int k = 0; k < unison; ++k) { unison_vibratto[nvoice].position[k] = RND * 1.8f - 0.9f; //make period to vary randomly from 50% to 200% vibratto base period float vibratto_period = vibratto_base_period - * powf(2.0f, RND * 2.0f - 1.0f); + * powf(2.0f, RND * 2.0f - 1.0f); float m = 4.0f / (vibratto_period * increments_per_second); if(RND < 0.5f) @@ -194,16 +195,16 @@ ADnote::ADnote(ADnoteParameters *pars, if(unison != 1) { int inv = pars->VoicePar[nvoice].Unison_invert_phase; switch(inv) { - case 0: for(int k = 0; k < unison; ++k) - unison_invert_phase[nvoice][k] = false; - break; - case 1: for(int k = 0; k < unison; ++k) - unison_invert_phase[nvoice][k] = (RND > 0.5f); - break; - default: for(int k = 0; k < unison; ++k) - unison_invert_phase[nvoice][k] = - (k % inv == 0) ? true : false; - break; + case 0: for(int k = 0; k < unison; ++k) + unison_invert_phase[nvoice][k] = false; + break; + case 1: for(int k = 0; k < unison; ++k) + unison_invert_phase[nvoice][k] = (RND > 0.5f); + break; + default: for(int k = 0; k < unison; ++k) + unison_invert_phase[nvoice][k] = + (k % inv == 0) ? true : false; + break; } } @@ -223,7 +224,7 @@ ADnote::ADnote(ADnoteParameters *pars, //use the Globalpars.detunetype if the detunetype is 0 if(pars->VoicePar[nvoice].PDetuneType != 0) { - NoteVoicePar[nvoice].Detune = getdetune( + NoteVoicePar[nvoice].Detune = getdetune( pars->VoicePar[nvoice].PDetuneType, pars->VoicePar[nvoice]. PCoarseDetune, @@ -234,7 +235,7 @@ ADnote::ADnote(ADnoteParameters *pars, pars->VoicePar[nvoice].PDetune); //fine detune } else { - NoteVoicePar[nvoice].Detune = getdetune( + NoteVoicePar[nvoice].Detune = getdetune( pars->GlobalPar.PDetuneType, pars->VoicePar[nvoice]. PCoarseDetune, @@ -297,40 +298,40 @@ ADnote::ADnote(ADnoteParameters *pars, oscposhi_start = (int)(RND * (OSCIL_SIZE - 1)); //put random starting point for other subvoices } - NoteVoicePar[nvoice].FreqLfo = NULL; - NoteVoicePar[nvoice].FreqEnvelope = NULL; + NoteVoicePar[nvoice].FreqLfo = NULL; + NoteVoicePar[nvoice].FreqEnvelope = NULL; - NoteVoicePar[nvoice].AmpLfo = NULL; - NoteVoicePar[nvoice].AmpEnvelope = NULL; + NoteVoicePar[nvoice].AmpLfo = NULL; + NoteVoicePar[nvoice].AmpEnvelope = NULL; - NoteVoicePar[nvoice].VoiceFilterL = NULL; - NoteVoicePar[nvoice].VoiceFilterR = NULL; - NoteVoicePar[nvoice].FilterEnvelope = NULL; - NoteVoicePar[nvoice].FilterLfo = NULL; + NoteVoicePar[nvoice].VoiceFilterL = NULL; + NoteVoicePar[nvoice].VoiceFilterR = NULL; + NoteVoicePar[nvoice].FilterEnvelope = NULL; + NoteVoicePar[nvoice].FilterLfo = NULL; NoteVoicePar[nvoice].FilterCenterPitch = pars->VoicePar[nvoice].VoiceFilter->getfreq(); - NoteVoicePar[nvoice].filterbypass = + NoteVoicePar[nvoice].filterbypass = pars->VoicePar[nvoice].Pfilterbypass; switch(pars->VoicePar[nvoice].PFMEnabled) { - case 1: - NoteVoicePar[nvoice].FMEnabled = MORPH; - break; - case 2: - NoteVoicePar[nvoice].FMEnabled = RING_MOD; - break; - case 3: - NoteVoicePar[nvoice].FMEnabled = PHASE_MOD; - break; - case 4: - NoteVoicePar[nvoice].FMEnabled = FREQ_MOD; - break; - case 5: - NoteVoicePar[nvoice].FMEnabled = PITCH_MOD; - break; - default: - NoteVoicePar[nvoice].FMEnabled = NONE; + case 1: + NoteVoicePar[nvoice].FMEnabled = MORPH; + break; + case 2: + NoteVoicePar[nvoice].FMEnabled = RING_MOD; + break; + case 3: + NoteVoicePar[nvoice].FMEnabled = PHASE_MOD; + break; + case 4: + NoteVoicePar[nvoice].FMEnabled = FREQ_MOD; + break; + case 5: + NoteVoicePar[nvoice].FMEnabled = PITCH_MOD; + break; + default: + NoteVoicePar[nvoice].FMEnabled = NONE; } NoteVoicePar[nvoice].FMVoice = pars->VoicePar[nvoice].PFMVoice; @@ -339,30 +340,32 @@ ADnote::ADnote(ADnoteParameters *pars, //Compute the Voice's modulator volume (incl. damping) float fmvoldamp = powf(440.0f / getvoicebasefreq( - nvoice), - pars->VoicePar[nvoice].PFMVolumeDamp / 64.0f - - 1.0f); + nvoice), + pars->VoicePar[nvoice].PFMVolumeDamp / 64.0f + - 1.0f); switch(NoteVoicePar[nvoice].FMEnabled) { - case PHASE_MOD: - fmvoldamp = - powf(440.0f / getvoicebasefreq( - nvoice), pars->VoicePar[nvoice].PFMVolumeDamp / 64.0f); - NoteVoicePar[nvoice].FMVolume = - (expf(pars->VoicePar[nvoice].PFMVolume / 127.0f - * FM_AMP_MULTIPLIER) - 1.0f) * fmvoldamp * 4.0f; - break; - case FREQ_MOD: - NoteVoicePar[nvoice].FMVolume = - (expf(pars->VoicePar[nvoice].PFMVolume / 127.0f - * FM_AMP_MULTIPLIER) - 1.0f) * fmvoldamp * 4.0f; - break; - // case PITCH_MOD:NoteVoicePar[nvoice].FMVolume=(pars->VoicePar[nvoice].PFMVolume/127.0f*8.0f)*fmvoldamp;//??????????? - // break; - default: - if(fmvoldamp > 1.0f) - fmvoldamp = 1.0f; - NoteVoicePar[nvoice].FMVolume = pars->VoicePar[nvoice].PFMVolume - / 127.0f * fmvoldamp; + case PHASE_MOD: + fmvoldamp = + powf(440.0f / getvoicebasefreq( + nvoice), pars->VoicePar[nvoice].PFMVolumeDamp + / 64.0f); + NoteVoicePar[nvoice].FMVolume = + (expf(pars->VoicePar[nvoice].PFMVolume / 127.0f + * FM_AMP_MULTIPLIER) - 1.0f) * fmvoldamp * 4.0f; + break; + case FREQ_MOD: + NoteVoicePar[nvoice].FMVolume = + (expf(pars->VoicePar[nvoice].PFMVolume / 127.0f + * FM_AMP_MULTIPLIER) - 1.0f) * fmvoldamp * 4.0f; + break; + // case PITCH_MOD:NoteVoicePar[nvoice].FMVolume=(pars->VoicePar[nvoice].PFMVolume/127.0f*8.0f)*fmvoldamp;//??????????? + // break; + default: + if(fmvoldamp > 1.0f) + fmvoldamp = 1.0f; + NoteVoicePar[nvoice].FMVolume = + pars->VoicePar[nvoice].PFMVolume + / 127.0f * fmvoldamp; } //Voice's modulator velocity sensing @@ -377,7 +380,7 @@ ADnote::ADnote(ADnoteParameters *pars, firsttick[nvoice] = 1; NoteVoicePar[nvoice].DelayTicks = (int)((expf(pars->VoicePar[nvoice].PDelay / 127.0f - * logf(50.0f)) + * logf(50.0f)) - 1.0f) / SOUND_BUFFER_SIZE / 10.0f * SAMPLE_RATE); } @@ -417,9 +420,9 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, velocity = 1.0f; this->velocity = velocity; - NoteGlobalPar.Detune = getdetune(pars->GlobalPar.PDetuneType, - pars->GlobalPar.PCoarseDetune, - pars->GlobalPar.PDetune); + NoteGlobalPar.Detune = getdetune(pars->GlobalPar.PDetuneType, + pars->GlobalPar.PCoarseDetune, + pars->GlobalPar.PDetune); bandwidthDetuneMultiplier = pars->getBandwidthDetuneMultiplier(); if(pars->GlobalPar.PPanning == 0) @@ -429,8 +432,11 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, //center freq NoteGlobalPar.FilterCenterPitch = pars->GlobalPar.GlobalFilter->getfreq() - + pars->GlobalPar.PFilterVelocityScale / 127.0f * 6.0f //velocity sensing - * (VelF(velocity, pars->GlobalPar.PFilterVelocityScaleFunction) - 1); + + pars->GlobalPar.PFilterVelocityScale + / 127.0f * 6.0f //velocity sensing + * (VelF(velocity, + pars->GlobalPar. + PFilterVelocityScaleFunction) - 1); for(int nvoice = 0; nvoice < NUM_VOICES; ++nvoice) { @@ -442,24 +448,24 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, //use the Globalpars.detunetype if the detunetype is 0 if(pars->VoicePar[nvoice].PDetuneType != 0) { - NoteVoicePar[nvoice].Detune = getdetune( + NoteVoicePar[nvoice].Detune = getdetune( pars->VoicePar[nvoice].PDetuneType, pars->VoicePar[nvoice].PCoarseDetune, - 8192);//coarse detune + 8192); //coarse detune NoteVoicePar[nvoice].FineDetune = getdetune( pars->VoicePar[nvoice].PDetuneType, 0, - pars->VoicePar[nvoice].PDetune);//fine detune + pars->VoicePar[nvoice].PDetune); //fine detune } else { - NoteVoicePar[nvoice].Detune = getdetune( + NoteVoicePar[nvoice].Detune = getdetune( pars->GlobalPar.PDetuneType, pars->VoicePar[nvoice].PCoarseDetune, - 8192);//coarse detune + 8192); //coarse detune NoteVoicePar[nvoice].FineDetune = getdetune( pars->GlobalPar.PDetuneType, 0, - pars->VoicePar[nvoice].PDetune);//fine detune + pars->VoicePar[nvoice].PDetune); //fine detune } if(pars->VoicePar[nvoice].PFMDetuneType != 0) NoteVoicePar[nvoice].FMDetune = getdetune( @@ -482,7 +488,7 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, pars->VoicePar[vc].OscilSmp->get(NoteVoicePar[nvoice].OscilSmp, getvoicebasefreq(nvoice), - pars->VoicePar[nvoice].Presonance);//(gf)Modif of the above line. + pars->VoicePar[nvoice].Presonance); //(gf)Modif of the above line. //I store the first elments to the last position for speedups for(int i = 0; i < OSCIL_SMP_EXTRA_SAMPLES; ++i) @@ -493,7 +499,7 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, NoteVoicePar[nvoice].FilterCenterPitch = pars->VoicePar[nvoice].VoiceFilter->getfreq(); - NoteVoicePar[nvoice].filterbypass = + NoteVoicePar[nvoice].filterbypass = pars->VoicePar[nvoice].Pfilterbypass; @@ -501,30 +507,32 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, //Compute the Voice's modulator volume (incl. damping) float fmvoldamp = powf(440.0f / getvoicebasefreq(nvoice), - pars->VoicePar[nvoice].PFMVolumeDamp / 64.0f - - 1.0f); + pars->VoicePar[nvoice].PFMVolumeDamp / 64.0f + - 1.0f); switch(NoteVoicePar[nvoice].FMEnabled) { - case PHASE_MOD: - fmvoldamp = - powf(440.0f / getvoicebasefreq( - nvoice), pars->VoicePar[nvoice].PFMVolumeDamp / 64.0f); - NoteVoicePar[nvoice].FMVolume = - (expf(pars->VoicePar[nvoice].PFMVolume / 127.0f - * FM_AMP_MULTIPLIER) - 1.0f) * fmvoldamp * 4.0f; - break; - case FREQ_MOD: - NoteVoicePar[nvoice].FMVolume = - (expf(pars->VoicePar[nvoice].PFMVolume / 127.0f - * FM_AMP_MULTIPLIER) - 1.0f) * fmvoldamp * 4.0f; - break; - // case PITCH_MOD:NoteVoicePar[nvoice].FMVolume=(pars->VoicePar[nvoice].PFMVolume/127.0f*8.0f)*fmvoldamp;//??????????? - // break; - default: - if(fmvoldamp > 1.0f) - fmvoldamp = 1.0f; - NoteVoicePar[nvoice].FMVolume = pars->VoicePar[nvoice].PFMVolume - / 127.0f * fmvoldamp; + case PHASE_MOD: + fmvoldamp = + powf(440.0f / getvoicebasefreq( + nvoice), pars->VoicePar[nvoice].PFMVolumeDamp + / 64.0f); + NoteVoicePar[nvoice].FMVolume = + (expf(pars->VoicePar[nvoice].PFMVolume / 127.0f + * FM_AMP_MULTIPLIER) - 1.0f) * fmvoldamp * 4.0f; + break; + case FREQ_MOD: + NoteVoicePar[nvoice].FMVolume = + (expf(pars->VoicePar[nvoice].PFMVolume / 127.0f + * FM_AMP_MULTIPLIER) - 1.0f) * fmvoldamp * 4.0f; + break; + // case PITCH_MOD:NoteVoicePar[nvoice].FMVolume=(pars->VoicePar[nvoice].PFMVolume/127.0f*8.0f)*fmvoldamp;//??????????? + // break; + default: + if(fmvoldamp > 1.0f) + fmvoldamp = 1.0f; + NoteVoicePar[nvoice].FMVolume = + pars->VoicePar[nvoice].PFMVolume + / 127.0f * fmvoldamp; } //Voice's modulator velocity sensing @@ -534,7 +542,7 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, NoteVoicePar[nvoice].DelayTicks = (int)((expf(pars->VoicePar[nvoice].PDelay / 127.0f - * logf(50.0f)) + * logf(50.0f)) - 1.0f) / SOUND_BUFFER_SIZE / 10.0f * SAMPLE_RATE); } @@ -547,7 +555,8 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, NoteGlobalPar.Volume = 4.0f * powf(0.1f, 3.0f - * (1.0f - partparams->GlobalPar.PVolume / 96.0f)) //-60 dB .. 0 dB + * (1.0f - partparams->GlobalPar.PVolume + / 96.0f)) //-60 dB .. 0 dB * VelF( velocity, partparams->GlobalPar. @@ -573,10 +582,11 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, NoteVoicePar[nvoice].noisetype = partparams->VoicePar[nvoice].Type; /* Voice Amplitude Parameters Init */ - NoteVoicePar[nvoice].Volume = - powf(0.1f, 3.0f * (1.0f - partparams->VoicePar[nvoice].PVolume / 127.0f)) // -60 dB .. 0 dB + NoteVoicePar[nvoice].Volume = + powf(0.1f, 3.0f + * (1.0f - partparams->VoicePar[nvoice].PVolume / 127.0f)) // -60 dB .. 0 dB * VelF(velocity, - partparams->VoicePar[nvoice].PAmpVelocityScaleFunction);//velocity + partparams->VoicePar[nvoice].PAmpVelocityScaleFunction); //velocity if(partparams->VoicePar[nvoice].PVolumeminus != 0) NoteVoicePar[nvoice].Volume = -NoteVoicePar[nvoice].Volume; @@ -617,7 +627,7 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, partparams->VoicePar[vc].FMSmp->newrandseed(prng()); for(int i = 0; i < OSCIL_SMP_EXTRA_SAMPLES; ++i) - NoteVoicePar[nvoice].FMSmp[OSCIL_SIZE + i] = + NoteVoicePar[nvoice].FMSmp[OSCIL_SIZE + i] = NoteVoicePar[nvoice].FMSmp[i]; } @@ -628,7 +638,6 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, && (NoteVoicePar[nvoice].FMAmpEnvelope != NULL)) FMnewamplitude[nvoice] *= NoteVoicePar[nvoice].FMAmpEnvelope->envout_dB(); - } for(int nvoice = 0; nvoice < NUM_VOICES; ++nvoice) { @@ -637,7 +646,6 @@ void ADnote::legatonote(float freq, float velocity, int portamento_, for(unsigned i = nvoice + 1; i < NUM_VOICES; ++i) if((NoteVoicePar[i].FMVoice == nvoice) && (tmp[i] == 0)) tmp[i] = 1; - } } @@ -730,8 +738,8 @@ void ADnote::initparameters() vce.noisetype = param.Type; /* Voice Amplitude Parameters Init */ - vce.Volume = powf(0.1f, 3.0f * (1.0f - param.PVolume / 127.0f))// -60dB..0dB - * VelF(velocity, param.PAmpVelocityScaleFunction); + vce.Volume = powf(0.1f, 3.0f * (1.0f - param.PVolume / 127.0f)) // -60dB..0dB + * VelF(velocity, param.PAmpVelocityScaleFunction); if(param.PVolumeminus) vce.Volume = -vce.Volume; @@ -797,8 +805,9 @@ void ADnote::initparameters() for(int k = 0; k < unison_size[nvoice]; ++k) oscposhiFM[nvoice][k] = (oscposhi[nvoice][k] - + partparams->VoicePar[vc].FMSmp->get(vce.FMSmp, tmp)) - % OSCIL_SIZE; + + partparams->VoicePar[vc].FMSmp->get( + vce.FMSmp, tmp)) + % OSCIL_SIZE; for(int i = 0; i < OSCIL_SMP_EXTRA_SAMPLES; ++i) vce.FMSmp[OSCIL_SIZE + i] = vce.FMSmp[i]; @@ -817,7 +826,8 @@ void ADnote::initparameters() FMnewamplitude[nvoice] = vce.FMVolume * ctl->fmamp.relamp; if(param.PFMAmpEnvelopeEnabled != 0) { - vce.FMAmpEnvelope = new Envelope(param.FMAmpEnvelope, basefreq); + vce.FMAmpEnvelope = new Envelope(param.FMAmpEnvelope, + basefreq); FMnewamplitude[nvoice] *= vce.FMAmpEnvelope->envout_dB(); } } @@ -832,7 +842,8 @@ void ADnote::initparameters() } if(NoteVoicePar[nvoice].VoiceOut) - memset(NoteVoicePar[nvoice].VoiceOut, 0, SOUND_BUFFER_SIZE * sizeof(float)); + memset(NoteVoicePar[nvoice].VoiceOut, 0, SOUND_BUFFER_SIZE + * sizeof(float)); } } @@ -910,19 +921,20 @@ void ADnote::setfreqFM(int nvoice, float in_freq) float ADnote::getvoicebasefreq(int nvoice) const { float detune = NoteVoicePar[nvoice].Detune / 100.0f - + NoteVoicePar[nvoice].FineDetune / 100.0f - * ctl->bandwidth.relbw * bandwidthDetuneMultiplier - + NoteGlobalPar.Detune / 100.0f; + + NoteVoicePar[nvoice].FineDetune / 100.0f + * ctl->bandwidth.relbw * bandwidthDetuneMultiplier + + NoteGlobalPar.Detune / 100.0f; if(NoteVoicePar[nvoice].fixedfreq == 0) - return this->basefreq * powf(2, detune / 12.0f); + return this->basefreq *powf(2, detune / 12.0f); else { //the fixed freq is enabled float fixedfreq = 440.0f; - int fixedfreqET = NoteVoicePar[nvoice].fixedfreqET; + int fixedfreqET = NoteVoicePar[nvoice].fixedfreqET; if(fixedfreqET != 0) { //if the frequency varies according the keyboard note float tmp = (midinote - - 69.0f) / 12.0f * (powf(2.0f, (fixedfreqET - 1) / 63.0f) - 1.0f); + - 69.0f) / 12.0f + * (powf(2.0f, (fixedfreqET - 1) / 63.0f) - 1.0f); if(fixedfreqET <= 64) fixedfreq *= powf(2.0f, tmp); else @@ -946,12 +958,12 @@ float ADnote::getFMvoicebasefreq(int nvoice) const */ void ADnote::computecurrentparameters() { - int nvoice; + int nvoice; float voicefreq, voicepitch, filterpitch, filterfreq, FMfreq, - FMrelativepitch, globalpitch, globalfilterpitch; + FMrelativepitch, globalpitch, globalfilterpitch; globalpitch = 0.01f * (NoteGlobalPar.FreqEnvelope->envout() - + NoteGlobalPar.FreqLfo->lfoout() - * ctl->modwheel.relmod); + + NoteGlobalPar.FreqLfo->lfoout() + * ctl->modwheel.relmod); globaloldamplitude = globalnewamplitude; globalnewamplitude = NoteGlobalPar.Volume * NoteGlobalPar.AmpEnvelope->envout_dB() @@ -962,7 +974,7 @@ void ADnote::computecurrentparameters() + NoteGlobalPar.FilterCenterPitch; float tmpfilterfreq = globalfilterpitch + ctl->filtercutoff.relfreq - + NoteGlobalPar.FilterFreqTracking; + + NoteGlobalPar.FilterFreqTracking; tmpfilterfreq = Filter::getrealfreq(tmpfilterfreq); @@ -977,7 +989,6 @@ void ADnote::computecurrentparameters() portamentofreqrap = ctl->portamento.freqrap; if(ctl->portamento.used == 0) //the portamento has finished portamento = 0; //this note is no longer "portamented" - } //compute parameters for all voices @@ -1034,8 +1045,8 @@ void ADnote::computecurrentparameters() if(NoteVoicePar[nvoice].FreqEnvelope != NULL) voicepitch += NoteVoicePar[nvoice].FreqEnvelope->envout() / 100.0f; - voicefreq = getvoicebasefreq(nvoice) - * powf(2, (voicepitch + globalpitch) / 12.0f); //Hz frequency + voicefreq = getvoicebasefreq(nvoice) + * powf(2, (voicepitch + globalpitch) / 12.0f); //Hz frequency voicefreq *= ctl->pitchwheel.relfreq; //change the frequency by the controller setfreq(nvoice, voicefreq * portamentofreqrap); @@ -1049,7 +1060,7 @@ void ADnote::computecurrentparameters() NoteVoicePar[nvoice].FMFreqEnvelope->envout() / 100; FMfreq = powf(2.0f, FMrelativepitch - / 12.0f) * voicefreq * portamentofreqrap; + / 12.0f) * voicefreq * portamentofreqrap; setfreqFM(nvoice, FMfreq); FMoldamplitude[nvoice] = FMnewamplitude[nvoice]; @@ -1094,13 +1105,13 @@ inline void ADnote::fadein(float *smps) const */ inline void ADnote::ComputeVoiceOscillator_LinearInterpolation(int nvoice) { - int i, poshi; + int i, poshi; float poslo; for(int k = 0; k < unison_size[nvoice]; ++k) { poshi = oscposhi[nvoice][k]; poslo = oscposlo[nvoice][k]; - int freqhi = oscfreqhi[nvoice][k]; + int freqhi = oscfreqhi[nvoice][k]; float freqlo = oscfreqlo[nvoice][k]; float *smps = NoteVoicePar[nvoice].OscilSmp; float *tw = tmpwave_unison[k]; @@ -1161,7 +1172,7 @@ inline void ADnote::ComputeVoiceOscillator_CubicInterpolation(int nvoice){ */ inline void ADnote::ComputeVoiceOscillatorMorph(int nvoice) { - int i; + int i; float amp; ComputeVoiceOscillator_LinearInterpolation(nvoice); if(FMnewamplitude[nvoice] > 1.0f) @@ -1175,28 +1186,29 @@ inline void ADnote::ComputeVoiceOscillatorMorph(int nvoice) for(int k = 0; k < unison_size[nvoice]; ++k) { float *tw = tmpwave_unison[k]; for(i = 0; i < SOUND_BUFFER_SIZE; ++i) { - amp = INTERPOLATE_AMPLITUDE(FMoldamplitude[nvoice], - FMnewamplitude[nvoice], - i, - SOUND_BUFFER_SIZE); + amp = INTERPOLATE_AMPLITUDE(FMoldamplitude[nvoice], + FMnewamplitude[nvoice], + i, + SOUND_BUFFER_SIZE); tw[i] = tw[i] - * (1.0f - amp) + amp * NoteVoicePar[FMVoice].VoiceOut[i]; + * (1.0f + - amp) + amp * NoteVoicePar[FMVoice].VoiceOut[i]; } } } - else { + else for(int k = 0; k < unison_size[nvoice]; ++k) { - int poshiFM = oscposhiFM[nvoice][k]; + int poshiFM = oscposhiFM[nvoice][k]; float posloFM = oscposloFM[nvoice][k]; - int freqhiFM = oscfreqhiFM[nvoice][k]; + int freqhiFM = oscfreqhiFM[nvoice][k]; float freqloFM = oscfreqloFM[nvoice][k]; float *tw = tmpwave_unison[k]; for(i = 0; i < SOUND_BUFFER_SIZE; ++i) { - amp = INTERPOLATE_AMPLITUDE(FMoldamplitude[nvoice], - FMnewamplitude[nvoice], - i, - SOUND_BUFFER_SIZE); + amp = INTERPOLATE_AMPLITUDE(FMoldamplitude[nvoice], + FMnewamplitude[nvoice], + i, + SOUND_BUFFER_SIZE); tw[i] = tw[i] * (1.0f - amp) + amp * (NoteVoicePar[nvoice].FMSmp[poshiFM] * (1 - posloFM) + NoteVoicePar[nvoice].FMSmp[poshiFM + 1] * posloFM); @@ -1211,7 +1223,6 @@ inline void ADnote::ComputeVoiceOscillatorMorph(int nvoice) oscposhiFM[nvoice][k] = poshiFM; oscposloFM[nvoice][k] = posloFM; } - } } /* @@ -1219,14 +1230,14 @@ inline void ADnote::ComputeVoiceOscillatorMorph(int nvoice) */ inline void ADnote::ComputeVoiceOscillatorRingModulation(int nvoice) { - int i; + int i; float amp; ComputeVoiceOscillator_LinearInterpolation(nvoice); if(FMnewamplitude[nvoice] > 1.0f) FMnewamplitude[nvoice] = 1.0f; if(FMoldamplitude[nvoice] > 1.0f) FMoldamplitude[nvoice] = 1.0f; - if(NoteVoicePar[nvoice].FMVoice >= 0) { + if(NoteVoicePar[nvoice].FMVoice >= 0) // if I use VoiceOut[] as modullator for(int k = 0; k < unison_size[nvoice]; ++k) { float *tw = tmpwave_unison[k]; @@ -1239,20 +1250,19 @@ inline void ADnote::ComputeVoiceOscillatorRingModulation(int nvoice) tw[i] *= (1.0f - amp) + amp * NoteVoicePar[FMVoice].VoiceOut[i]; } } - } - else { + else for(int k = 0; k < unison_size[nvoice]; ++k) { - int poshiFM = oscposhiFM[nvoice][k]; + int poshiFM = oscposhiFM[nvoice][k]; float posloFM = oscposloFM[nvoice][k]; - int freqhiFM = oscfreqhiFM[nvoice][k]; + int freqhiFM = oscfreqhiFM[nvoice][k]; float freqloFM = oscfreqloFM[nvoice][k]; float *tw = tmpwave_unison[k]; for(i = 0; i < SOUND_BUFFER_SIZE; ++i) { - amp = INTERPOLATE_AMPLITUDE(FMoldamplitude[nvoice], - FMnewamplitude[nvoice], - i, - SOUND_BUFFER_SIZE); + amp = INTERPOLATE_AMPLITUDE(FMoldamplitude[nvoice], + FMnewamplitude[nvoice], + i, + SOUND_BUFFER_SIZE); tw[i] *= (NoteVoicePar[nvoice].FMSmp[poshiFM] * (1.0f - posloFM) + NoteVoicePar[nvoice].FMSmp[poshiFM + 1] * posloFM) * amp @@ -1268,7 +1278,6 @@ inline void ADnote::ComputeVoiceOscillatorRingModulation(int nvoice) oscposhiFM[nvoice][k] = poshiFM; oscposloFM[nvoice][k] = posloFM; } - } } @@ -1279,24 +1288,23 @@ inline void ADnote::ComputeVoiceOscillatorRingModulation(int nvoice) inline void ADnote::ComputeVoiceOscillatorFrequencyModulation(int nvoice, int FMmode) { - int carposhi = 0; - int i, FMmodfreqhi = 0; + int carposhi = 0; + int i, FMmodfreqhi = 0; float FMmodfreqlo = 0, carposlo = 0; - if(NoteVoicePar[nvoice].FMVoice >= 0) { + if(NoteVoicePar[nvoice].FMVoice >= 0) //if I use VoiceOut[] as modulator for(int k = 0; k < unison_size[nvoice]; ++k) { float *tw = tmpwave_unison[k]; memcpy(tw, NoteVoicePar[NoteVoicePar[nvoice].FMVoice].VoiceOut, - SOUND_BUFFER_SIZE * sizeof(float)); + SOUND_BUFFER_SIZE * sizeof(float)); } - } - else { + else //Compute the modulator and store it in tmpwave_unison[][] for(int k = 0; k < unison_size[nvoice]; ++k) { - int poshiFM = oscposhiFM[nvoice][k]; + int poshiFM = oscposhiFM[nvoice][k]; float posloFM = oscposloFM[nvoice][k]; - int freqhiFM = oscfreqhiFM[nvoice][k]; + int freqhiFM = oscfreqhiFM[nvoice][k]; float freqloFM = oscfreqloFM[nvoice][k]; float *tw = tmpwave_unison[k]; @@ -1315,10 +1323,9 @@ inline void ADnote::ComputeVoiceOscillatorFrequencyModulation(int nvoice, oscposhiFM[nvoice][k] = poshiFM; oscposloFM[nvoice][k] = posloFM; } - } // Amplitude interpolation if(ABOVE_AMPLITUDE_THRESHOLD(FMoldamplitude[nvoice], - FMnewamplitude[nvoice])) { + FMnewamplitude[nvoice])) for(int k = 0; k < unison_size[nvoice]; ++k) { float *tw = tmpwave_unison[k]; for(i = 0; i < SOUND_BUFFER_SIZE; ++i) @@ -1326,22 +1333,19 @@ inline void ADnote::ComputeVoiceOscillatorFrequencyModulation(int nvoice, FMnewamplitude[nvoice], i, SOUND_BUFFER_SIZE); - } - } - else { + else for(int k = 0; k < unison_size[nvoice]; ++k) { float *tw = tmpwave_unison[k]; for(i = 0; i < SOUND_BUFFER_SIZE; ++i) tw[i] *= FMnewamplitude[nvoice]; } - } //normalize: makes all sample-rates, oscil_sizes to produce same sound if(FMmode != 0) { //Frequency modulation float normalize = OSCIL_SIZE / 262144.0f * 44100.0f - / (float)SAMPLE_RATE; + / (float)SAMPLE_RATE; for(int k = 0; k < unison_size[nvoice]; ++k) { float *tw = tmpwave_unison[k]; float fmold = FMoldsmp[nvoice][k]; @@ -1364,10 +1368,10 @@ inline void ADnote::ComputeVoiceOscillatorFrequencyModulation(int nvoice, //do the modulation for(int k = 0; k < unison_size[nvoice]; ++k) { float *tw = tmpwave_unison[k]; - int poshi = oscposhi[nvoice][k]; - float poslo = oscposlo[nvoice][k]; - int freqhi = oscfreqhi[nvoice][k]; - float freqlo = oscfreqlo[nvoice][k]; + int poshi = oscposhi[nvoice][k]; + float poslo = oscposlo[nvoice][k]; + int freqhi = oscfreqhi[nvoice][k]; + float freqlo = oscfreqlo[nvoice][k]; for(i = 0; i < SOUND_BUFFER_SIZE; ++i) { F2I(tw[i], FMmodfreqhi); @@ -1385,10 +1389,10 @@ inline void ADnote::ComputeVoiceOscillatorFrequencyModulation(int nvoice, } carposhi &= (OSCIL_SIZE - 1); - tw[i] = NoteVoicePar[nvoice].OscilSmp[carposhi] - * (1.0f - carposlo) - + NoteVoicePar[nvoice].OscilSmp[carposhi - + 1] * carposlo; + tw[i] = NoteVoicePar[nvoice].OscilSmp[carposhi] + * (1.0f - carposlo) + + NoteVoicePar[nvoice].OscilSmp[carposhi + + 1] * carposlo; poslo += freqlo; if(poslo >= 1.0f) { @@ -1447,22 +1451,22 @@ int ADnote::noteout(float *outl, float *outr) continue; if(NoteVoicePar[nvoice].noisetype == 0) //voice mode=sound switch(NoteVoicePar[nvoice].FMEnabled) { - case MORPH: - ComputeVoiceOscillatorMorph(nvoice); - break; - case RING_MOD: - ComputeVoiceOscillatorRingModulation(nvoice); - break; - case PHASE_MOD: - ComputeVoiceOscillatorFrequencyModulation(nvoice, 0); - break; - case FREQ_MOD: - ComputeVoiceOscillatorFrequencyModulation(nvoice, 1); - break; - //case PITCH_MOD:ComputeVoiceOscillatorPitchModulation(nvoice);break; - default: - ComputeVoiceOscillator_LinearInterpolation(nvoice); - //if (config.cfg.Interpolation) ComputeVoiceOscillator_CubicInterpolation(nvoice); + case MORPH: + ComputeVoiceOscillatorMorph(nvoice); + break; + case RING_MOD: + ComputeVoiceOscillatorRingModulation(nvoice); + break; + case PHASE_MOD: + ComputeVoiceOscillatorFrequencyModulation(nvoice, 0); + break; + case FREQ_MOD: + ComputeVoiceOscillatorFrequencyModulation(nvoice, 1); + break; + //case PITCH_MOD:ComputeVoiceOscillatorPitchModulation(nvoice);break; + default: + ComputeVoiceOscillator_LinearInterpolation(nvoice); + //if (config.cfg.Interpolation) ComputeVoiceOscillator_CubicInterpolation(nvoice); } else ComputeVoiceNoise(nvoice); @@ -1476,11 +1480,11 @@ int ADnote::noteout(float *outl, float *outr) for(int k = 0; k < unison_size[nvoice]; ++k) { float *tw = tmpwave_unison[k]; if(stereo) { - float stereo_pos = 0; + float stereo_pos = 0; if(unison_size[nvoice] > 1) stereo_pos = k / (float)(unison_size[nvoice] - - 1) * 2.0f - 1.0f; + - 1) * 2.0f - 1.0f; float stereo_spread = unison_stereo_spread[nvoice] * 2.0f; //between 0 and 2.0f if(stereo_spread > 1.0f) { float stereo_pos_1 = (stereo_pos >= 0.0f) ? 1.0f : -1.0f; @@ -1518,7 +1522,6 @@ int ADnote::noteout(float *outl, float *outr) else for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) tmpwavel[i] += tw[i]; - } @@ -1572,7 +1575,7 @@ int ADnote::noteout(float *outl, float *outr) NoteVoicePar[nvoice].VoiceFilterR->filterout(&tmpwaver[0]); //check if the amplitude envelope is finished, if yes, the voice will be fadeout - if(NoteVoicePar[nvoice].AmpEnvelope != NULL) { + if(NoteVoicePar[nvoice].AmpEnvelope != NULL) if(NoteVoicePar[nvoice].AmpEnvelope->finished() != 0) { for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) tmpwavel[i] *= 1.0f - (float)i @@ -1582,8 +1585,7 @@ int ADnote::noteout(float *outl, float *outr) tmpwaver[i] *= 1.0f - (float)i / (float)SOUND_BUFFER_SIZE; } - //the voice is killed later - } + //the voice is killed later // Put the ADnote samples in VoiceOut (without appling Global volume, because I wish to use this voice as a modullator) @@ -1595,44 +1597,39 @@ int ADnote::noteout(float *outl, float *outr) else //mono for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) NoteVoicePar[nvoice].VoiceOut[i] = tmpwavel[i]; - } // Add the voice that do not bypass the filter to out if(NoteVoicePar[nvoice].filterbypass == 0) { //no bypass - if(stereo) { + if(stereo) for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { //stereo outl[i] += tmpwavel[i] * NoteVoicePar[nvoice].Volume * NoteVoicePar[nvoice].Panning * 2.0f; outr[i] += tmpwaver[i] * NoteVoicePar[nvoice].Volume * (1.0f - NoteVoicePar[nvoice].Panning) * 2.0f; } - } else - for(int i = 0; i < SOUND_BUFFER_SIZE; ++i)//mono + for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) //mono outl[i] += tmpwavel[i] * NoteVoicePar[nvoice].Volume; - } else { //bypass the filter - if(stereo) { + if(stereo) for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { //stereo bypassl[i] += tmpwavel[i] * NoteVoicePar[nvoice].Volume * NoteVoicePar[nvoice].Panning * 2.0f; bypassr[i] += tmpwaver[i] * NoteVoicePar[nvoice].Volume - * (1.0f - NoteVoicePar[nvoice].Panning) * 2.0f; + * (1.0f + - NoteVoicePar[nvoice].Panning) * 2.0f; } - } else for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) //mono bypassl[i] += tmpwavel[i] * NoteVoicePar[nvoice].Volume; - } // chech if there is necesary to proces the voice longer (if the Amplitude envelope isn't finished) if(NoteVoicePar[nvoice].AmpEnvelope != NULL) if(NoteVoicePar[nvoice].AmpEnvelope->finished() != 0) KillVoice(nvoice); - } @@ -1651,29 +1648,27 @@ int ADnote::noteout(float *outl, float *outr) outr[i] += bypassr[i]; } - if(ABOVE_AMPLITUDE_THRESHOLD(globaloldamplitude, globalnewamplitude)) { + if(ABOVE_AMPLITUDE_THRESHOLD(globaloldamplitude, globalnewamplitude)) // Amplitude Interpolation for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { float tmpvol = INTERPOLATE_AMPLITUDE(globaloldamplitude, - globalnewamplitude, - i, - SOUND_BUFFER_SIZE); + globalnewamplitude, + i, + SOUND_BUFFER_SIZE); outl[i] *= tmpvol * NoteGlobalPar.Panning; outr[i] *= tmpvol * (1.0f - NoteGlobalPar.Panning); } - } - else { + else for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { outl[i] *= globalnewamplitude * NoteGlobalPar.Panning; outr[i] *= globalnewamplitude * (1.0f - NoteGlobalPar.Panning); } - } //Apply the punch - if(NoteGlobalPar.Punch.Enabled != 0) { + if(NoteGlobalPar.Punch.Enabled != 0) for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { float punchamp = NoteGlobalPar.Punch.initialvalue - * NoteGlobalPar.Punch.t + 1.0f; + * NoteGlobalPar.Punch.t + 1.0f; outl[i] *= punchamp; outr[i] *= punchamp; NoteGlobalPar.Punch.t -= NoteGlobalPar.Punch.dt; @@ -1682,11 +1677,10 @@ int ADnote::noteout(float *outl, float *outr) break; } } - } // Apply legato-specific sound signal modifications - legato.apply(*this,outl,outr); + legato.apply(*this, outl, outr); // Check if the global amplitude is finished. @@ -1743,9 +1737,9 @@ void ADnote::Voice::releasekey() } template -static inline void nullify(T &t) {delete t; t=NULL;} +static inline void nullify(T &t) {delete t; t = NULL;} template -static inline void arrayNullify(T &t) {delete [] t; t=NULL;} +static inline void arrayNullify(T &t) {delete [] t; t = NULL;} void ADnote::Voice::kill() { @@ -1792,18 +1786,18 @@ void ADnote::Global::initparameters(const ADnoteGlobalParam ¶m, FreqEnvelope = new Envelope(param.FreqEnvelope, basefreq); FreqLfo = new LFO(param.FreqLfo, basefreq); - AmpEnvelope = new Envelope(param.AmpEnvelope, basefreq); - AmpLfo = new LFO(param.AmpLfo, basefreq); + AmpEnvelope = new Envelope(param.AmpEnvelope, basefreq); + AmpLfo = new LFO(param.AmpLfo, basefreq); Volume = 4.0f * powf(0.1f, 3.0f * (1.0f - param.PVolume / 96.0f)) //-60 dB .. 0 dB - * VelF(velocity, param.PAmpVelocityScaleFunction); //sensing + * VelF(velocity, param.PAmpVelocityScaleFunction); //sensing GlobalFilterL = Filter::generate(param.GlobalFilter); if(stereo) GlobalFilterR = Filter::generate(param.GlobalFilter); - FilterEnvelope = new Envelope(param.FilterEnvelope, basefreq); - FilterLfo = new LFO(param.FilterLfo, basefreq); + FilterEnvelope = new Envelope(param.FilterEnvelope, basefreq); + FilterLfo = new LFO(param.FilterLfo, basefreq); FilterQ = param.GlobalFilter->getq(); FilterFreqTracking = param.GlobalFilter->getfreqtracking(basefreq); } diff --git a/src/Synth/ADnote.h b/src/Synth/ADnote.h index 91518af3..4d08a01e 100644 --- a/src/Synth/ADnote.h +++ b/src/Synth/ADnote.h @@ -37,7 +37,7 @@ #define OSCIL_SMP_EXTRA_SAMPLES 5 /**The "additive" synthesizer*/ -class ADnote :public SynthNote +class ADnote:public SynthNote { public: /**Constructor. @@ -114,7 +114,7 @@ class ADnote :public SynthNote //GLOBALS ADnoteParameters *partparams; unsigned char stereo; //if the note is stereo (allows note Panning) - int midinote; + int midinote; float velocity, basefreq; ONOFFTYPE NoteEnabled; @@ -132,7 +132,7 @@ class ADnote :public SynthNote /****************************************** * FREQUENCY GLOBAL PARAMETERS * ******************************************/ - float Detune; //cents + float Detune; //cents Envelope *FreqEnvelope; LFO *FreqLfo; @@ -140,30 +140,30 @@ class ADnote :public SynthNote /******************************************** * AMPLITUDE GLOBAL PARAMETERS * ********************************************/ - float Volume; // [ 0 .. 1 ] + float Volume; // [ 0 .. 1 ] - float Panning; // [ 0 .. 1 ] + float Panning; // [ 0 .. 1 ] Envelope *AmpEnvelope; LFO *AmpLfo; struct { - int Enabled; + int Enabled; float initialvalue, dt, t; } Punch; /****************************************** * FILTER GLOBAL PARAMETERS * ******************************************/ - class Filter *GlobalFilterL, *GlobalFilterR; + class Filter *GlobalFilterL, *GlobalFilterR; - float FilterCenterPitch; //octaves - float FilterQ; - float FilterFreqTracking; + float FilterCenterPitch; //octaves + float FilterQ; + float FilterFreqTracking; Envelope *FilterEnvelope; - LFO *FilterLfo; + LFO *FilterLfo; } NoteGlobalPar; @@ -171,7 +171,7 @@ class ADnote :public SynthNote /***********************************************************/ /* VOICE PARAMETERS */ /***********************************************************/ - struct Voice{ + struct Voice { void releasekey(); void kill(); /* If the voice is enabled */ @@ -196,7 +196,7 @@ class ADnote :public SynthNote int fixedfreqET; //if the "fixed" frequency varies according to the note (ET) // cents = basefreq*VoiceDetune - float Detune, FineDetune; + float Detune, FineDetune; Envelope *FreqEnvelope; LFO *FreqLfo; @@ -207,8 +207,8 @@ class ADnote :public SynthNote ***************************/ /* Panning 0.0f=left, 0.5f - center, 1.0f = right */ - float Panning; - float Volume; // [-1.0f .. 1.0f] + float Panning; + float Volume; // [-1.0f .. 1.0f] Envelope *AmpEnvelope; LFO *AmpLfo; @@ -217,11 +217,11 @@ class ADnote :public SynthNote * FILTER PARAMETERS * *************************/ - class Filter *VoiceFilterL; - class Filter *VoiceFilterR; + class Filter *VoiceFilterL; + class Filter *VoiceFilterR; - float FilterCenterPitch; /* Filter center Pitch*/ - float FilterFreqTracking; + float FilterCenterPitch; /* Filter center Pitch*/ + float FilterFreqTracking; Envelope *FilterEnvelope; LFO *FilterLfo; @@ -233,7 +233,7 @@ class ADnote :public SynthNote FMTYPE FMEnabled; - int FMVoice; + int FMVoice; // Voice Output used by other voices if use this as modullator float *VoiceOut; @@ -241,8 +241,8 @@ class ADnote :public SynthNote /* Wave of the Voice */ float *FMSmp; - float FMVolume; - float FMDetune; //in cents + float FMVolume; + float FMDetune; //in cents Envelope *FMFreqEnvelope; Envelope *FMAmpEnvelope; @@ -293,17 +293,17 @@ class ADnote :public SynthNote //used to compute and interpolate the amplitudes of voices and modullators float oldamplitude[NUM_VOICES], - newamplitude[NUM_VOICES], - FMoldamplitude[NUM_VOICES], - FMnewamplitude[NUM_VOICES]; + newamplitude[NUM_VOICES], + FMoldamplitude[NUM_VOICES], + FMnewamplitude[NUM_VOICES]; //used by Frequency Modulation (for integration) float *FMoldsmp[NUM_VOICES]; //temporary buffer - float *tmpwavel; - float *tmpwaver; - int max_unison; + float *tmpwavel; + float *tmpwaver; + int max_unison; float **tmpwave_unison; //Filter bypass samples @@ -323,4 +323,3 @@ class ADnote :public SynthNote }; #endif - diff --git a/src/Synth/Envelope.cpp b/src/Synth/Envelope.cpp index 5f507fe4..79973364 100644 --- a/src/Synth/Envelope.cpp +++ b/src/Synth/Envelope.cpp @@ -27,7 +27,7 @@ Envelope::Envelope(EnvelopeParams *envpars, float basefreq) { int i; - envpoints = envpars->Penvpoints; + envpoints = envpars->Penvpoints; if(envpoints > MAX_ENVELOPE_POINTS) envpoints = MAX_ENVELOPE_POINTS; envsustain = (envpars->Penvsustain == 0) ? -1 : envpars->Penvsustain; @@ -56,35 +56,36 @@ Envelope::Envelope(EnvelopeParams *envpars, float basefreq) envdt[i] = 2.0f; //any value larger than 1 switch(mode) { - case 2: - envval[i] = (1.0f - envpars->Penvval[i] / 127.0f) * -40; - break; - case 3: - envval[i] = - (powf(2, 6.0f - * fabs(envpars->Penvval[i] - 64.0f) / 64.0f) - 1.0f) * 100.0f; - if(envpars->Penvval[i] < 64) - envval[i] = -envval[i]; - break; - case 4: - envval[i] = (envpars->Penvval[i] - 64.0f) / 64.0f * 6.0f; //6 octaves (filtru) - break; - case 5: - envval[i] = (envpars->Penvval[i] - 64.0f) / 64.0f * 10; - break; - default: - envval[i] = envpars->Penvval[i] / 127.0f; + case 2: + envval[i] = (1.0f - envpars->Penvval[i] / 127.0f) * -40; + break; + case 3: + envval[i] = + (powf(2, 6.0f + * fabs(envpars->Penvval[i] + - 64.0f) / 64.0f) - 1.0f) * 100.0f; + if(envpars->Penvval[i] < 64) + envval[i] = -envval[i]; + break; + case 4: + envval[i] = (envpars->Penvval[i] - 64.0f) / 64.0f * 6.0f; //6 octaves (filtru) + break; + case 5: + envval[i] = (envpars->Penvval[i] - 64.0f) / 64.0f * 10; + break; + default: + envval[i] = envpars->Penvval[i] / 127.0f; } } - envdt[0] = 1.0f; + envdt[0] = 1.0f; currentpoint = 1; //the envelope starts from 1 keyreleased = false; t = 0.0f; - envfinish = false; - inct = envdt[1]; - envoutval = 0.0f; + envfinish = false; + inct = envdt[1]; + envoutval = 0.0f; } Envelope::~Envelope() @@ -141,8 +142,8 @@ float Envelope::envout() if(inct >= 1.0f) out = envval[currentpoint]; else - out = envval[currentpoint - 1] + - (envval[currentpoint] - envval[currentpoint - 1]) * t; + out = envval[currentpoint - 1] + + (envval[currentpoint] - envval[currentpoint - 1]) * t; t += inct; if(t >= 1.0f) { @@ -172,12 +173,12 @@ float Envelope::envout_dB() float v2 = dB2rap(envval[1]); out = v1 + (v2 - v1) * t; - t += inct; + t += inct; if(t >= 1.0f) { t = 0.0f; inct = envdt[2]; currentpoint++; - out = v2; + out = v2; } if(out > 0.001f) @@ -195,4 +196,3 @@ bool Envelope::finished() const { return envfinish; } - diff --git a/src/Synth/Envelope.h b/src/Synth/Envelope.h index 6147ba0e..ee75e0a3 100644 --- a/src/Synth/Envelope.h +++ b/src/Synth/Envelope.h @@ -42,17 +42,17 @@ class Envelope * @return returns 1 if the envelope is finished*/ bool finished() const; private: - int envpoints; - int envsustain; //"-1" means disabled + int envpoints; + int envsustain; //"-1" means disabled float envdt[MAX_ENVELOPE_POINTS]; //millisecons float envval[MAX_ENVELOPE_POINTS]; // [0.0f .. 1.0f] float envstretch; - int linearenvelope; + int linearenvelope; - int currentpoint; //current envelope point (starts from 1) - int forcedrelase; - bool keyreleased; //if the key was released - bool envfinish; + int currentpoint; //current envelope point (starts from 1) + int forcedrelase; + bool keyreleased; //if the key was released + bool envfinish; float t; // the time from the last point float inct; // the time increment float envoutval; //used to do the forced release @@ -60,4 +60,3 @@ class Envelope #endif - diff --git a/src/Synth/LFO.cpp b/src/Synth/LFO.cpp index bfccfaa0..00b377c9 100644 --- a/src/Synth/LFO.cpp +++ b/src/Synth/LFO.cpp @@ -32,9 +32,9 @@ LFO::LFO(LFOParams *lfopars, float basefreq) if(lfopars->Pstretch == 0) lfopars->Pstretch = 1; float lfostretch = powf(basefreq / 440.0f, - (lfopars->Pstretch - 64.0f) / 63.0f); //max 2x/octave + (lfopars->Pstretch - 64.0f) / 63.0f); //max 2x/octave - float lfofreq = + float lfofreq = (powf(2, lfopars->Pfreq * 10.0f) - 1.0f) / 12.0f * lfostretch; incx = fabs(lfofreq) * (float)SOUND_BUFFER_SIZE / (float)SAMPLE_RATE; @@ -65,16 +65,16 @@ LFO::LFO(LFOParams *lfopars, float basefreq) lfofreqrnd = powf(lfopars->Pfreqrand / 127.0f, 2.0f) * 4.0f; switch(lfopars->fel) { - case 1: - lfointensity = lfopars->Pintensity / 127.0f; - break; - case 2: - lfointensity = lfopars->Pintensity / 127.0f * 4.0f; - break; //in octave - default: - lfointensity = powf(2, lfopars->Pintensity / 127.0f * 11.0f) - 1.0f; //in centi - x -= 0.25f; //chance the starting phase - break; + case 1: + lfointensity = lfopars->Pintensity / 127.0f; + break; + case 2: + lfointensity = lfopars->Pintensity / 127.0f * 4.0f; + break; //in octave + default: + lfointensity = powf(2, lfopars->Pintensity / 127.0f * 11.0f) - 1.0f; //in centi + x -= 0.25f; //chance the starting phase + break; } amp1 = (1 - lfornd) + lfornd * RND; @@ -97,35 +97,35 @@ float LFO::lfoout() { float out; switch(lfotype) { - case 1: //LFO_TRIANGLE - if((x >= 0.0f) && (x < 0.25f)) - out = 4.0f * x; - else - if((x > 0.25f) && (x < 0.75f)) - out = 2 - 4 * x; - else - out = 4.0f * x - 4.0f; - break; - case 2: //LFO_SQUARE - if(x < 0.5f) - out = -1; - else - out = 1; - break; - case 3: //LFO_RAMPUP - out = (x - 0.5f) * 2.0f; - break; - case 4: //LFO_RAMPDOWN - out = (0.5f - x) * 2.0f; - break; - case 5: //LFO_EXP_DOWN 1 - out = powf(0.05f, x) * 2.0f - 1.0f; - break; - case 6: //LFO_EXP_DOWN 2 - out = powf(0.001f, x) * 2.0f - 1.0f; - break; - default: - out = cosf(x * 2.0f * PI); //LFO_SINE + case 1: //LFO_TRIANGLE + if((x >= 0.0f) && (x < 0.25f)) + out = 4.0f * x; + else + if((x > 0.25f) && (x < 0.75f)) + out = 2 - 4 * x; + else + out = 4.0f * x - 4.0f; + break; + case 2: //LFO_SQUARE + if(x < 0.5f) + out = -1; + else + out = 1; + break; + case 3: //LFO_RAMPUP + out = (x - 0.5f) * 2.0f; + break; + case 4: //LFO_RAMPDOWN + out = (0.5f - x) * 2.0f; + break; + case 5: //LFO_EXP_DOWN 1 + out = powf(0.05f, x) * 2.0f - 1.0f; + break; + case 6: //LFO_EXP_DOWN 2 + out = powf(0.001f, x) * 2.0f - 1.0f; + break; + default: + out = cosf(x * 2.0f * PI); //LFO_SINE } @@ -181,4 +181,3 @@ void LFO::computenextincrnd() incrnd = nextincrnd; nextincrnd = powf(0.5f, lfofreqrnd) + RND * (powf(2.0f, lfofreqrnd) - 1.0f); } - diff --git a/src/Synth/LFO.h b/src/Synth/LFO.h index 150af76f..2b933a34 100644 --- a/src/Synth/LFO.h +++ b/src/Synth/LFO.h @@ -56,4 +56,3 @@ class LFO }; #endif - diff --git a/src/Synth/OscilGen.cpp b/src/Synth/OscilGen.cpp index 5503b8c7..33a9e36f 100644 --- a/src/Synth/OscilGen.cpp +++ b/src/Synth/OscilGen.cpp @@ -77,7 +77,7 @@ void normalize(fft_t *freqs) if(max < 1e-8) //data is all ~zero, do not amplify noise return; - for(int i=0; i < OSCIL_SIZE / 2; ++i) + for(int i = 0; i < OSCIL_SIZE / 2; ++i) freqs[i] /= max; } @@ -97,15 +97,15 @@ void rmsNormalize(fft_t *freqs) freqs[i] *= gain; } -#define DIFF(par) (old##par != P##par) +#define DIFF(par) (old ## par != P ## par) OscilGen::OscilGen(FFTwrapper *fft_, Resonance *res_):Presets() { assert(fft_); setpresettype("Poscilgen"); - fft = fft_; - res = res_; + fft = fft_; + res = res_; tmpsmps = new float[OSCIL_SIZE]; @@ -133,17 +133,17 @@ void OscilGen::defaults() oldbasefunc = 0; oldbasepar = 64; oldhmagtype = 0; - oldwaveshapingfunction = 0; - oldwaveshaping = 64; + oldwaveshapingfunction = 0; + oldwaveshaping = 64; oldbasefuncmodulation = 0; oldharmonicshift = 0; oldbasefuncmodulationpar1 = 0; oldbasefuncmodulationpar2 = 0; oldbasefuncmodulationpar3 = 0; - oldmodulation = 0; - oldmodulationpar1 = 0; - oldmodulationpar2 = 0; - oldmodulationpar3 = 0; + oldmodulation = 0; + oldmodulationpar1 = 0; + oldmodulationpar2 = 0; + oldmodulationpar3 = 0; for(int i = 0; i < MAX_AD_HARMONICS; ++i) { hmag[i] = 0.0f; @@ -166,27 +166,27 @@ void OscilGen::defaults() Pbasefuncmodulationpar2 = 64; Pbasefuncmodulationpar3 = 32; - Pmodulation = 0; - Pmodulationpar1 = 64; - Pmodulationpar2 = 64; - Pmodulationpar3 = 32; + Pmodulation = 0; + Pmodulationpar1 = 64; + Pmodulationpar2 = 64; + Pmodulationpar3 = 32; Pwaveshapingfunction = 0; - Pwaveshaping = 64; - Pfiltertype = 0; - Pfilterpar1 = 64; - Pfilterpar2 = 64; - Pfilterbeforews = 0; + Pwaveshaping = 64; + Pfiltertype = 0; + Pfilterpar1 = 64; + Pfilterpar2 = 64; + Pfilterbeforews = 0; Psatype = 0; Psapar = 64; Pamprandpower = 64; - Pamprandtype = 0; + Pamprandtype = 0; Pharmonicshift = 0; Pharmonicshiftfirst = 0; - Padaptiveharmonics = 0; + Padaptiveharmonics = 0; Padaptiveharmonicspower = 100; Padaptiveharmonicsbasefreq = 128; Padaptiveharmonicspar = 50; @@ -201,8 +201,8 @@ void OscilGen::defaults() void OscilGen::convert2sine() { - float mag[MAX_AD_HARMONICS], phase[MAX_AD_HARMONICS]; - float oscil[OSCIL_SIZE]; + float mag[MAX_AD_HARMONICS], phase[MAX_AD_HARMONICS]; + float oscil[OSCIL_SIZE]; fft_t *freqs = new fft_t[OSCIL_SIZE / 2]; get(oscil, -1.0f); @@ -225,7 +225,7 @@ void OscilGen::convert2sine() float newmag = mag[i]; float newphase = phase[i]; - Phmag[i] = (int) ((newmag) * 64.0f) + 64; + Phmag[i] = (int) ((newmag) * 64.0f) + 64; Phphase[i] = 64 - (int) (64.0f * newphase / PI); if(Phphase[i] > 127) @@ -243,38 +243,38 @@ void OscilGen::convert2sine() */ void OscilGen::getbasefunction(float *smps) { - int i; + int i; float par = (Pbasefuncpar + 0.5f) / 128.0f; if(Pbasefuncpar == 64) par = 0.5f; float basefuncmodulationpar1 = Pbasefuncmodulationpar1 / 127.0f, - basefuncmodulationpar2 = Pbasefuncmodulationpar2 / 127.0f, - basefuncmodulationpar3 = Pbasefuncmodulationpar3 / 127.0f; + basefuncmodulationpar2 = Pbasefuncmodulationpar2 / 127.0f, + basefuncmodulationpar3 = Pbasefuncmodulationpar3 / 127.0f; switch(Pbasefuncmodulation) { - case 1: - basefuncmodulationpar1 = - (powf(2, basefuncmodulationpar1 * 5.0f) - 1.0f) / 10.0f; - basefuncmodulationpar3 = - floor((powf(2, basefuncmodulationpar3 * 5.0f) - 1.0f)); - if(basefuncmodulationpar3 < 0.9999f) - basefuncmodulationpar3 = -1.0f; - break; - case 2: - basefuncmodulationpar1 = - (powf(2, basefuncmodulationpar1 * 5.0f) - 1.0f) / 10.0f; - basefuncmodulationpar3 = 1.0f - + floor((powf(2, basefuncmodulationpar3 - * 5.0f) - 1.0f)); - break; - case 3: - basefuncmodulationpar1 = - (powf(2, basefuncmodulationpar1 * 7.0f) - 1.0f) / 10.0f; - basefuncmodulationpar3 = 0.01f - + (powf(2, basefuncmodulationpar3 - * 16.0f) - 1.0f) / 10.0f; - break; + case 1: + basefuncmodulationpar1 = + (powf(2, basefuncmodulationpar1 * 5.0f) - 1.0f) / 10.0f; + basefuncmodulationpar3 = + floor((powf(2, basefuncmodulationpar3 * 5.0f) - 1.0f)); + if(basefuncmodulationpar3 < 0.9999f) + basefuncmodulationpar3 = -1.0f; + break; + case 2: + basefuncmodulationpar1 = + (powf(2, basefuncmodulationpar1 * 5.0f) - 1.0f) / 10.0f; + basefuncmodulationpar3 = 1.0f + + floor((powf(2, basefuncmodulationpar3 + * 5.0f) - 1.0f)); + break; + case 3: + basefuncmodulationpar1 = + (powf(2, basefuncmodulationpar1 * 7.0f) - 1.0f) / 10.0f; + basefuncmodulationpar3 = 0.01f + + (powf(2, basefuncmodulationpar3 + * 16.0f) - 1.0f) / 10.0f; + break; } base_func func = getBaseFunction(Pcurrentbasefunc); @@ -283,21 +283,25 @@ void OscilGen::getbasefunction(float *smps) float t = i * 1.0f / OSCIL_SIZE; switch(Pbasefuncmodulation) { - case 1: - t = t * basefuncmodulationpar3 + sinf( - (t - + basefuncmodulationpar2) * 2.0f * PI) * basefuncmodulationpar1;//rev - break; - case 2: - t = t + sinf( - (t * basefuncmodulationpar3 - + basefuncmodulationpar2) * 2.0f * PI) * basefuncmodulationpar1;//sine - break; - case 3: - t = t + powf((1.0f - cosf( - (t + basefuncmodulationpar2) * 2.0f * PI)) * 0.5f, - basefuncmodulationpar3) * basefuncmodulationpar1;//power - break; + case 1: + t = t * basefuncmodulationpar3 + sinf( + (t + + basefuncmodulationpar2) * 2.0f + * PI) * basefuncmodulationpar1; //rev + break; + case 2: + t = t + sinf( + (t * basefuncmodulationpar3 + + basefuncmodulationpar2) * 2.0f + * PI) * basefuncmodulationpar1; //sine + break; + case 3: + t = t + powf((1.0f - cosf( + (t + + basefuncmodulationpar2) * 2.0f + * PI)) * 0.5f, + basefuncmodulationpar3) * basefuncmodulationpar1; //power + break; } t = t - floor(t); @@ -318,12 +322,12 @@ void OscilGen::oscilfilter() if(Pfiltertype == 0) return; - const float par = 1.0f - Pfilterpar1 / 128.0f; - const float par2 = Pfilterpar2 / 127.0f; + const float par = 1.0f - Pfilterpar1 / 128.0f; + const float par2 = Pfilterpar2 / 127.0f; filter_func filter = getFilter(Pfiltertype); for(int i = 1; i < OSCIL_SIZE / 2; ++i) - oscilFFTfreqs[i] *= filter(i,par,par2); + oscilFFTfreqs[i] *= filter(i, par, par2); normalize(oscilFFTfreqs); } @@ -409,24 +413,26 @@ void OscilGen::modulation() float modulationpar1 = Pmodulationpar1 / 127.0f, - modulationpar2 = 0.5f - Pmodulationpar2 / 127.0f, - modulationpar3 = Pmodulationpar3 / 127.0f; + modulationpar2 = 0.5f - Pmodulationpar2 / 127.0f, + modulationpar3 = Pmodulationpar3 / 127.0f; switch(Pmodulation) { - case 1: - modulationpar1 = (powf(2, modulationpar1 * 7.0f) - 1.0f) / 100.0f; - modulationpar3 = floor((powf(2, modulationpar3 * 5.0f) - 1.0f)); - if(modulationpar3 < 0.9999f) - modulationpar3 = -1.0f; - break; - case 2: - modulationpar1 = (powf(2, modulationpar1 * 7.0f) - 1.0f) / 100.0f; - modulationpar3 = 1.0f + floor((powf(2, modulationpar3 * 5.0f) - 1.0f)); - break; - case 3: - modulationpar1 = (powf(2, modulationpar1 * 9.0f) - 1.0f) / 100.0f; - modulationpar3 = 0.01f + (powf(2, modulationpar3 * 16.0f) - 1.0f) / 10.0f; - break; + case 1: + modulationpar1 = (powf(2, modulationpar1 * 7.0f) - 1.0f) / 100.0f; + modulationpar3 = floor((powf(2, modulationpar3 * 5.0f) - 1.0f)); + if(modulationpar3 < 0.9999f) + modulationpar3 = -1.0f; + break; + case 2: + modulationpar1 = (powf(2, modulationpar1 * 7.0f) - 1.0f) / 100.0f; + modulationpar3 = 1.0f + + floor((powf(2, modulationpar3 * 5.0f) - 1.0f)); + break; + case 3: + modulationpar1 = (powf(2, modulationpar1 * 9.0f) - 1.0f) / 100.0f; + modulationpar3 = 0.01f + + (powf(2, modulationpar3 * 16.0f) - 1.0f) / 10.0f; + break; } clearDC(oscilFFTfreqs); //remove the DC @@ -436,8 +442,8 @@ void OscilGen::modulation() oscilFFTfreqs[OSCIL_SIZE / 2 - i] *= tmp; } fft->freqs2smps(oscilFFTfreqs, tmpsmps); - int extra_points = 2; - float *in = new float[OSCIL_SIZE + extra_points]; + int extra_points = 2; + float *in = new float[OSCIL_SIZE + extra_points]; //Normalize normalize(tmpsmps, OSCIL_SIZE); @@ -452,25 +458,25 @@ void OscilGen::modulation() float t = i * 1.0f / OSCIL_SIZE; switch(Pmodulation) { - case 1: - t = t * modulationpar3 - + sinf((t + modulationpar2) * 2.0f * PI) * modulationpar1; //rev - break; - case 2: - t = t - + sinf((t * modulationpar3 - + modulationpar2) * 2.0f * PI) * modulationpar1; //sine - break; - case 3: - t = t + powf((1.0f - cosf( - (t + modulationpar2) * 2.0f * PI)) * 0.5f, - modulationpar3) * modulationpar1; //power - break; + case 1: + t = t * modulationpar3 + + sinf((t + modulationpar2) * 2.0f * PI) * modulationpar1; //rev + break; + case 2: + t = t + + sinf((t * modulationpar3 + + modulationpar2) * 2.0f * PI) * modulationpar1; //sine + break; + case 3: + t = t + powf((1.0f - cosf( + (t + modulationpar2) * 2.0f * PI)) * 0.5f, + modulationpar3) * modulationpar1; //power + break; } t = (t - floor(t)) * OSCIL_SIZE; - int poshi = (int) t; + int poshi = (int) t; float poslo = t - floor(t); tmpsmps[i] = in[poshi] * (1.0f - poslo) + in[poshi + 1] * poslo; @@ -490,19 +496,19 @@ void OscilGen::spectrumadjust() return; float par = Psapar / 127.0f; switch(Psatype) { - case 1: - par = 1.0f - par * 2.0f; - if(par >= 0.0f) - par = powf(5.0f, par); - else - par = powf(8.0f, par); - break; - case 2: - par = powf(10.0f, (1.0f - par) * 3.0f) * 0.25f; - break; - case 3: - par = powf(10.0f, (1.0f - par) * 3.0f) * 0.25f; - break; + case 1: + par = 1.0f - par * 2.0f; + if(par >= 0.0f) + par = powf(5.0f, par); + else + par = powf(8.0f, par); + break; + case 2: + par = powf(10.0f, (1.0f - par) * 3.0f) * 0.25f; + break; + case 3: + par = powf(10.0f, (1.0f - par) * 3.0f) * 0.25f; + break; } @@ -513,18 +519,18 @@ void OscilGen::spectrumadjust() float phase = arg(oscilFFTfreqs, i); switch(Psatype) { - case 1: - mag = powf(mag, par); - break; - case 2: - if(mag < par) - mag = 0.0f; - break; - case 3: - mag /= par; - if(mag > 1.0f) - mag = 1.0f; - break; + case 1: + mag = powf(mag, par); + break; + case 2: + if(mag < par) + mag = 0.0f; + break; + case 3: + mag /= par; + if(mag > 1.0f) + mag = 1.0f; + break; } oscilFFTfreqs[i] = std::polar(mag, phase); } @@ -538,7 +544,7 @@ void OscilGen::shiftharmonics() int harmonicshift = -Pharmonicshift; fft_t h; - if(harmonicshift > 0) { + if(harmonicshift > 0) for(int i = OSCIL_SIZE / 2 - 2; i >= 0; i--) { int oldh = i - harmonicshift; if(oldh < 0) @@ -547,8 +553,7 @@ void OscilGen::shiftharmonics() h = oscilFFTfreqs[oldh + 1]; oscilFFTfreqs[i + 1] = h; } - } - else { + else for(int i = 0; i < OSCIL_SIZE / 2 - 1; ++i) { int oldh = i + abs(harmonicshift); if(oldh >= (OSCIL_SIZE / 2 - 1)) @@ -561,7 +566,6 @@ void OscilGen::shiftharmonics() oscilFFTfreqs[i + 1] = h; } - } clearDC(oscilFFTfreqs); } @@ -582,21 +586,21 @@ void OscilGen::prepare() for(int i = 0; i < MAX_AD_HARMONICS; ++i) { const float hmagnew = 1.0f - fabs(Phmag[i] / 64.0f - 1.0f); switch(Phmagtype) { - case 1: - hmag[i] = expf(hmagnew * logf(0.01f)); - break; - case 2: - hmag[i] = expf(hmagnew * logf(0.001f)); - break; - case 3: - hmag[i] = expf(hmagnew * logf(0.0001f)); - break; - case 4: - hmag[i] = expf(hmagnew * logf(0.00001f)); - break; - default: - hmag[i] = 1.0f - hmagnew; - break; + case 1: + hmag[i] = expf(hmagnew * logf(0.01f)); + break; + case 2: + hmag[i] = expf(hmagnew * logf(0.001f)); + break; + case 3: + hmag[i] = expf(hmagnew * logf(0.0001f)); + break; + case 4: + hmag[i] = expf(hmagnew * logf(0.00001f)); + break; + default: + hmag[i] = 1.0f - hmagnew; + break; } if(Phmag[i] < 64) @@ -610,13 +614,16 @@ void OscilGen::prepare() clearAll(oscilFFTfreqs); - if(Pcurrentbasefunc == 0) { //the sine case + if(Pcurrentbasefunc == 0) //the sine case for(int i = 0; i < MAX_AD_HARMONICS; ++i) { - oscilFFTfreqs[i + 1].real() = -hmag[i] * sinf(hphase[i] * (i + 1)) / 2.0f; - oscilFFTfreqs[i + 1].imag() = hmag[i] * cosf(hphase[i] * (i + 1)) / 2.0f; + oscilFFTfreqs[i + + 1].real() = -hmag[i] + * sinf(hphase[i] * (i + 1)) / 2.0f; + oscilFFTfreqs[i + + 1].imag() = hmag[i] + * cosf(hphase[i] * (i + 1)) / 2.0f; } - } - else { + else for(int j = 0; j < MAX_AD_HARMONICS; ++j) { if(Phmag[j] == 64) continue; @@ -624,10 +631,11 @@ void OscilGen::prepare() int k = i * (j + 1); if(k >= OSCIL_SIZE / 2) break; - oscilFFTfreqs[k] += basefuncFFTfreqs[i] * std::polar(hmag[j], hphase[j] * k); + oscilFFTfreqs[k] += basefuncFFTfreqs[i] * std::polar( + hmag[j], + hphase[j] * k); } } - } if(Pharmonicshiftfirst != 0) shiftharmonics(); @@ -651,7 +659,7 @@ void OscilGen::prepare() oldhmagtype = Phmagtype; oldharmonicshift = Pharmonicshift + Pharmonicshiftfirst * 256; - oscilprepared = 1; + oscilprepared = 1; } void OscilGen::adaptiveharmonic(fft_t *f, float freq) @@ -671,7 +679,7 @@ void OscilGen::adaptiveharmonic(fft_t *f, float freq) float basefreq = 30.0f * powf(10.0f, Padaptiveharmonicsbasefreq / 128.0f); float power = (Padaptiveharmonicspower + 1.0f) / 101.0f; - float rap = freq / basefreq; + float rap = freq / basefreq; rap = powf(rap, power); @@ -683,7 +691,7 @@ void OscilGen::adaptiveharmonic(fft_t *f, float freq) for(int i = 0; i < OSCIL_SIZE / 2 - 2; ++i) { float h = i * rap; - int high = (int)(i * rap); + int high = (int)(i * rap); float low = fmod(h, 1.0f); if(high >= (OSCIL_SIZE / 2 - 2)) @@ -696,8 +704,10 @@ void OscilGen::adaptiveharmonic(fft_t *f, float freq) f[high + 1].imag() += inf[i].imag() * low; } else { - hc = inf[high].real() * (1.0f - low) + inf[high + 1].real() * low; - hs = inf[high].imag() * (1.0f - low) + inf[high + 1].imag() * low; + hc = inf[high].real() + * (1.0f - low) + inf[high + 1].real() * low; + hs = inf[high].imag() + * (1.0f - low) + inf[high + 1].imag() * low; } if(fabs(hc) < 0.000001f) hc = 0.0f; @@ -729,7 +739,7 @@ void OscilGen::adaptiveharmonicpostprocess(fft_t *f, int size) for(int i = 0; i < size; ++i) { inf[i] = f[i] * double(par); - f[i] *= (1.0f - par); + f[i] *= (1.0f - par); } @@ -742,15 +752,13 @@ void OscilGen::adaptiveharmonicpostprocess(fft_t *f, int size) int nh = (Padaptiveharmonics - 3) / 2 + 2; int sub_vs_add = (Padaptiveharmonics - 3) % 2; if(sub_vs_add == 0) { - for(int i = 0; i < size; ++i) { + for(int i = 0; i < size; ++i) if(((i + 1) % nh) == 0) f[i] += inf[i]; - } } - else { + else for(int i = 0; i < size / nh - 1; ++i) f[(i + 1) * nh - 1] += inf[i]; - } } delete [] inf; @@ -786,12 +794,12 @@ bool OscilGen::needPrepare(void) //Check function modulation if(DIFF(basefuncmodulation) || DIFF(basefuncmodulationpar1) - || DIFF(basefuncmodulationpar2) || DIFF(basefuncmodulationpar3)) + || DIFF(basefuncmodulationpar2) || DIFF(basefuncmodulationpar3)) outdated = true; //Check overall modulation if(DIFF(modulation) || DIFF(modulationpar1) - || DIFF(modulationpar2) || DIFF(modulationpar3)) + || DIFF(modulationpar2) || DIFF(modulationpar3)) outdated = true; //Check harmonic shifts @@ -810,7 +818,8 @@ short int OscilGen::get(float *smps, float freqHz, int resonance) prepare(); int outpos = - (int)((RND * 2.0f - 1.0f) * (float) OSCIL_SIZE * (Prand - 64.0f) / 64.0f); + (int)((RND * 2.0f + - 1.0f) * (float) OSCIL_SIZE * (Prand - 64.0f) / 64.0f); outpos = (outpos + 2 * OSCIL_SIZE) % OSCIL_SIZE; @@ -837,17 +846,17 @@ short int OscilGen::get(float *smps, float freqHz, int resonance) nyquist = realnyquist; } - if(Padaptiveharmonics) { //do the antialiasing in the case of adaptive harmonics + if(Padaptiveharmonics) //do the antialiasing in the case of adaptive harmonics for(int i = nyquist; i < OSCIL_SIZE / 2; ++i) outoscilFFTfreqs[i] = fft_t(0.0f, 0.0f); - } // Randomness (each harmonic), the block type is computed // in ADnote by setting start position according to this setting if((Prand > 64) && (freqHz >= 0.0f) && (!ADvsPAD)) { const float rnd = PI * powf((Prand - 64.0f) / 64.0f, 2.0f); for(int i = 1; i < nyquist - 1; ++i) //to Nyquist only for AntiAliasing - outoscilFFTfreqs[i] *= std::polar(1.0f, (float)(rnd * i * RND)); + outoscilFFTfreqs[i] *= + std::polar(1.0f, (float)(rnd * i * RND)); } //Harmonic Amplitude Randomness @@ -857,20 +866,20 @@ short int OscilGen::get(float *smps, float freqHz, int resonance) float power = Pamprandpower / 127.0f; float normalize = 1.0f / (1.2f - power); switch(Pamprandtype) { - case 1: - power = power * 2.0f - 0.5f; - power = powf(15.0f, power); - for(int i = 1; i < nyquist - 1; ++i) - outoscilFFTfreqs[i] *= powf(RND, power) * normalize; - break; - case 2: - power = power * 2.0f - 0.5f; - power = powf(15.0f, power) * 2.0f; - float rndfreq = 2 * PI * RND; - for(int i = 1; i < nyquist - 1; ++i) - outoscilFFTfreqs[i] *= powf(fabs(sinf(i * rndfreq)), power) - * normalize; - break; + case 1: + power = power * 2.0f - 0.5f; + power = powf(15.0f, power); + for(int i = 1; i < nyquist - 1; ++i) + outoscilFFTfreqs[i] *= powf(RND, power) * normalize; + break; + case 2: + power = power * 2.0f - 0.5f; + power = powf(15.0f, power) * 2.0f; + float rndfreq = 2 * PI * RND; + for(int i = 1; i < nyquist - 1; ++i) + outoscilFFTfreqs[i] *= powf(fabs(sinf(i * rndfreq)), power) + * normalize; + break; } sprng(realrnd + 1); } @@ -918,7 +927,7 @@ void OscilGen::getspectrum(int n, float *spc, int what) if(what == 0) { for(int i = 0; i < n; ++i) outoscilFFTfreqs[i] = fft_t(spc[i], spc[i]); - memset(outoscilFFTfreqs+n, 0, (OSCIL_SIZE / 2 - n) * sizeof(fft_t)); + memset(outoscilFFTfreqs + n, 0, (OSCIL_SIZE / 2 - n) * sizeof(fft_t)); adaptiveharmonic(outoscilFFTfreqs, 0.0f); adaptiveharmonicpostprocess(outoscilFFTfreqs, n - 1); for(int i = 0; i < n; ++i) @@ -1022,63 +1031,63 @@ void OscilGen::getfromXML(XMLwrapper *xml) { Phmagtype = xml->getpar127("harmonic_mag_type", Phmagtype); - Pcurrentbasefunc = xml->getpar127("base_function", Pcurrentbasefunc); - Pbasefuncpar = xml->getpar127("base_function_par", Pbasefuncpar); + Pcurrentbasefunc = xml->getpar127("base_function", Pcurrentbasefunc); + Pbasefuncpar = xml->getpar127("base_function_par", Pbasefuncpar); Pbasefuncmodulation = xml->getpar127("base_function_modulation", Pbasefuncmodulation); - Pbasefuncmodulationpar1 = xml->getpar127("base_function_modulation_par1", - Pbasefuncmodulationpar1); - Pbasefuncmodulationpar2 = xml->getpar127("base_function_modulation_par2", - Pbasefuncmodulationpar2); - Pbasefuncmodulationpar3 = xml->getpar127("base_function_modulation_par3", - Pbasefuncmodulationpar3); - - Pmodulation = xml->getpar127("modulation", Pmodulation); - Pmodulationpar1 = xml->getpar127("modulation_par1", - Pmodulationpar1); - Pmodulationpar2 = xml->getpar127("modulation_par2", - Pmodulationpar2); - Pmodulationpar3 = xml->getpar127("modulation_par3", - Pmodulationpar3); - - Pwaveshaping = xml->getpar127("wave_shaping", Pwaveshaping); - Pwaveshapingfunction = xml->getpar127("wave_shaping_function", - Pwaveshapingfunction); - - Pfiltertype = xml->getpar127("filter_type", Pfiltertype); - Pfilterpar1 = xml->getpar127("filter_par1", Pfilterpar1); - Pfilterpar2 = xml->getpar127("filter_par2", Pfilterpar2); - Pfilterbeforews = xml->getpar127("filter_before_wave_shaping", - Pfilterbeforews); - - Psatype = xml->getpar127("spectrum_adjust_type", Psatype); - Psapar = xml->getpar127("spectrum_adjust_par", Psapar); - - Prand = xml->getpar127("rand", Prand); - Pamprandtype = xml->getpar127("amp_rand_type", Pamprandtype); - Pamprandpower = xml->getpar127("amp_rand_power", Pamprandpower); - - Pharmonicshift = xml->getpar("harmonic_shift", - Pharmonicshift, - -64, - 64); - Pharmonicshiftfirst = xml->getparbool("harmonic_shift_first", - Pharmonicshiftfirst); - - Padaptiveharmonics = xml->getpar("adaptive_harmonics", - Padaptiveharmonics, - 0, - 127); + Pbasefuncmodulationpar1 = xml->getpar127("base_function_modulation_par1", + Pbasefuncmodulationpar1); + Pbasefuncmodulationpar2 = xml->getpar127("base_function_modulation_par2", + Pbasefuncmodulationpar2); + Pbasefuncmodulationpar3 = xml->getpar127("base_function_modulation_par3", + Pbasefuncmodulationpar3); + + Pmodulation = xml->getpar127("modulation", Pmodulation); + Pmodulationpar1 = xml->getpar127("modulation_par1", + Pmodulationpar1); + Pmodulationpar2 = xml->getpar127("modulation_par2", + Pmodulationpar2); + Pmodulationpar3 = xml->getpar127("modulation_par3", + Pmodulationpar3); + + Pwaveshaping = xml->getpar127("wave_shaping", Pwaveshaping); + Pwaveshapingfunction = xml->getpar127("wave_shaping_function", + Pwaveshapingfunction); + + Pfiltertype = xml->getpar127("filter_type", Pfiltertype); + Pfilterpar1 = xml->getpar127("filter_par1", Pfilterpar1); + Pfilterpar2 = xml->getpar127("filter_par2", Pfilterpar2); + Pfilterbeforews = xml->getpar127("filter_before_wave_shaping", + Pfilterbeforews); + + Psatype = xml->getpar127("spectrum_adjust_type", Psatype); + Psapar = xml->getpar127("spectrum_adjust_par", Psapar); + + Prand = xml->getpar127("rand", Prand); + Pamprandtype = xml->getpar127("amp_rand_type", Pamprandtype); + Pamprandpower = xml->getpar127("amp_rand_power", Pamprandpower); + + Pharmonicshift = xml->getpar("harmonic_shift", + Pharmonicshift, + -64, + 64); + Pharmonicshiftfirst = xml->getparbool("harmonic_shift_first", + Pharmonicshiftfirst); + + Padaptiveharmonics = xml->getpar("adaptive_harmonics", + Padaptiveharmonics, + 0, + 127); Padaptiveharmonicsbasefreq = xml->getpar( "adaptive_harmonics_base_frequency", Padaptiveharmonicsbasefreq, 0, 255); - Padaptiveharmonicspower = xml->getpar("adaptive_harmonics_power", - Padaptiveharmonicspower, - 0, - 200); + Padaptiveharmonicspower = xml->getpar("adaptive_harmonics_power", + Padaptiveharmonicspower, + 0, + 200); if(xml->enterbranch("HARMONICS")) { @@ -1099,13 +1108,12 @@ void OscilGen::getfromXML(XMLwrapper *xml) if(xml->enterbranch("BASE_FUNCTION")) { - for(int i = 1; i < OSCIL_SIZE / 2; ++i) { + for(int i = 1; i < OSCIL_SIZE / 2; ++i) if(xml->enterbranch("BF_HARMONIC", i)) { basefuncFFTfreqs[i].real() = xml->getparreal("cos", 0.0f); basefuncFFTfreqs[i].imag() = xml->getparreal("sin", 0.0f); xml->exitbranch(); } - } xml->exitbranch(); clearDC(basefuncFFTfreqs); @@ -1115,7 +1123,7 @@ void OscilGen::getfromXML(XMLwrapper *xml) //Define basic functions -#define FUNC(b) float basefunc_##b(float x, float a) +#define FUNC(b) float basefunc_ ## b(float x, float a) FUNC(pulse) { @@ -1258,7 +1266,7 @@ FUNC(sqr) return -atanf(sinf(x * 2.0f * PI) * a); } -typedef float(*base_func)(float,float); +typedef float (*base_func)(float, float); base_func getBaseFunction(unsigned char func) { if(!func) @@ -1282,13 +1290,14 @@ base_func getBaseFunction(unsigned char func) basefunc_chirp, basefunc_absstretchsine, basefunc_chebyshev, - basefunc_sqr,}; + basefunc_sqr, + }; return functions[func]; } //And filters -#define FILTER(x) float osc_##x(unsigned int i, float par, float par2) +#define FILTER(x) float osc_ ## x(unsigned int i, float par, float par2) FILTER(lp) { float gain = powf(1.0f - par * par * par * 0.99f, i); @@ -1308,8 +1317,9 @@ FILTER(hp1b) { if(par < 0.2f) par = par * 0.25f + 0.15f; - float gain = 1.0f - powf(1.0f - par * par * 0.999f + 0.001f, i * 0.05f * i + 1.0f); - float tmp = powf(5.0f, par2 * 2.0f); + float gain = 1.0f - powf(1.0f - par * par * 0.999f + 0.001f, + i * 0.05f * i + 1.0f); + float tmp = powf(5.0f, par2 * 2.0f); return powf(gain, tmp); } @@ -1317,7 +1327,7 @@ FILTER(bp1) { float gain = i + 1 - powf(2, (1.0f - par) * 7.5f); gain = 1.0f / (1.0f + gain * gain / (i + 1.0f)); - float tmp = powf(5.0f, par2 * 2.0f); + float tmp = powf(5.0f, par2 * 2.0f); gain = powf(gain, tmp); if(gain < 1e-5) gain = 1e-5; @@ -1333,24 +1343,34 @@ FILTER(bs1) FILTER(lp2) { - return (i + 1 > powf(2, (1.0f - par) * 10) ? 0.0f : 1.0f) * par2 + (1.0f - par2); + return (i + 1 > + powf(2, (1.0f - par) * 10) ? 0.0f : 1.0f) * par2 + (1.0f - par2); } FILTER(hp2) { if(par == 1) return 1.0f; - return (i + 1 > powf(2, (1.0f - par) * 7) ? 1.0f : 0.0f) * par2 + (1.0f - par2); + return (i + 1 > + powf(2, (1.0f - par) * 7) ? 1.0f : 0.0f) * par2 + (1.0f - par2); } FILTER(bp2) { - return (fabs(powf(2, (1.0f - par) * 7) - i) > i / 2 + 1 ? 0.0f : 1.0f) * par2 + (1.0f - par2); + return (fabs(powf(2, + (1.0f + - par) + * 7) + - i) > i / 2 + 1 ? 0.0f : 1.0f) * par2 + (1.0f - par2); } FILTER(bs2) { - return (fabs(powf(2, (1.0f - par) * 7) - i) < i / 2 + 1 ? 0.0f : 1.0f) * par2 + (1.0f - par2); + return (fabs(powf(2, + (1.0f + - par) + * 7) + - i) < i / 2 + 1 ? 0.0f : 1.0f) * par2 + (1.0f - par2); } bool floatEq(float a, float b) @@ -1365,7 +1385,7 @@ FILTER(cos) tmp = powf(i / 32.0f, tmp) * 32.0f; if(floatEq(par2 * 127.0f, 64.0f)) tmp = i; - float gain = cosf(par * par * PI / 2.0f * tmp); + float gain = cosf(par * par * PI / 2.0f * tmp); gain *= gain; return gain; } @@ -1388,15 +1408,15 @@ FILTER(low_shelf) if(x < 0.0f) x = 0.0f; else - if(x > 1.0f) - x = 1.0f; - float tmp = powf(1.0f - par2, 2.0f); + if(x > 1.0f) + x = 1.0f; + float tmp = powf(1.0f - par2, 2.0f); return cosf(x * PI) * (1.0f - tmp) + 1.01f + tmp; } FILTER(s) { - unsigned int tmp = (int) (powf(2.0f, (1.0f - par) * 7.2f)); + unsigned int tmp = (int) (powf(2.0f, (1.0f - par) * 7.2f)); float gain = 1.0f; if(i == tmp) gain = powf(2.0f, par2 * par2 * 8.0f); @@ -1404,7 +1424,7 @@ FILTER(s) } #undef FILTER -typedef float(*filter_func)(unsigned int, float, float); +typedef float (*filter_func)(unsigned int, float, float); filter_func getFilter(unsigned char func) { if(!func) @@ -1425,7 +1445,7 @@ filter_func getFilter(unsigned char func) osc_cos, osc_sin, osc_low_shelf, - osc_s}; + osc_s + }; return functions[func]; } - diff --git a/src/Synth/OscilGen.h b/src/Synth/OscilGen.h index 15285dd2..483a3859 100644 --- a/src/Synth/OscilGen.h +++ b/src/Synth/OscilGen.h @@ -40,7 +40,7 @@ class OscilGen:public Presets /**do the antialiasing(cut off higher freqs.),apply randomness and do a IFFT*/ //returns where should I start getting samples, used in block type randomness - short get(float *smps, float freqHz, int resonance=0); + short get(float *smps, float freqHz, int resonance = 0); //if freqHz is smaller than 0, return the "un-randomized" sample for UI void getbasefunction(float *smps); @@ -79,7 +79,7 @@ class OscilGen:public Presets unsigned char Pbasefuncmodulation; //what modulation is applied to the basefunc unsigned char Pbasefuncmodulationpar1, Pbasefuncmodulationpar2, - Pbasefuncmodulationpar3;//the parameter of the base function modulation + Pbasefuncmodulationpar3; //the parameter of the base function modulation /*the Randomness: 64=no randomness @@ -159,18 +159,17 @@ class OscilGen:public Presets fft_t *basefuncFFTfreqs; //Base Function Frequencies fft_t *oscilFFTfreqs; //Oscillator Frequencies - this is different than the hamonics set-up by the user, it may contains time-domain data if the antialiasing is turned off - int oscilprepared; //1 if the oscil is prepared, 0 if it is not prepared and is need to call ::prepare() before ::get() + int oscilprepared; //1 if the oscil is prepared, 0 if it is not prepared and is need to call ::prepare() before ::get() Resonance *res; unsigned int randseed; }; -typedef float(*filter_func)(unsigned int, float, float); +typedef float (*filter_func)(unsigned int, float, float); filter_func getFilter(unsigned char func); -typedef float(*base_func)(float,float); +typedef float (*base_func)(float, float); base_func getBaseFunction(unsigned char func); #endif - diff --git a/src/Synth/PADnote.cpp b/src/Synth/PADnote.cpp index 5c4482df..071ce723 100644 --- a/src/Synth/PADnote.cpp +++ b/src/Synth/PADnote.cpp @@ -30,17 +30,21 @@ PADnote::PADnote(PADnoteParameters *parameters, int portamento_, int midinote, bool besilent) -:SynthNote(freq, velocity, portamento_, midinote, besilent) + :SynthNote(freq, velocity, portamento_, midinote, besilent) { pars = parameters; - ctl = ctl_; + ctl = ctl_; firsttime = true; setup(freq, velocity, portamento_, midinote); } -void PADnote::setup(float freq, float velocity,int portamento_, int midinote, bool legato) +void PADnote::setup(float freq, + float velocity, + int portamento_, + int midinote, + bool legato) { portamento = portamento_; this->velocity = velocity; @@ -55,7 +59,8 @@ void PADnote::setup(float freq, float velocity,int portamento_, int midinote, bo if(fixedfreqET != 0) { //if the frequency varies according the keyboard note float tmp = (midinote - - 69.0f) / 12.0f * (powf(2.0f, (fixedfreqET - 1) / 63.0f) - 1.0f); + - 69.0f) / 12.0f + * (powf(2.0f, (fixedfreqET - 1) / 63.0f) - 1.0f); if(fixedfreqET <= 64) basefreq *= powf(2.0f, tmp); else @@ -91,13 +96,13 @@ void PADnote::setup(float freq, float velocity,int portamento_, int midinote, bo size = 1; - if(!legato) {//not sure + if(!legato) { //not sure poshi_l = (int)(RND * (size - 1)); if(pars->PStereo != 0) poshi_r = (poshi_l + size / 2) % size; else poshi_r = poshi_l; - poslo = 0.0f; + poslo = 0.0f; } @@ -115,13 +120,14 @@ void PADnote::setup(float freq, float velocity,int portamento_, int midinote, bo if(!legato) { if(pars->PPunchStrength != 0) { - NoteGlobalPar.Punch.Enabled = 1; + NoteGlobalPar.Punch.Enabled = 1; NoteGlobalPar.Punch.t = 1.0f; //start from 1.0f and to 0.0f NoteGlobalPar.Punch.initialvalue = ((powf(10, 1.5f * pars->PPunchStrength / 127.0f) - 1.0f) * VelF(velocity, - pars->PPunchVelocitySensing)); - float time = powf(10, 3.0f * pars->PPunchTime / 127.0f) / 10000.0f; //0.1f .. 100 ms + pars->PPunchVelocitySensing)); + float time = + powf(10, 3.0f * pars->PPunchTime / 127.0f) / 10000.0f; //0.1f .. 100 ms float stretch = powf(440.0f / freq, pars->PPunchStretch / 64.0f); NoteGlobalPar.Punch.dt = 1.0f / (time * SAMPLE_RATE * stretch); } @@ -131,11 +137,12 @@ void PADnote::setup(float freq, float velocity,int portamento_, int midinote, bo NoteGlobalPar.FreqEnvelope = new Envelope(pars->FreqEnvelope, basefreq); NoteGlobalPar.FreqLfo = new LFO(pars->FreqLfo, basefreq); - NoteGlobalPar.AmpEnvelope = new Envelope(pars->AmpEnvelope, basefreq); - NoteGlobalPar.AmpLfo = new LFO(pars->AmpLfo, basefreq); + NoteGlobalPar.AmpEnvelope = new Envelope(pars->AmpEnvelope, basefreq); + NoteGlobalPar.AmpLfo = new LFO(pars->AmpLfo, basefreq); } - NoteGlobalPar.Volume = 4.0f * powf(0.1f, 3.0f * (1.0f - pars->PVolume / 96.0f)) //-60 dB .. 0 dB + NoteGlobalPar.Volume = 4.0f + * powf(0.1f, 3.0f * (1.0f - pars->PVolume / 96.0f)) //-60 dB .. 0 dB * VelF(velocity, pars->PAmpVelocityScaleFunction); //velocity sensing NoteGlobalPar.AmpEnvelope->envout_dB(); //discard the first envelope output @@ -145,12 +152,12 @@ void PADnote::setup(float freq, float velocity,int portamento_, int midinote, bo * NoteGlobalPar.AmpLfo->amplfoout(); if(!legato) { - NoteGlobalPar.GlobalFilterL = Filter::generate(pars->GlobalFilter); - NoteGlobalPar.GlobalFilterR = Filter::generate(pars->GlobalFilter); + NoteGlobalPar.GlobalFilterL = Filter::generate(pars->GlobalFilter); + NoteGlobalPar.GlobalFilterR = Filter::generate(pars->GlobalFilter); NoteGlobalPar.FilterEnvelope = new Envelope(pars->FilterEnvelope, - basefreq); - NoteGlobalPar.FilterLfo = new LFO(pars->FilterLfo, basefreq); + basefreq); + NoteGlobalPar.FilterLfo = new LFO(pars->FilterLfo, basefreq); } NoteGlobalPar.FilterQ = pars->GlobalFilter->getq(); NoteGlobalPar.FilterFreqTracking = pars->GlobalFilter->getfreqtracking( @@ -163,10 +170,10 @@ void PADnote::setup(float freq, float velocity,int portamento_, int midinote, bo } void PADnote::legatonote(float freq, - float velocity, - int portamento_, - int midinote, - bool externcall) + float velocity, + int portamento_, + int midinote, + bool externcall) { // Manage legato stuff if(legato.update(freq, velocity, portamento_, midinote, externcall)) @@ -215,8 +222,8 @@ void PADnote::computecurrentparameters() { float globalpitch, globalfilterpitch; globalpitch = 0.01f * (NoteGlobalPar.FreqEnvelope->envout() - + NoteGlobalPar.FreqLfo->lfoout() - * ctl->modwheel.relmod + NoteGlobalPar.Detune); + + NoteGlobalPar.FreqLfo->lfoout() + * ctl->modwheel.relmod + NoteGlobalPar.Detune); globaloldamplitude = globalnewamplitude; globalnewamplitude = NoteGlobalPar.Volume * NoteGlobalPar.AmpEnvelope->envout_dB() @@ -227,7 +234,7 @@ void PADnote::computecurrentparameters() + NoteGlobalPar.FilterCenterPitch; float tmpfilterfreq = globalfilterpitch + ctl->filtercutoff.relfreq - + NoteGlobalPar.FilterFreqTracking; + + NoteGlobalPar.FilterFreqTracking; tmpfilterfreq = Filter::getrealfreq(tmpfilterfreq); @@ -289,7 +296,7 @@ int PADnote::Compute_Cubic(float *outl, finished_ = true; return 1; } - int size = pars->sample[nsample].size; + int size = pars->sample[nsample].size; float xm1, x0, x1, x2, a, b, c; for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { poshi_l += freqhi; @@ -344,7 +351,7 @@ int PADnote::noteout(float *outl, float *outr) float freqrap = realfreq / smpfreq; - int freqhi = (int) (floor(freqrap)); + int freqhi = (int) (floor(freqrap)); float freqlo = freqrap - floor(freqrap); @@ -364,10 +371,10 @@ int PADnote::noteout(float *outl, float *outr) NoteGlobalPar.GlobalFilterR->filterout(outr); //Apply the punch - if(NoteGlobalPar.Punch.Enabled != 0) { + if(NoteGlobalPar.Punch.Enabled != 0) for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { float punchamp = NoteGlobalPar.Punch.initialvalue - * NoteGlobalPar.Punch.t + 1.0f; + * NoteGlobalPar.Punch.t + 1.0f; outl[i] *= punchamp; outr[i] *= punchamp; NoteGlobalPar.Punch.t -= NoteGlobalPar.Punch.dt; @@ -376,29 +383,26 @@ int PADnote::noteout(float *outl, float *outr) break; } } - } - if(ABOVE_AMPLITUDE_THRESHOLD(globaloldamplitude, globalnewamplitude)) { + if(ABOVE_AMPLITUDE_THRESHOLD(globaloldamplitude, globalnewamplitude)) // Amplitude Interpolation for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { float tmpvol = INTERPOLATE_AMPLITUDE(globaloldamplitude, - globalnewamplitude, - i, - SOUND_BUFFER_SIZE); + globalnewamplitude, + i, + SOUND_BUFFER_SIZE); outl[i] *= tmpvol * NoteGlobalPar.Panning; outr[i] *= tmpvol * (1.0f - NoteGlobalPar.Panning); } - } - else { + else for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { outl[i] *= globalnewamplitude * NoteGlobalPar.Panning; outr[i] *= globalnewamplitude * (1.0f - NoteGlobalPar.Panning); } - } // Apply legato-specific sound signal modifications - legato.apply(*this,outl,outr); + legato.apply(*this, outl, outr); // Check if the global amplitude is finished. // If it does, disable the note @@ -425,4 +429,3 @@ void PADnote::relasekey() NoteGlobalPar.FilterEnvelope->relasekey(); NoteGlobalPar.AmpEnvelope->relasekey(); } - diff --git a/src/Synth/PADnote.h b/src/Synth/PADnote.h index e8728bb9..0eb84465 100644 --- a/src/Synth/PADnote.h +++ b/src/Synth/PADnote.h @@ -30,7 +30,7 @@ #include "../Params/Controller.h" /**The "pad" synthesizer*/ -class PADnote :public SynthNote +class PADnote:public SynthNote { public: PADnote(PADnoteParameters *parameters, @@ -49,18 +49,18 @@ class PADnote :public SynthNote int finished() const; void relasekey(); private: - void setup(float freq, float velocity,int portamento_, - int midinote, bool legato=false); + void setup(float freq, float velocity, int portamento_, + int midinote, bool legato = false); void fadein(float *smps); void computecurrentparameters(); bool finished_; PADnoteParameters *pars; - int poshi_l, poshi_r; + int poshi_l, poshi_r; float poslo; float basefreq; - bool firsttime, released; + bool firsttime, released; int nsample, portamento; @@ -78,7 +78,7 @@ class PADnote :public SynthNote /****************************************** * FREQUENCY GLOBAL PARAMETERS * ******************************************/ - float Detune; //cents + float Detune; //cents Envelope *FreqEnvelope; LFO *FreqLfo; @@ -86,37 +86,36 @@ class PADnote :public SynthNote /******************************************** * AMPLITUDE GLOBAL PARAMETERS * ********************************************/ - float Volume; // [ 0 .. 1 ] + float Volume; // [ 0 .. 1 ] - float Panning; // [ 0 .. 1 ] + float Panning; // [ 0 .. 1 ] Envelope *AmpEnvelope; LFO *AmpLfo; struct { - int Enabled; + int Enabled; float initialvalue, dt, t; } Punch; /****************************************** * FILTER GLOBAL PARAMETERS * ******************************************/ - class Filter *GlobalFilterL, *GlobalFilterR; + class Filter *GlobalFilterL, *GlobalFilterR; - float FilterCenterPitch; //octaves - float FilterQ; - float FilterFreqTracking; + float FilterCenterPitch; //octaves + float FilterQ; + float FilterFreqTracking; Envelope *FilterEnvelope; - LFO *FilterLfo; + LFO *FilterLfo; } NoteGlobalPar; - float globaloldamplitude, globalnewamplitude, velocity, realfreq; + float globaloldamplitude, globalnewamplitude, velocity, realfreq; Controller *ctl; }; #endif - diff --git a/src/Synth/Resonance.cpp b/src/Synth/Resonance.cpp index 17ed2fef..4eb4e019 100644 --- a/src/Synth/Resonance.cpp +++ b/src/Synth/Resonance.cpp @@ -40,8 +40,8 @@ void Resonance::defaults() Pcenterfreq = 64; //1 kHz Poctavesfreq = 64; Pprotectthefundamental = 0; - ctlcenter = 1.0f; - ctlbw = 1.0f; + ctlcenter = 1.0f; + ctlbw = 1.0f; for(int i = 0; i < N_RES_POINTS; ++i) Prespoints[i] = 64; } @@ -64,8 +64,8 @@ void Resonance::applyres(int n, fft_t *fftdata, float freq) if(Penabled == 0) return; //if the resonance is disabled float sum = 0.0f, - l1 = logf(getfreqx(0.0f) * ctlcenter), - l2 = logf(2.0f) * getoctavesfreq() * ctlbw; + l1 = logf(getfreqx(0.0f) * ctlcenter), + l2 = logf(2.0f) * getoctavesfreq() * ctlbw; for(int i = 0; i < N_RES_POINTS; ++i) if(sum < Prespoints[i]) @@ -80,14 +80,14 @@ void Resonance::applyres(int n, fft_t *fftdata, float freq) x *= N_RES_POINTS; float dx = x - floor(x); - x = floor(x); - int kx1 = (int)x; + x = floor(x); + int kx1 = (int)x; if(kx1 >= N_RES_POINTS) kx1 = N_RES_POINTS - 1; - int kx2 = kx1 + 1; + int kx2 = kx1 + 1; if(kx2 >= N_RES_POINTS) kx2 = N_RES_POINTS - 1; - float y = + float y = (Prespoints[kx1] * (1.0f - dx) + Prespoints[kx2] * dx) / 127.0f - sum / 127.0f; @@ -107,7 +107,7 @@ void Resonance::applyres(int n, fft_t *fftdata, float freq) float Resonance::getfreqresponse(float freq) { float l1 = logf(getfreqx(0.0f) * ctlcenter), - l2 = logf(2.0f) * getoctavesfreq() * ctlbw, sum = 0.0f; + l2 = logf(2.0f) * getoctavesfreq() * ctlbw, sum = 0.0f; for(int i = 0; i < N_RES_POINTS; ++i) if(sum < Prespoints[i]) @@ -119,12 +119,12 @@ float Resonance::getfreqresponse(float freq) if(x < 0.0f) x = 0.0f; x *= N_RES_POINTS; - float dx = x - floor(x); - x = floor(x); - int kx1 = (int)x; + float dx = x - floor(x); + x = floor(x); + int kx1 = (int)x; if(kx1 >= N_RES_POINTS) kx1 = N_RES_POINTS - 1; - int kx2 = kx1 + 1; + int kx2 = kx1 + 1; if(kx2 >= N_RES_POINTS) kx2 = N_RES_POINTS - 1; float result = @@ -178,7 +178,7 @@ void Resonance::randomize(int type) void Resonance::interpolatepeaks(int type) { int x1 = 0, y1 = Prespoints[0]; - for(int i = 1; i < N_RES_POINTS; ++i) { + for(int i = 1; i < N_RES_POINTS; ++i) if((Prespoints[i] != 64) || (i + 1 == N_RES_POINTS)) { int y2 = Prespoints[i]; for(int k = 0; k < i - x1; ++k) { @@ -190,7 +190,6 @@ void Resonance::interpolatepeaks(int type) x1 = i; y1 = y2; } - } } /* @@ -261,7 +260,7 @@ void Resonance::add2XML(XMLwrapper *xml) void Resonance::getfromXML(XMLwrapper *xml) { - Penabled = xml->getparbool("enabled", Penabled); + Penabled = xml->getparbool("enabled", Penabled); PmaxdB = xml->getpar127("max_db", PmaxdB); Pcenterfreq = xml->getpar127("center_freq", Pcenterfreq); @@ -275,4 +274,3 @@ void Resonance::getfromXML(XMLwrapper *xml) xml->exitbranch(); } } - diff --git a/src/Synth/Resonance.h b/src/Synth/Resonance.h index f730897c..77785711 100644 --- a/src/Synth/Resonance.h +++ b/src/Synth/Resonance.h @@ -68,4 +68,3 @@ class Resonance:public Presets }; #endif - diff --git a/src/Synth/SUBnote.cpp b/src/Synth/SUBnote.cpp index e11e3bcf..9a1f586e 100644 --- a/src/Synth/SUBnote.cpp +++ b/src/Synth/SUBnote.cpp @@ -35,15 +35,19 @@ SUBnote::SUBnote(SUBnoteParameters *parameters, int portamento_, int midinote, bool besilent) -:SynthNote(freq, velocity, portamento_, midinote, besilent) + :SynthNote(freq, velocity, portamento_, midinote, besilent) { pars = parameters; ctl = ctl_; - NoteEnabled= ON; + NoteEnabled = ON; setup(freq, velocity, portamento_, midinote); } -void SUBnote::setup(float freq, float velocity, int portamento_, int midinote, bool legato) +void SUBnote::setup(float freq, + float velocity, + int portamento_, + int midinote, + bool legato) { portamento = portamento_; NoteEnabled = ON; @@ -69,7 +73,8 @@ void SUBnote::setup(float freq, float velocity, int portamento_, int midinote, b if(fixedfreqET != 0) { //if the frequency varies according the keyboard note float tmp = (midinote - - 69.0f) / 12.0f * (powf(2.0f, (fixedfreqET - 1) / 63.0f) - 1.0f); + - 69.0f) / 12.0f + * (powf(2.0f, (fixedfreqET - 1) / 63.0f) - 1.0f); if(fixedfreqET <= 64) basefreq *= powf(2.0f, tmp); else @@ -77,14 +82,15 @@ void SUBnote::setup(float freq, float velocity, int portamento_, int midinote, b } } float detune = getdetune(pars->PDetuneType, - pars->PCoarseDetune, - pars->PDetune); + pars->PCoarseDetune, + pars->PDetune); basefreq *= powf(2.0f, detune / 1200.0f); //detune // basefreq*=ctl->pitchwheel.relfreq;//pitch wheel //global filter GlobalFilterCenterPitch = pars->GlobalFilter->getfreq() //center freq - + (pars->PGlobalFilterVelocityScale / 127.0f * 6.0f) //velocity sensing + + (pars->PGlobalFilterVelocityScale / 127.0f + * 6.0f) //velocity sensing * (VelF(velocity, pars->PGlobalFilterVelocityScaleFunction) - 1); @@ -146,26 +152,26 @@ void SUBnote::setup(float freq, float velocity, int portamento_, int midinote, b bw = 25.0f; //try to keep same amplitude on all freqs and bw. (empirically) - float gain = sqrt(1500.0f / (bw * freq)); + float gain = sqrt(1500.0f / (bw * freq)); float hmagnew = 1.0f - pars->Phmag[pos[n]] / 127.0f; float hgain; switch(pars->Phmagtype) { - case 1: - hgain = expf(hmagnew * logf(0.01f)); - break; - case 2: - hgain = expf(hmagnew * logf(0.001f)); - break; - case 3: - hgain = expf(hmagnew * logf(0.0001f)); - break; - case 4: - hgain = expf(hmagnew * logf(0.00001f)); - break; - default: - hgain = 1.0f - hmagnew; + case 1: + hgain = expf(hmagnew * logf(0.01f)); + break; + case 2: + hgain = expf(hmagnew * logf(0.001f)); + break; + case 3: + hgain = expf(hmagnew * logf(0.0001f)); + break; + case 4: + hgain = expf(hmagnew * logf(0.00001f)); + break; + default: + hgain = 1.0f - hmagnew; } gain *= hgain; reduceamp += hgain; @@ -200,7 +206,8 @@ void SUBnote::setup(float freq, float velocity, int portamento_, int midinote, b if(pars->PGlobalFilterEnabled != 0) { globalfiltercenterq = pars->GlobalFilter->getq(); - GlobalFilterFreqTracking = pars->GlobalFilter->getfreqtracking(basefreq); + GlobalFilterFreqTracking = pars->GlobalFilter->getfreqtracking( + basefreq); } } @@ -330,14 +337,14 @@ void SUBnote::filter(bpfilter &filter, float *smps) { assert(SOUND_BUFFER_SIZE % 8 == 0); for(int i = 0; i < SOUND_BUFFER_SIZE; i += 8) { - smps[i] = SubFilter(filter, smps[i]); - smps[i+1] = SubFilter(filter, smps[i+1]); - smps[i+2] = SubFilter(filter, smps[i+2]); - smps[i+3] = SubFilter(filter, smps[i+3]); - smps[i+4] = SubFilter(filter, smps[i+4]); - smps[i+5] = SubFilter(filter, smps[i+5]); - smps[i+6] = SubFilter(filter, smps[i+6]); - smps[i+7] = SubFilter(filter, smps[i+7]); + smps[i] = SubFilter(filter, smps[i]); + smps[i + 1] = SubFilter(filter, smps[i + 1]); + smps[i + 2] = SubFilter(filter, smps[i + 2]); + smps[i + 3] = SubFilter(filter, smps[i + 3]); + smps[i + 4] = SubFilter(filter, smps[i + 4]); + smps[i + 5] = SubFilter(filter, smps[i + 5]); + smps[i + 6] = SubFilter(filter, smps[i + 6]); + smps[i + 7] = SubFilter(filter, smps[i + 7]); } } @@ -360,8 +367,8 @@ void SUBnote::initparameters(float freq) GlobalFilterL = Filter::generate(pars->GlobalFilter); if(stereo) GlobalFilterR = Filter::generate(pars->GlobalFilter); - GlobalFilterEnvelope = new Envelope(pars->GlobalFilterEnvelope, - freq); + GlobalFilterEnvelope = new Envelope(pars->GlobalFilterEnvelope, + freq); GlobalFilterFreqTracking = pars->GlobalFilter->getfreqtracking(basefreq); } computecurrentparameters(); @@ -401,7 +408,7 @@ void SUBnote::computecurrentparameters() float tmpgain = 1.0f / sqrt(envbw * envfreq); - for(int n = 0; n < numharmonics; ++n) { + for(int n = 0; n < numharmonics; ++n) for(int nph = 0; nph < numstages; ++nph) { if(nph == 0) gain = tmpgain; @@ -412,9 +419,8 @@ void SUBnote::computecurrentparameters() lfilter[nph + n * numstages].bw * envbw, gain); } - } if(stereo != 0) - for(int n = 0; n < numharmonics; ++n) { + for(int n = 0; n < numharmonics; ++n) for(int nph = 0; nph < numstages; ++nph) { if(nph == 0) gain = tmpgain; @@ -427,7 +433,7 @@ void SUBnote::computecurrentparameters() rfilter[nph + n * numstages].bw * envbw, gain); } - } + oldbandwidth = ctl->bandwidth.data; oldpitchwheel = ctl->pitchwheel.data; @@ -437,9 +443,9 @@ void SUBnote::computecurrentparameters() //Filter if(GlobalFilterL != NULL) { float globalfilterpitch = GlobalFilterCenterPitch - + GlobalFilterEnvelope->envout(); + + GlobalFilterEnvelope->envout(); float filterfreq = globalfilterpitch + ctl->filtercutoff.relfreq - + GlobalFilterFreqTracking; + + GlobalFilterFreqTracking; filterfreq = Filter::getrealfreq(filterfreq); GlobalFilterL->setfreq_and_q(filterfreq, @@ -511,29 +517,27 @@ int SUBnote::noteout(float *outl, float *outr) firsttick = 0; } - if(ABOVE_AMPLITUDE_THRESHOLD(oldamplitude, newamplitude)) { + if(ABOVE_AMPLITUDE_THRESHOLD(oldamplitude, newamplitude)) // Amplitude interpolation for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { float tmpvol = INTERPOLATE_AMPLITUDE(oldamplitude, - newamplitude, - i, - SOUND_BUFFER_SIZE); + newamplitude, + i, + SOUND_BUFFER_SIZE); outl[i] *= tmpvol * panning; outr[i] *= tmpvol * (1.0f - panning); } - } - else { + else for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { outl[i] *= newamplitude * panning; outr[i] *= newamplitude * (1.0f - panning); } - } oldamplitude = newamplitude; computecurrentparameters(); // Apply legato-specific sound signal modifications - legato.apply(*this,outl,outr); + legato.apply(*this, outl, outr); // Check if the note needs to be computed more if(AmpEnvelope->finished() != 0) { @@ -571,4 +575,3 @@ int SUBnote::finished() const else return 0; } - diff --git a/src/Synth/SUBnote.h b/src/Synth/SUBnote.h index b8389f65..21e40623 100644 --- a/src/Synth/SUBnote.h +++ b/src/Synth/SUBnote.h @@ -30,7 +30,7 @@ #include "Envelope.h" #include "../DSP/Filter.h" -class SUBnote :public SynthNote +class SUBnote:public SynthNote { public: SUBnote(SUBnoteParameters *parameters, Controller *ctl_, float freq, @@ -45,7 +45,11 @@ class SUBnote :public SynthNote int finished() const; private: - void setup(float freq, float velocity, int portamento_, int midinote, bool legato=false); + void setup(float freq, + float velocity, + int portamento_, + int midinote, + bool legato = false); void computecurrentparameters(); void initparameters(float freq); void KillNote(); @@ -53,13 +57,13 @@ class SUBnote :public SynthNote SUBnoteParameters *pars; //parameters - int stereo; - int numstages; //number of stages of filters - int numharmonics; //number of harmonics (after the too higher hamonics are removed) - int firstnumharmonics; //To keep track of the first note's numharmonics value, useful in legato mode. - int start; //how the harmonics start - float basefreq; - float panning; + int stereo; + int numstages; //number of stages of filters + int numharmonics; //number of harmonics (after the too higher hamonics are removed) + int firstnumharmonics; //To keep track of the first note's numharmonics value, useful in legato mode. + int start; //how the harmonics start + float basefreq; + float panning; Envelope *AmpEnvelope; Envelope *FreqEnvelope; Envelope *BandWidthEnvelope; @@ -70,8 +74,8 @@ class SUBnote :public SynthNote //internal values ONOFFTYPE NoteEnabled; - int firsttick, portamento; - float volume, oldamplitude, newamplitude; + int firsttick, portamento; + float volume, oldamplitude, newamplitude; float GlobalFilterCenterPitch; //octaves float GlobalFilterFreqTracking; @@ -97,9 +101,8 @@ class SUBnote :public SynthNote bpfilter *lfilter, *rfilter; Controller *ctl; - int oldpitchwheel, oldbandwidth; + int oldpitchwheel, oldbandwidth; float globalfiltercenterq; }; #endif - diff --git a/src/Synth/SynthNote.cpp b/src/Synth/SynthNote.cpp index f192a1aa..472b10b8 100644 --- a/src/Synth/SynthNote.cpp +++ b/src/Synth/SynthNote.cpp @@ -3,7 +3,7 @@ #include SynthNote::SynthNote(float freq, float vel, int port, int note, bool quiet) - :legato(freq,vel,port,note,quiet) + :legato(freq, vel, port, note, quiet) {} SynthNote::Legato::Legato(float freq, float vel, int port, @@ -11,13 +11,13 @@ SynthNote::Legato::Legato(float freq, float vel, int port, { // Initialise some legato-specific vars msg = LM_Norm; - fade.length = (int)(SAMPLE_RATE * 0.005f); // 0.005f seems ok. + fade.length = (int)(SAMPLE_RATE * 0.005f); // 0.005f seems ok. if(fade.length < 1) fade.length = 1; // (if something's fishy) - fade.step = (1.0f / fade.length); - decounter = -10; - param.freq = freq; - param.vel = vel; + fade.step = (1.0f / fade.length); + decounter = -10; + param.freq = freq; + param.vel = vel; param.portamento = port; param.midinote = note; lastfreq = 0.0f; @@ -25,7 +25,7 @@ SynthNote::Legato::Legato(float freq, float vel, int port, } int SynthNote::Legato::update(float freq, float velocity, int portamento_, - int midinote_, bool externcall) + int midinote_, bool externcall) { if(externcall) msg = LM_Norm; @@ -60,69 +60,68 @@ void SynthNote::Legato::apply(SynthNote ¬e, float *outl, float *outr) memset(outr, 0, SOUND_BUFFER_SIZE * sizeof(float)); } switch(msg) { - case LM_CatchUp: // Continue the catch-up... - if(decounter == -10) - decounter = fade.length; - //Yea, could be done without the loop... - for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { - decounter--; - if(decounter < 1) { - // Catching-up done, we can finally set - // the note to the actual parameters. - decounter = -10; - msg = LM_ToNorm; - note.legatonote(param.freq, param.vel, param.portamento, - param.midinote, false); - break; - } - } - break; - case LM_FadeIn: // Fade-in - if(decounter == -10) - decounter = fade.length; - silent = false; - for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { - decounter--; - if(decounter < 1) { - decounter = -10; - msg = LM_Norm; - break; + case LM_CatchUp: // Continue the catch-up... + if(decounter == -10) + decounter = fade.length; + //Yea, could be done without the loop... + for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { + decounter--; + if(decounter < 1) { + // Catching-up done, we can finally set + // the note to the actual parameters. + decounter = -10; + msg = LM_ToNorm; + note.legatonote(param.freq, param.vel, param.portamento, + param.midinote, false); + break; + } } - fade.m += fade.step; - outl[i] *= fade.m; - outr[i] *= fade.m; - } - break; - case LM_FadeOut: // Fade-out, then set the catch-up - if(decounter == -10) - decounter = fade.length; - for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { - decounter--; - if(decounter < 1) { - for(int j = i; j < SOUND_BUFFER_SIZE; ++j) { - outl[j] = 0.0f; - outr[j] = 0.0f; + break; + case LM_FadeIn: // Fade-in + if(decounter == -10) + decounter = fade.length; + silent = false; + for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { + decounter--; + if(decounter < 1) { + decounter = -10; + msg = LM_Norm; + break; } - decounter = -10; - silent = true; - // Fading-out done, now set the catch-up : + fade.m += fade.step; + outl[i] *= fade.m; + outr[i] *= fade.m; + } + break; + case LM_FadeOut: // Fade-out, then set the catch-up + if(decounter == -10) decounter = fade.length; - msg = LM_CatchUp; - //This freq should make this now silent note to catch-up/resync - //with the heard note for the same length it stayed at the - //previous freq during the fadeout. - float catchupfreq = param.freq * (param.freq / lastfreq); - note.legatonote(catchupfreq, param.vel, param.portamento, - param.midinote, false); - break; + for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) { + decounter--; + if(decounter < 1) { + for(int j = i; j < SOUND_BUFFER_SIZE; ++j) { + outl[j] = 0.0f; + outr[j] = 0.0f; + } + decounter = -10; + silent = true; + // Fading-out done, now set the catch-up : + decounter = fade.length; + msg = LM_CatchUp; + //This freq should make this now silent note to catch-up/resync + //with the heard note for the same length it stayed at the + //previous freq during the fadeout. + float catchupfreq = param.freq * (param.freq / lastfreq); + note.legatonote(catchupfreq, param.vel, param.portamento, + param.midinote, false); + break; + } + fade.m -= fade.step; + outl[i] *= fade.m; + outr[i] *= fade.m; } - fade.m -= fade.step; - outl[i] *= fade.m; - outr[i] *= fade.m; - } - break; - default: - break; + break; + default: + break; } } - diff --git a/src/Synth/SynthNote.h b/src/Synth/SynthNote.h index 00ddafab..bc5ba2ec 100644 --- a/src/Synth/SynthNote.h +++ b/src/Synth/SynthNote.h @@ -43,33 +43,34 @@ class SynthNote virtual int finished() const = 0; virtual void legatonote(float freq, float velocity, - int portamento_, int midinote_, bool externcall) = 0; + int portamento_, int midinote_, + bool externcall) = 0; protected: // Legato transitions - class Legato{ + class Legato + { public: Legato(float freq, float vel, int port, - int note, bool quiet); + int note, bool quiet); void apply(SynthNote ¬e, float *outl, float *outr); int update(float freq, float velocity, int portamento_, - int midinote_, bool externalcall); + int midinote_, bool externalcall); private: bool silent; - float lastfreq; + float lastfreq; LegatoMsg msg; - int decounter; + int decounter; struct { // Fade In/Out vars - int length; + int length; float m, step; } fade; struct { // Note parameters float freq, vel; - int portamento, midinote; + int portamento, midinote; } param; } legato; }; #endif - diff --git a/src/Tests/AdNoteTest.h b/src/Tests/AdNoteTest.h index 842472d7..78fe5d46 100644 --- a/src/Tests/AdNoteTest.h +++ b/src/Tests/AdNoteTest.h @@ -15,9 +15,9 @@ class AdNoteTest:public CxxTest::TestSuite { public: - ADnote *note; - Master *master; - FFTwrapper *fft; + ADnote *note; + Master *master; + FFTwrapper *fft; Controller *controller; unsigned char testnote; @@ -170,4 +170,3 @@ class AdNoteTest:public CxxTest::TestSuite } #endif }; - diff --git a/src/Tests/ControllerTest.h b/src/Tests/ControllerTest.h index 6c149091..ffa6257f 100644 --- a/src/Tests/ControllerTest.h +++ b/src/Tests/ControllerTest.h @@ -69,4 +69,3 @@ class ControllerTest:public CxxTest::TestSuite private: Controller *testCtl; }; - diff --git a/src/Tests/EchoTest.h b/src/Tests/EchoTest.h index 0541439f..aa9a87ac 100644 --- a/src/Tests/EchoTest.h +++ b/src/Tests/EchoTest.h @@ -38,7 +38,8 @@ class EchoTest:public CxxTest::TestSuite outR = new float[SOUND_BUFFER_SIZE]; for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) outR[i] = 0.0f; - input = new Stereo(new float[SOUND_BUFFER_SIZE],new float[SOUND_BUFFER_SIZE]); + input = new Stereo(new float[SOUND_BUFFER_SIZE], + new float[SOUND_BUFFER_SIZE]); for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) input->l[i] = input->r[i] = 0.0f; testFX = new Echo(true, outL, outR); @@ -91,7 +92,6 @@ class EchoTest:public CxxTest::TestSuite } //Insures that the proper decay occurs with high feedback void testDecaywFb() { - //flood with high input for(int i = 0; i < SOUND_BUFFER_SIZE; ++i) input->r[i] = input->l[i] = 1.0f; @@ -120,4 +120,3 @@ class EchoTest:public CxxTest::TestSuite float *outR, *outL; Echo *testFX; }; - diff --git a/src/Tests/MicrotonalTest.h b/src/Tests/MicrotonalTest.h index 8f1d3a3b..dc484671 100644 --- a/src/Tests/MicrotonalTest.h +++ b/src/Tests/MicrotonalTest.h @@ -87,7 +87,7 @@ class MicrotonalTest:public CxxTest::TestSuite xml.endbranch(); xml.endbranch(); - char *tmp = xml.getXMLdata(); + char *tmp = xml.getXMLdata(); Microtonal other; other.Penabled = 1; @@ -129,7 +129,7 @@ class MicrotonalTest:public CxxTest::TestSuite //the tuning is from old documentation for "Intense Diatonic" scale const char *tuning[7] = {"9/8", "5/4", "4/3", "3/2", "5/3", "15/8", "2/1"}; - const int numTunings = 7; + const int numTunings = 7; //for(int i=0;i<20;++i) // cout << i << ':' << testMicro->getnotefreq(i,0) << endl; // go to middle key and verify the proportions @@ -140,4 +140,3 @@ class MicrotonalTest:public CxxTest::TestSuite private: Microtonal *testMicro; }; - diff --git a/src/Tests/OscilGenTest.h b/src/Tests/OscilGenTest.h index a5e7f187..42b8528d 100644 --- a/src/Tests/OscilGenTest.h +++ b/src/Tests/OscilGenTest.h @@ -7,15 +7,15 @@ using namespace std; class OscilGenTest:public CxxTest::TestSuite { public: - float freq; + float freq; float *outR, *outL; FFTwrapper *fft; - OscilGen *oscil; + OscilGen *oscil; void setUp() { //First the sensible settings and variables that have to be set: SOUND_BUFFER_SIZE = 256; - OSCIL_SIZE = 1024; + OSCIL_SIZE = 1024; outL = new float[OSCIL_SIZE]; outR = new float[OSCIL_SIZE]; @@ -55,7 +55,7 @@ class OscilGenTest:public CxxTest::TestSuite const char testnote = 50; freq = 440.0f * powf(2.0f, (testnote - 69.0f) / 12.0f); } - + void tearDown() { delete oscil; delete fft; @@ -74,7 +74,7 @@ class OscilGenTest:public CxxTest::TestSuite void testOutput(void) { oscil->get(outL, freq); - TS_ASSERT_DELTA(outL[23], -0.044547f, 0.0001f); + TS_ASSERT_DELTA(outL[23], -0.044547f, 0.0001f); TS_ASSERT_DELTA(outL[129], -0.018169f, 0.0001f); TS_ASSERT_DELTA(outL[586], 0.045647f, 0.0001f); TS_ASSERT_DELTA(outL[1023], -0.038334f, 0.0001f); @@ -104,7 +104,7 @@ class OscilGenTest:public CxxTest::TestSuite printf("OscilGenTest: %f seconds for %d prepares.\n", (static_cast(t_off - t_on)) / CLOCKS_PER_SEC, samps); - + t_on = clock(); // timer before calling func for(int i = 0; i < samps; ++i) oscil->get(outL, freq); diff --git a/src/Tests/RandTest.h b/src/Tests/RandTest.h index c41cf11e..eeaa0482 100644 --- a/src/Tests/RandTest.h +++ b/src/Tests/RandTest.h @@ -38,5 +38,3 @@ class RandTest:public CxxTest::TestSuite TS_ASSERT_DELTA(RND, 0.511766, 0.00001); } }; - - diff --git a/src/Tests/SampleTest.h b/src/Tests/SampleTest.h index eed03289..e6363589 100644 --- a/src/Tests/SampleTest.h +++ b/src/Tests/SampleTest.h @@ -41,7 +41,7 @@ class SampleTest:public CxxTest::TestSuite smp[1] = 1; smp[2] = 2; Sample nsmp(40); - nsmp = smp; + nsmp = smp; TS_ASSERT_EQUALS(smp.size(), nsmp.size()); for(int i = 0; i < 29; ++i) TS_ASSERT_EQUALS(smp[i], nsmp[i]); @@ -82,21 +82,20 @@ class SampleTest:public CxxTest::TestSuite } void testResample() { - Sample orig(32,2); + Sample orig(32, 2); Sample cpy(orig); //test for no resampleing - orig.resample(128,128); - TS_ASSERT_EQUALS(cpy,orig); + orig.resample(128, 128); + TS_ASSERT_EQUALS(cpy, orig); //test for no bad distortions - orig.resample(128,256); - orig.resample(256,128); - TS_ASSERT_EQUALS(cpy,orig); + orig.resample(128, 256); + orig.resample(256, 128); + TS_ASSERT_EQUALS(cpy, orig); //test for downsample - orig.resample(256,128); - TS_ASSERT_EQUALS(orig.size(),cpy.size()/2); + orig.resample(256, 128); + TS_ASSERT_EQUALS(orig.size(), cpy.size() / 2); } }; - diff --git a/src/Tests/SubNoteTest.h b/src/Tests/SubNoteTest.h index 48968bf8..d12cf15b 100644 --- a/src/Tests/SubNoteTest.h +++ b/src/Tests/SubNoteTest.h @@ -156,4 +156,3 @@ class SubNoteTest:public CxxTest::TestSuite } #endif }; - diff --git a/src/Tests/XMLwrapperTest.h b/src/Tests/XMLwrapperTest.h index 339d4ce7..3b759ca4 100644 --- a/src/Tests/XMLwrapperTest.h +++ b/src/Tests/XMLwrapperTest.h @@ -40,13 +40,15 @@ class XMLwrapperTest:public CxxTest::TestSuite //here to verify that no leaks occur void testLoad() { - string location = string(SOURCE_DIR) + string("/Tests/guitar-adnote.xmz"); + string location = string(SOURCE_DIR) + string( + "/Tests/guitar-adnote.xmz"); xmla->loadXMLfile(location); } void testAnotherLoad() { - string dat = "\n\n\ + string dat = + "\n\n\ \n\ \n\ @@ -64,4 +66,3 @@ version-revision=\"1\" ZynAddSubFX-author=\"Nasca Octavian Paul\">\n\ XMLwrapper *xmla; XMLwrapper *xmlb; }; - diff --git a/src/UI/NioUI.cpp b/src/UI/NioUI.cpp index 6d3d1dde..04b97009 100644 --- a/src/UI/NioUI.cpp +++ b/src/UI/NioUI.cpp @@ -14,25 +14,25 @@ using namespace std; NioUI::NioUI() - :Fl_Window(200,100,400,400,"New IO Controls") + :Fl_Window(200, 100, 400, 400, "New IO Controls") { //hm, I appear to be leaking memory - Fl_Tabs *wintabs = new Fl_Tabs(0,0,400,400-15); + Fl_Tabs *wintabs = new Fl_Tabs(0, 0, 400, 400 - 15); { - Fl_Group *gen = new Fl_Group(0,20,400,400-35,"General"); + Fl_Group *gen = new Fl_Group(0, 20, 400, 400 - 35, "General"); { - Fl_Text_Buffer *buff = new Fl_Text_Buffer(); - Fl_Text_Display *intro = new Fl_Text_Display(20,40,350,300); + Fl_Text_Buffer *buff = new Fl_Text_Buffer(); + Fl_Text_Display *intro = new Fl_Text_Display(20, 40, 350, 300); intro->buffer(buff); buff->text("Thanks For Testing Out the New" - " Input/Output system. " - "Beware of bugs that may exist and" - " enjoy the new system."); + " Input/Output system. " + "Beware of bugs that may exist and" + " enjoy the new system."); intro->wrap_mode(4, 40); } gen->end(); - Fl_Group *settings = new Fl_Group(0,20,400,400-35,"Settings"); + Fl_Group *settings = new Fl_Group(0, 20, 400, 400 - 35, "Settings"); { audio = new Fl_Choice(60, 80, 100, 25, "Audio"); audio->callback(audioCallback); @@ -46,10 +46,10 @@ NioUI::NioUI() //initialize midi list { set midiList = nio.getSources(); - string source = nio.getSource(); + string source = nio.getSource(); int midival = 0; for(set::iterator itr = midiList.begin(); - itr != midiList.end(); ++itr) { + itr != midiList.end(); ++itr) { midi->add(itr->c_str()); if(*itr == source) midival = midi->size() - 2; @@ -60,10 +60,10 @@ NioUI::NioUI() //initialize audio list { set audioList = nio.getSinks(); - string sink = nio.getInstance().getSink(); + string sink = nio.getInstance().getSink(); int audioval = 0; for(set::iterator itr = audioList.begin(); - itr != audioList.end(); ++itr) { + itr != audioList.end(); ++itr) { audio->add(itr->c_str()); if(*itr == sink) audioval = audio->size() - 2; @@ -74,26 +74,23 @@ NioUI::NioUI() wintabs->end(); resizable(this); - size_range(400,300); + size_range(400, 300); } NioUI::~NioUI() -{ -} +{} void NioUI::refresh() -{ -} +{} void NioUI::midiCallback(Fl_Widget *c) { bool good = Nio::getInstance().setSource(static_cast(c)->text()); - static_cast(c)->textcolor(fl_rgb_color(255*!good,0,0)); + static_cast(c)->textcolor(fl_rgb_color(255 * !good, 0, 0)); } void NioUI::audioCallback(Fl_Widget *c) { bool good = Nio::getInstance().setSink(static_cast(c)->text()); - static_cast(c)->textcolor(fl_rgb_color(255*!good,0,0)); + static_cast(c)->textcolor(fl_rgb_color(255 * !good, 0, 0)); } - diff --git a/src/UI/NioUI.h b/src/UI/NioUI.h index 7a71f57b..f894997a 100644 --- a/src/UI/NioUI.h +++ b/src/UI/NioUI.h @@ -4,18 +4,17 @@ #include #include -class NioUI : public Fl_Window +class NioUI:public Fl_Window { public: NioUI(); ~NioUI(); void refresh(); private: - class Fl_Choice *midi; - class Fl_Choice *audio; + class Fl_Choice * midi; + class Fl_Choice * audio; static void midiCallback(Fl_Widget *c); static void audioCallback(Fl_Widget *c); }; #endif - diff --git a/src/UI/WidgetPDial.cpp b/src/UI/WidgetPDial.cpp index 6ef2b16a..76eb422e 100644 --- a/src/UI/WidgetPDial.cpp +++ b/src/UI/WidgetPDial.cpp @@ -15,22 +15,23 @@ using namespace std; -class TipWin : public Fl_Menu_Window { +class TipWin:public Fl_Menu_Window +{ public: TipWin(); void draw(); void showValue(float f); - void setText(const char * c); + void setText(const char *c); void showText(); private: void redraw(); const char *getStr() const; string tip; string text; - bool textmode; + bool textmode; }; -TipWin::TipWin():Fl_Menu_Window(1,1) +TipWin::TipWin():Fl_Menu_Window(1, 1) { set_override(); end(); @@ -44,7 +45,8 @@ void TipWin::draw() fl_font(labelfont(), labelsize()); //Draw the current string - fl_draw(getStr(), 3, 3, w()-6, h()-6, Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_WRAP)); + fl_draw(getStr(), 3, 3, w() - 6, h() - 6, + Fl_Align(FL_ALIGN_LEFT | FL_ALIGN_WRAP)); } void TipWin::showValue(float f) @@ -54,22 +56,22 @@ void TipWin::showValue(float f) snprintf(tmp, 9, "%.2f", f); tip = tmp; - textmode=false; + textmode = false; redraw(); show(); } -void TipWin::setText(const char * c) +void TipWin::setText(const char *c) { - text = c; - textmode=true; + text = c; + textmode = true; redraw(); } void TipWin::showText() { if(!text.empty()) { - textmode=true; + textmode = true; redraw(); show(); } @@ -95,8 +97,8 @@ const char *TipWin::getStr() const //static int numobj = 0; -WidgetPDial::WidgetPDial(int x,int y, int w, int h, const char *label) - :Fl_Dial(x,y,w,h,label),oldvalue(0.0f),pos(false),textset(false) +WidgetPDial::WidgetPDial(int x, int y, int w, int h, const char *label) + :Fl_Dial(x, y, w, h, label), oldvalue(0.0f), pos(false), textset(false) { //cout << "[" << label << "] There are now " << ++numobj << endl; Fl_Group *save = Fl_Group::current(); @@ -113,24 +115,25 @@ WidgetPDial::~WidgetPDial() int WidgetPDial::handle(int event) { - double dragsize, min=minimum(),max=maximum(); - int my; + double dragsize, min = minimum(), max = maximum(); + int my; - switch (event){ + switch(event) { case FL_PUSH: - oldvalue=value(); + oldvalue = value(); case FL_DRAG: getPos(); tipwin->showValue(value()); - my=-(Fl::event_y()-y()-h()/2); + my = -(Fl::event_y() - y() - h() / 2); - dragsize=200.0f; - if (Fl::event_state(FL_BUTTON1)==0) - dragsize*=10; + dragsize = 200.0f; + if(Fl::event_state(FL_BUTTON1) == 0) + dragsize *= 10; - value(limit(oldvalue+my/dragsize*(max-min),min,max)); + value(limit(oldvalue + my / dragsize * (max - min), min, max)); value_damage(); - if (this->when()!=0) do_callback(); + if(this->when() != 0) + do_callback(); return 1; case FL_ENTER: getPos(); @@ -144,7 +147,7 @@ int WidgetPDial::handle(int event) case FL_RELEASE: tipwin->hide(); resetPos(); - if (this->when()==0) + if(this->when() == 0) do_callback(); return 1; break; @@ -152,87 +155,92 @@ int WidgetPDial::handle(int event) return 0; } -void WidgetPDial::drawgradient(int cx,int cy,int sx,double m1,double m2) +void WidgetPDial::drawgradient(int cx, int cy, int sx, double m1, double m2) { - for (int i=(int)(m1*sx);i<(int)(m2*sx);i++){ - double tmp=1.0f-powf(i*1.0f/sx,2.0f); - pdialcolor(140+(int) (tmp*90),140+(int)(tmp*90),140+(int) (tmp*100)); - fl_arc(cx+sx/2-i/2,cy+sx/2-i/2,i,i,0,360); + for(int i = (int)(m1 * sx); i < (int)(m2 * sx); i++) { + double tmp = 1.0f - powf(i * 1.0f / sx, 2.0f); + pdialcolor(140 + + (int) (tmp + * 90), 140 + + (int)(tmp * 90), 140 + (int) (tmp * 100)); + fl_arc(cx + sx / 2 - i / 2, cy + sx / 2 - i / 2, i, i, 0, 360); } } void WidgetPDial::draw() { - int cx=x(),cy=y(),sx=w(),sy=h(); + int cx = x(), cy = y(), sx = w(), sy = h(); //clears the button face - pdialcolor(190,190,200); - fl_pie(cx-1,cy-1,sx+2,sy+2,0,360); + pdialcolor(190, 190, 200); + fl_pie(cx - 1, cy - 1, sx + 2, sy + 2, 0, 360); //Draws the button face (gradinet) - drawgradient(cx,cy,sx,0.5f,1.0f); + drawgradient(cx, cy, sx, 0.5f, 1.0f); - double val=(value()-minimum())/(maximum()-minimum()); + double val = (value() - minimum()) / (maximum() - minimum()); //draws the scale - pdialcolor(220,220,250); - double a1=angle1(),a2=angle2(); - for (int i=0;i<12;i++){ - double a=-i/12.0f*360.0f-val*(a2-a1)-a1; - fl_pie(cx,cy,sx,sy,a+270-3,a+3+270); - }; + pdialcolor(220, 220, 250); + double a1 = angle1(), a2 = angle2(); + for(int i = 0; i < 12; i++) { + double a = -i / 12.0f * 360.0f - val * (a2 - a1) - a1; + fl_pie(cx, cy, sx, sy, a + 270 - 3, a + 3 + 270); + } - drawgradient(cx,cy,sx,0.0f,0.75f); + drawgradient(cx, cy, sx, 0.0f, 0.75f); //draws the value - double a=-(a2-a1)*val-a1; + double a = -(a2 - a1) * val - a1; //draws the max and min points - pdialcolor(0,100,200); - int xp=(int)(cx+sx/2.0f+sx/2.0f*sinf(angle1()/180.0f*3.141592f)); - int yp=(int)(cy+sy/2.0f+sy/2.0f*cosf(angle1()/180.0f*3.141592f)); - fl_pie(xp-2,yp-2,4,4,0,360); + pdialcolor(0, 100, 200); + int xp = + (int)(cx + sx / 2.0f + sx / 2.0f * sinf(angle1() / 180.0f * 3.141592f)); + int yp = + (int)(cy + sy / 2.0f + sy / 2.0f * cosf(angle1() / 180.0f * 3.141592f)); + fl_pie(xp - 2, yp - 2, 4, 4, 0, 360); - xp=(int)(cx+sx/2.0f+sx/2.0f*sinf(angle2()/180.0f*3.141592f)); - yp=(int)(cy+sy/2.0f+sy/2.0f*cosf(angle2()/180.0f*3.141592f)); - fl_pie(xp-2,yp-2,4,4,0,360); + xp = (int)(cx + sx / 2.0f + sx / 2.0f * sinf(angle2() / 180.0f * 3.141592f)); + yp = (int)(cy + sy / 2.0f + sy / 2.0f * cosf(angle2() / 180.0f * 3.141592f)); + fl_pie(xp - 2, yp - 2, 4, 4, 0, 360); fl_push_matrix(); - fl_translate(cx+sx/2,cy+sy/2); - fl_rotate(a-90.0f); + fl_translate(cx + sx / 2, cy + sy / 2); + fl_rotate(a - 90.0f); - fl_translate(sx/2,0); + fl_translate(sx / 2, 0); fl_begin_polygon(); - pdialcolor(0,0,0); - fl_vertex(-10,-4); - fl_vertex(-10,4); - fl_vertex(0,0); + pdialcolor(0, 0, 0); + fl_vertex(-10, -4); + fl_vertex(-10, 4); + fl_vertex(0, 0); fl_end_polygon(); fl_pop_matrix(); } -void WidgetPDial::pdialcolor(int r,int g,int b) +void WidgetPDial::pdialcolor(int r, int g, int b) { - if (active_r()) - fl_color(r,g,b); + if(active_r()) + fl_color(r, g, b); else - fl_color(160-(160-r)/3,160-(160-b)/3,160-(160-b)/3); + fl_color(160 - (160 - r) / 3, 160 - (160 - b) / 3, 160 - (160 - b) / 3); } -void WidgetPDial::tooltip(const char * c) +void WidgetPDial::tooltip(const char *c) { tipwin->setText(c); - textset=true; + textset = true; } void WidgetPDial::getPos() { if(!pos) { - tipwin->position(Fl::event_x_root(), Fl::event_y_root()+20); - pos=true; + tipwin->position(Fl::event_x_root(), Fl::event_y_root() + 20); + pos = true; } } diff --git a/src/UI/WidgetPDial.h b/src/UI/WidgetPDial.h index b12db506..3f8cd711 100644 --- a/src/UI/WidgetPDial.h +++ b/src/UI/WidgetPDial.h @@ -5,21 +5,22 @@ #include -class WidgetPDial : public Fl_Dial { +class WidgetPDial:public Fl_Dial +{ public: - WidgetPDial(int x,int y, int w, int h, const char *label=0); + WidgetPDial(int x, int y, int w, int h, const char *label = 0); ~WidgetPDial(); int handle(int event); - void drawgradient(int cx,int cy,int sx,double m1,double m2); + void drawgradient(int cx, int cy, int sx, double m1, double m2); void draw(); - void pdialcolor(int r,int g,int b); - void tooltip(const char * c); + void pdialcolor(int r, int g, int b); + void tooltip(const char *c); private: void getPos(); void resetPos(); double oldvalue; - bool pos; - bool textset; - class TipWin *tipwin; + bool pos; + bool textset; + class TipWin * tipwin; }; #endif diff --git a/src/globals.h b/src/globals.h index 2797503c..ac523226 100644 --- a/src/globals.h +++ b/src/globals.h @@ -154,7 +154,8 @@ extern int OSCIL_SIZE; * How the amplitude threshold is computed */ #define ABOVE_AMPLITUDE_THRESHOLD(a, b) ((2.0f * fabs((b) - (a)) \ - / (fabs((b) + (a) + 0.0000000001f))) > \ + / (fabs((b) + (a) \ + + 0.0000000001f))) > \ AMPLITUDE_INTERPOLATION_THRESHOLD) /* @@ -177,10 +178,10 @@ extern int OSCIL_SIZE; i++) \ data_[i] = 0;} #define ZERO_float(data, size) {float *data_ = (float *) data; \ - for(int i = 0; \ - i < size; \ - i++) \ - data_[i] = 0.0f;} + for(int i = 0; \ + i < size; \ + i++) \ + data_[i] = 0.0f;} enum ONOFFTYPE { OFF = 0, ON = 1 @@ -205,7 +206,8 @@ enum LegatoMsg { #ifdef ASM_F2I_YES #define F2I(f, \ i) __asm__ __volatile__ ("fistpl %0" : "=m" (i) : "t" (f \ - - 0.49999999f) \ + - \ + 0.49999999f) \ : "st"); #else #define F2I(f, i) (i) = ((f > 0) ? ((int)(f)) : ((int)(f - 1.0f))); @@ -218,4 +220,3 @@ enum LegatoMsg { #endif #endif - diff --git a/src/main.cpp b/src/main.cpp index f3976426..e4263692 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,14 +59,14 @@ using namespace std; pthread_t thr3, thr4; Master *master; -int swaplr = 0; //1 for left-right swapping +int swaplr = 0; //1 for left-right swapping #if LASH #include "Misc/LASHClient.h" LASHClient *lash = NULL; #endif -int Pexitprogram = 0; //if the UI set this to 1, the program will exit +int Pexitprogram = 0; //if the UI set this to 1, the program will exit /* * User Interface thread @@ -175,7 +175,6 @@ void exitprogram() int main(int argc, char *argv[]) { - config.init(); dump.startnow(); int noui = 0; @@ -185,14 +184,14 @@ int main(int argc, char *argv[]) cerr << "Compiled: " << __DATE__ << " " << __TIME__ << endl; cerr << "This program is free software (GNU GPL v.2 or later) and \n"; cerr << "it comes with ABSOLUTELY NO WARRANTY.\n" << endl; - if(argc == 1) - cerr << "Try 'zynaddsubfx --help' for command-line options." << endl; + if(argc == 1) + cerr << "Try 'zynaddsubfx --help' for command-line options." << endl; /* Get the settings from the Config*/ SAMPLE_RATE = config.cfg.SampleRate; SOUND_BUFFER_SIZE = config.cfg.SoundBufferSize; - OSCIL_SIZE = config.cfg.OscilSize; - swaplr = config.cfg.SwapStereo; + OSCIL_SIZE = config.cfg.OscilSize; + swaplr = config.cfg.SwapStereo; sprng(time(NULL)); //produce denormal buf @@ -202,21 +201,51 @@ int main(int argc, char *argv[]) /* Parse command-line options */ struct option opts[] = { - {"load", 2, NULL, 'l'}, - {"load-instrument", 2, NULL, 'L'}, - {"sample-rate", 2, NULL, 'r'}, - {"buffer-size", 2, NULL, 'b'}, - {"oscil-size", 2, NULL, 'o'}, - {"dump", 2, NULL, 'D'}, - {"swap", 2, NULL, 'S'}, - {"no-gui", 2, NULL, 'U'}, - {"dummy", 2, NULL, 'Y'}, - {"help", 2, NULL, 'h'}, - {"named", 1, NULL, 'N'}, - {"auto-connect", 0, NULL, 'a'}, - {"output", 1, NULL, 'O'}, - {"input", 1, NULL, 'I'}, - {0, 0, 0, 0} + { + "load", 2, NULL, 'l' + }, + { + "load-instrument", 2, NULL, 'L' + }, + { + "sample-rate", 2, NULL, 'r' + }, + { + "buffer-size", 2, NULL, 'b' + }, + { + "oscil-size", 2, NULL, 'o' + }, + { + "dump", 2, NULL, 'D' + }, + { + "swap", 2, NULL, 'S' + }, + { + "no-gui", 2, NULL, 'U' + }, + { + "dummy", 2, NULL, 'Y' + }, + { + "help", 2, NULL, 'h' + }, + { + "named", 1, NULL, 'N' + }, + { + "auto-connect", 0, NULL, 'a' + }, + { + "output", 1, NULL, 'O' + }, + { + "input", 1, NULL, 'I' + }, + { + 0, 0, 0, 0 + } }; opterr = 0; int option_index = 0, opt, exitwithhelp = 0; @@ -227,89 +256,97 @@ int main(int argc, char *argv[]) int tmp = 0; /**\todo check this process for a small memory leak*/ - opt = getopt_long(argc, argv, "l:L:r:b:o:I:O:N:haSDUY", opts, &option_index); + opt = getopt_long(argc, + argv, + "l:L:r:b:o:I:O:N:haSDUY", + opts, + &option_index); char *optarguments = optarg; -#define GETOP(x) if(optarguments) x = optarguments -#define GETOPNUM(x) if(optarguments) x = atoi(optarguments) +#define GETOP(x) if(optarguments) \ + x = optarguments +#define GETOPNUM(x) if(optarguments) \ + x = atoi(optarguments) if(opt == -1) break; switch(opt) { - case 'h': - exitwithhelp = 1; - break; - case 'Y':/* this command a dummy command (has NO effect) + case 'h': + exitwithhelp = 1; + break; + case 'Y':/* this command a dummy command (has NO effect) and is used because I need for NSIS installer (NSIS sometimes forces a command line for a program, even if I don't need that; eg. when I want to add a icon to a shortcut. */ - break; - case 'U': - noui = 1; - break; - case 'l': - GETOP(loadfile); - break; - case 'L': - GETOP(loadinstrument); - break; - case 'r': - GETOPNUM(SAMPLE_RATE); - if(SAMPLE_RATE < 4000) { - cerr << "ERROR:Incorrect sample rate: " << optarguments << endl; - exit(1); - } - break; - case 'b': - GETOPNUM(SOUND_BUFFER_SIZE); - if(SOUND_BUFFER_SIZE < 2) { - cerr << "ERROR:Incorrect buffer size: " << optarguments << endl; - exit(1); - } - break; - case 'o': - if(optarguments) - OSCIL_SIZE = tmp = atoi(optarguments); - if(OSCIL_SIZE < MAX_AD_HARMONICS * 2) - OSCIL_SIZE = MAX_AD_HARMONICS * 2; - OSCIL_SIZE = (int) powf(2, ceil(logf(OSCIL_SIZE - 1.0f) / logf(2.0f))); - if(tmp != OSCIL_SIZE) { - cerr << "OSCIL_SIZE is wrong (must be 2^n) or too small. Adjusting to " - << OSCIL_SIZE << "." << endl; - } - break; - case 'S': - swaplr = 1; - break; - case 'D': - dump.startnow(); - break; - case 'N': - Nio::getInstance().setPostfix(optarguments); - break; - case 'I': - if(optarguments) { - if(Nio::getInstance().setDefaultSource(optarguments)) + break; + case 'U': + noui = 1; + break; + case 'l': + GETOP(loadfile); + break; + case 'L': + GETOP(loadinstrument); + break; + case 'r': + GETOPNUM(SAMPLE_RATE); + if(SAMPLE_RATE < 4000) { + cerr << "ERROR:Incorrect sample rate: " << optarguments + << endl; exit(1); - } - break; - case 'O': - if(optarguments) { - if(Nio::getInstance().setDefaultSink(optarguments)) + } + break; + case 'b': + GETOPNUM(SOUND_BUFFER_SIZE); + if(SOUND_BUFFER_SIZE < 2) { + cerr << "ERROR:Incorrect buffer size: " << optarguments + << endl; exit(1); - } - break; - case 'a': - Nio::getInstance().autoConnect = true; - break; - case '?': - cerr << "ERROR:Bad option or parameter.\n" << endl; - exitwithhelp = 1; - break; + } + break; + case 'o': + if(optarguments) + OSCIL_SIZE = tmp = atoi(optarguments); + if(OSCIL_SIZE < MAX_AD_HARMONICS * 2) + OSCIL_SIZE = MAX_AD_HARMONICS * 2; + OSCIL_SIZE = + (int) powf(2, ceil(logf(OSCIL_SIZE - 1.0f) / logf(2.0f))); + if(tmp != OSCIL_SIZE) + cerr + << + "OSCIL_SIZE is wrong (must be 2^n) or too small. Adjusting to " + << OSCIL_SIZE << "." << endl; + break; + case 'S': + swaplr = 1; + break; + case 'D': + dump.startnow(); + break; + case 'N': + Nio::getInstance().setPostfix(optarguments); + break; + case 'I': + if(optarguments) + if(Nio::getInstance().setDefaultSource(optarguments)) + exit(1); + break; + case 'O': + if(optarguments) + if(Nio::getInstance().setDefaultSink(optarguments)) + exit(1); + break; + case 'a': + Nio::getInstance().autoConnect = true; + break; + case '?': + cerr << "ERROR:Bad option or parameter.\n" << endl; + exitwithhelp = 1; + break; } } @@ -319,11 +356,13 @@ int main(int argc, char *argv[]) << " -l file, --load=FILE\t\t\t Loads a .xmz file\n" << " -L file, --load-instrument=FILE\t Loads a .xiz file\n" << " -r SR, --sample-rate=SR\t\t Set the sample rate SR\n" - << " -b BS, --buffer-size=SR\t\t Set the buffer size (granularity)\n" + << + " -b BS, --buffer-size=SR\t\t Set the buffer size (granularity)\n" << " -o OS, --oscil-size=OS\t\t Set the ADsynth oscil. size\n" << " -S , --swap\t\t\t\t Swap Left <--> Right\n" << " -D , --dump\t\t\t\t Dumps midi note ON/OFF commands\n" - << " -U , --no-gui\t\t\t\t Run ZynAddSubFX without user interface\n" + << + " -U , --no-gui\t\t\t\t Run ZynAddSubFX without user interface\n" << " -N , --named\t\t\t\t Postfix IO Name when possible\n" << " -a , --auto-connect\t\t\t AutoConnect when using JACK\n" << " -O , --output\t\t\t\t Set Output Engine\n" @@ -332,7 +371,7 @@ int main(int argc, char *argv[]) return 0; } - initprogram(argc,argv); + initprogram(argc, argv); #if 0 //TODO update this code #ifdef USE_LASH @@ -363,7 +402,8 @@ int main(int argc, char *argv[]) if(!loadinstrument.empty()) { int loadtopart = 0; - int tmp = master->part[loadtopart]->loadXMLinstrument(loadinstrument.c_str()); + int tmp = master->part[loadtopart]->loadXMLinstrument( + loadinstrument.c_str()); if(tmp < 0) { cerr << "ERROR: Could not load instrument file " << loadinstrument << '.' << endl; @@ -380,7 +420,7 @@ int main(int argc, char *argv[]) #ifndef DISABLE_GUI if(noui == 0) - pthread_create(&thr3, NULL, thread3, (void*)!ioGood); + pthread_create(&thr3, NULL, thread3, (void *)!ioGood); #endif //TODO look into a conditional variable here, it seems to match usage diff --git a/style.cfg b/style.cfg new file mode 100644 index 00000000..ba66d990 --- /dev/null +++ b/style.cfg @@ -0,0 +1,1218 @@ +# Uncrustify 0.53 + +# +# General options +# + +# The type of line endings +newlines = lf # auto/lf/crlf/cr + +# The original size of tabs in the input +input_tab_size = 4 # number + +# The size of tabs in the output (only used if align_with_tabs=true) +output_tab_size = 4 # number + +# The ascii value of the string escape char, usually 92 (\) or 94 (^). (Pawn) +string_escape_char = 92 # number + +# Alternate string escape char for Pawn. Only works right before the quote char. +string_escape_char2 = 0 # number + +# +# Indenting +# + +# The number of columns to indent per level. +# Usually 2, 3, 4, or 8. +indent_columns = 4 # number + +# How to use tabs when indenting code +# 0=spaces only +# 1=indent with tabs, align with spaces +# 2=indent and align with tabs +indent_with_tabs = 0 # number + +# Whether to indent strings broken by '\' so that they line up +indent_align_string = true # false/true + +# The number of spaces to indent multi-line XML strings. +# Requires indent_align_string=True +indent_xml_string = 0 # number + +# Spaces to indent '{' from level +indent_brace = 0 # number + +# Whether braces are indented to the body level +indent_braces = false # false/true + +# Disabled indenting function braces if indent_braces is true +indent_braces_no_func = false # false/true + +# Indent based on the size of the brace parent, ie 'if' => 3 spaces, 'for' => 4 spaces, etc. +indent_brace_parent = false # false/true + +# Whether the 'namespace' body is indented +indent_namespace = true # false/true + +# Whether the 'extern "C"' body is indented +indent_extern = true # false/true + +# Whether the 'class' body is indented +indent_class = true # false/true + +# Whether to indent the stuff after a leading class colon +indent_class_colon = true # false/true + +# False=treat 'else\nif' as 'else if' for indenting purposes +# True=indent the 'if' one level +indent_else_if = false # false/true + +# Amount to indent variable declarations after a open brace. neg=relative, pos=absolute +indent_var_def_blk = 0 # number + +# True: indent continued function call parameters one indent level +# False: align parameters under the open paren +indent_func_call_param = false # false/true + +# Same as indent_func_call_param, but for function defs +indent_func_def_param = false # false/true + +# Same as indent_func_call_param, but for function protos +indent_func_proto_param = false # false/true + +# Same as indent_func_call_param, but for class declarations +indent_func_class_param = false # false/true + +# Same as indent_func_call_param, but for class variable constructors +indent_func_ctor_var_param = false # false/true + +# Same as indent_func_call_param, but for templates +indent_template_param = false # false/true + +# Double the indent for indent_func_xxx_param options +indent_func_param_double = false # false/true + +# Indentation column for standalone 'const' function decl/proto qualifier +indent_func_const = 0 # number + +# Indentation column for standalone 'throw' function decl/proto qualifier +indent_func_throw = 0 # number + +# The number of spaces to indent a continued '->' or '.' +# Usually set to 0, 1, or indent_columns. +indent_member = 0 # number + +# Spaces to indent single line ('//') comments on lines before code +indent_sing_line_comments = 0 # number + +# If set, will indent trailing single line ('//') comments relative +# to the code instead of trying to keep the same absolute column +indent_relative_single_line_comments = false # false/true + +# Spaces to indent 'case' from 'switch' +# Usually 0 or indent_columns. +indent_switch_case = 4 # number + +# Spaces to shift the 'case' line, without affecting any other lines +# Usually 0. +indent_case_shift = 0 # number + +# Spaces to indent '{' from 'case'. +# By default, the brace will appear under the 'c' in case. +# Usually set to 0 or indent_columns. +indent_case_brace = 0 # number + +# Whether to indent comments found in first column +indent_col1_comment = false # false/true + +# How to indent goto labels +# >0 : absolute column where 1 is the leftmost column +# <=0 : subtract from brace indent +indent_label = 1 # number + +# Same as indent_label, but for access specifiers that are followed by a colon +indent_access_spec = 1 # number + +# Indent the code after an access specifier by one level. +# If set, this option forces 'indent_access_spec=0' +indent_access_spec_body = true # false/true + +# If an open paren is followed by a newline, indent the next line so that it lines up after the open paren (not recommended) +indent_paren_nl = false # false/true + +# Controls the indent of a close paren after a newline. +# 0: Indent to body level +# 1: Align under the open paren +# 2: Indent to the brace level +indent_paren_close = 1 # number + +# Controls the indent of a comma when inside a paren.If TRUE, aligns under the open paren +indent_comma_paren = false # false/true + +# Controls the indent of a BOOL operator when inside a paren.If TRUE, aligns under the open paren +indent_bool_paren = false # false/true + +# If an open square is followed by a newline, indent the next line so that it lines up after the open square (not recommended) +indent_square_nl = false # false/true + +# Don't change the relative indent of ESQL/C 'EXEC SQL' bodies +indent_preserve_sql = false # false/true + +# Align continued statements at the '='. Default=True +# If FALSE or the '=' is followed by a newline, the next line is indent one tab. +indent_align_assign = true # false/true + +# +# Spacing options +# + +# Add or remove space around arithmetic operator '+', '-', '/', '*', etc +sp_arith = force # ignore/add/remove/force + +# Add or remove space around assignment operator '=', '+=', etc +sp_assign = force # ignore/add/remove/force + +# Add or remove space before assignment operator '=', '+=', etc. Overrides sp_assign. +sp_before_assign = ignore # ignore/add/remove/force + +# Add or remove space after assignment operator '=', '+=', etc. Overrides sp_assign. +sp_after_assign = ignore # ignore/add/remove/force + +# Add or remove space around assignment '=' in enum +sp_enum_assign = force # ignore/add/remove/force + +# Add or remove space before assignment '=' in enum. Overrides sp_enum_assign. +sp_enum_before_assign = ignore # ignore/add/remove/force + +# Add or remove space after assignment '=' in enum. Overrides sp_enum_assign. +sp_enum_after_assign = ignore # ignore/add/remove/force + +# Add or remove space around preprocessor '##' concatenation operator +sp_pp_concat = add # ignore/add/remove/force + +# Add or remove space after preprocessor '#' stringify operator +sp_pp_stringify = add # ignore/add/remove/force + +# Add or remove space around boolean operators '&&' and '||' +sp_bool = force # ignore/add/remove/force + +# Add or remove space around compare operator '<', '>', '==', etc +sp_compare = force # ignore/add/remove/force + +# Add or remove space inside '(' and ')' +sp_inside_paren = remove # ignore/add/remove/force + +# Add or remove space between nested parens +sp_paren_paren = remove # ignore/add/remove/force + +# Whether to balance spaces inside nested parens +sp_balance_nested_parens = false # false/true + +# Add or remove space between ')' and '{' +sp_paren_brace = force # ignore/add/remove/force + +# Add or remove space before pointer star '*' +sp_before_ptr_star = force # ignore/add/remove/force + +# Add or remove space before pointer star '*' that isn't followed by a variable name +# If set to 'ignore', sp_before_ptr_star is used instead. +sp_before_unnamed_ptr_star = ignore # ignore/add/remove/force + +# Add or remove space between pointer stars '*' +sp_between_ptr_star = remove # ignore/add/remove/force + +# Add or remove space after pointer star '*', if followed by a word. +sp_after_ptr_star = remove # ignore/add/remove/force + +# Add or remove space after a pointer star '*', if followed by a func proto/def. +sp_after_ptr_star_func = remove # ignore/add/remove/force + +# Add or remove space before a pointer star '*', if followed by a func proto/def. +sp_before_ptr_star_func = force # ignore/add/remove/force + +# Add or remove space before a reference sign '&' +sp_before_byref = force # ignore/add/remove/force + +# Add or remove space before a reference sign '&' that isn't followed by a variable name +# If set to 'ignore', sp_before_byref is used instead. +sp_before_unnamed_byref = ignore # ignore/add/remove/force + +# Add or remove space after reference sign '&', if followed by a word. +sp_after_byref = remove # ignore/add/remove/force + +# Add or remove space after a reference sign '&', if followed by a func proto/def. +sp_after_byref_func = ignore # ignore/add/remove/force + +# Add or remove space before a reference sign '&', if followed by a func proto/def. +sp_before_byref_func = ignore # ignore/add/remove/force + +# Add or remove space between type and word +sp_after_type = remove # ignore/add/remove/force + +# Add or remove space in 'template <' vs 'template<'. +# If set to ignore, sp_before_angle is used. +sp_template_angle = ignore # ignore/add/remove/force + +# Add or remove space before '<>' +sp_before_angle = remove # ignore/add/remove/force + +# Add or remove space inside '<' and '>' +sp_inside_angle = remove # ignore/add/remove/force + +# Add or remove space after '<>' +sp_after_angle = ignore # ignore/add/remove/force + +# Add or remove space between '<>' and '(' as found in 'new List();' +sp_angle_paren = remove # ignore/add/remove/force + +# Add or remove space between '<>' and a word as in 'List m;' +sp_angle_word = ignore # ignore/add/remove/force + +# Add or remove space before '(' of 'if', 'for', 'switch', and 'while' +sp_before_sparen = remove # ignore/add/remove/force + +# Add or remove space inside if-condition '(' and ')' +sp_inside_sparen = remove # ignore/add/remove/force + +# Add or remove space before if-condition ')'. Overrides sp_inside_sparen. +sp_inside_sparen_close = remove # ignore/add/remove/force + +# Add or remove space after ')' of 'if', 'for', 'switch', and 'while' +sp_after_sparen = remove # ignore/add/remove/force + +# Add or remove space between ')' and '{' of 'if', 'for', 'switch', and 'while' +sp_sparen_brace = force # ignore/add/remove/force + +# Add or remove space between 'invariant' and '(' in the D language. +sp_invariant_paren = ignore # ignore/add/remove/force + +# Add or remove space after the ')' in 'invariant (C) c' in the D language. +sp_after_invariant_paren = ignore # ignore/add/remove/force + +# Add or remove space before empty statement ';' on 'if', 'for' and 'while' +sp_special_semi = ignore # ignore/add/remove/force + +# Add or remove space before ';' +sp_before_semi = remove # ignore/add/remove/force + +# Add or remove space before ';' in non-empty 'for' statements +sp_before_semi_for = remove # ignore/add/remove/force + +# Add or remove space before a semicolon of an empty part of a for statment. +sp_before_semi_for_empty = remove # ignore/add/remove/force + +# Add or remove space after the final semicolon of an empty part of a for statment: for ( ; ; ). +sp_after_semi_for_empty = remove # ignore/add/remove/force + +# Add or remove space before '[' (except '[]') +sp_before_square = ignore # ignore/add/remove/force + +# Add or remove space before '[]' +sp_before_squares = ignore # ignore/add/remove/force + +# Add or remove space inside '[' and ']' +sp_inside_square = remove # ignore/add/remove/force + +# Add or remove space after ',' +sp_after_comma = force # ignore/add/remove/force + +# Add or remove space before ',' +sp_before_comma = remove # ignore/add/remove/force + +# Add or remove space after class ':' +sp_after_class_colon = remove # ignore/add/remove/force + +# Add or remove space before class ':' +sp_before_class_colon = remove # ignore/add/remove/force + +# Add or remove space before case ':' +sp_before_case_colon = remove # ignore/add/remove/force + +# Add or remove space between 'operator' and operator sign +sp_after_operator = ignore # ignore/add/remove/force + +# Add or remove space between the operator symbol and the open paren, as in 'operator ++(' +sp_after_operator_sym = ignore # ignore/add/remove/force + +# Add or remove space after C/D cast, ie 'cast(int)a' vs 'cast(int) a' or '(int)a' vs '(int) a' +sp_after_cast = ignore # ignore/add/remove/force + +# Add or remove spaces inside cast parens +sp_inside_paren_cast = remove # ignore/add/remove/force + +# Add or remove space between the type and open paren in a C++ cast, ie 'int(exp)' vs 'int (exp)' +sp_cpp_cast_paren = remove # ignore/add/remove/force + +# Add or remove space between 'sizeof' and '(' +sp_sizeof_paren = remove # ignore/add/remove/force + +# Add or remove space after the tag keyword (Pawn) +sp_after_tag = ignore # ignore/add/remove/force + +# Add or remove space inside enum '{' and '}' +sp_inside_braces_enum = ignore # ignore/add/remove/force + +# Add or remove space inside struct/union '{' and '}' +sp_inside_braces_struct = remove # ignore/add/remove/force + +# Add or remove space inside '{' and '}' +sp_inside_braces = ignore # ignore/add/remove/force + +# Add or remove space inside '{}' +sp_inside_braces_empty = ignore # ignore/add/remove/force + +# Add or remove space between return type and function name +# A minimum of 1 is forced except for pointer return types. +sp_type_func = ignore # ignore/add/remove/force + +# Add or remove space between function name and '(' on function declaration +sp_func_proto_paren = remove # ignore/add/remove/force + +# Add or remove space between function name and '(' on function definition +sp_func_def_paren = remove # ignore/add/remove/force + +# Add or remove space inside empty function '()' +sp_inside_fparens = remove # ignore/add/remove/force + +# Add or remove space inside function '(' and ')' +sp_inside_fparen = remove # ignore/add/remove/force + +# Add or remove space between ']' and '(' when part of a function call. +sp_square_fparen = ignore # ignore/add/remove/force + +# Add or remove space between ')' and '{' of function +sp_fparen_brace = force # ignore/add/remove/force + +# Add or remove space between function name and '(' on function calls +sp_func_call_paren = remove # ignore/add/remove/force + +# Add or remove space between the user function name and '(' on function calls +# You need to set a keyword to be a user function, like this: 'set func_call_user _' in the config file. +sp_func_call_user_paren = ignore # ignore/add/remove/force + +# Add or remove space between a constructor/destructor and the open paren +sp_func_class_paren = remove # ignore/add/remove/force + +# Add or remove space between 'return' and '(' +sp_return_paren = remove # ignore/add/remove/force + +# Add or remove space between '__attribute__' and '(' +sp_attribute_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'defined' and '(' in '#if defined (FOO)' +sp_defined_paren = ignore # ignore/add/remove/force + +# Add or remove space between 'throw' and '(' in 'throw (something)' +sp_throw_paren = ignore # ignore/add/remove/force + +# Add or remove space between macro and value +sp_macro = ignore # ignore/add/remove/force + +# Add or remove space between macro function ')' and value +sp_macro_func = ignore # ignore/add/remove/force + +# Add or remove space between 'else' and '{' if on the same line +sp_else_brace = force # ignore/add/remove/force + +# Add or remove space between '}' and 'else' if on the same line +sp_brace_else = ignore # ignore/add/remove/force + +# Add or remove space between '}' and the name of a typedef on the same line +sp_brace_typedef = ignore # ignore/add/remove/force + +# Add or remove space between 'catch' and '{' if on the same line +sp_catch_brace = ignore # ignore/add/remove/force + +# Add or remove space between '}' and 'catch' if on the same line +sp_brace_catch = ignore # ignore/add/remove/force + +# Add or remove space between 'finally' and '{' if on the same line +sp_finally_brace = ignore # ignore/add/remove/force + +# Add or remove space between '}' and 'finally' if on the same line +sp_brace_finally = ignore # ignore/add/remove/force + +# Add or remove space between 'try' and '{' if on the same line +sp_try_brace = ignore # ignore/add/remove/force + +# Add or remove space between get/set and '{' if on the same line +sp_getset_brace = ignore # ignore/add/remove/force + +# Add or remove space before the '::' operator +sp_before_dc = remove # ignore/add/remove/force + +# Add or remove space after the '::' operator +sp_after_dc = remove # ignore/add/remove/force + +# Add or remove around the D named array initializer ':' operator +sp_d_array_colon = ignore # ignore/add/remove/force + +# Add or remove space after the '!' (not) operator. +sp_not = remove # ignore/add/remove/force + +# Add or remove space after the '~' (invert) operator. +sp_inv = remove # ignore/add/remove/force + +# Add or remove space after the '&' (address-of) operator. +# This does not affect the spacing after a '&' that is part of a type. +sp_addr = remove # ignore/add/remove/force + +# Add or remove space around the '.' or '->' operators +sp_member = remove # ignore/add/remove/force + +# Add or remove space after the '*' (dereference) operator. +# This does not affect the spacing after a '*' that is part of a type. +sp_deref = remove # ignore/add/remove/force + +# Add or remove space after '+' or '-', as in 'x = -5' or 'y = +7' +sp_sign = remove # ignore/add/remove/force + +# Add or remove space before or after '++' and '--', as in '(--x)' or 'y++;' +sp_incdec = remove # ignore/add/remove/force + +# Add or remove space before a backslash-newline at the end of a line +sp_before_nl_cont = force # ignore/add/remove/force + +# Add or remove space after the scope '+' or '-', as in '-(void) foo;' or '+(int) bar;' +sp_after_oc_scope = ignore # ignore/add/remove/force + +# Add or remove space after the colon in message specs +# '-(int) f:(int) x;' vs '-(int) f: (int) x;' +sp_after_oc_colon = ignore # ignore/add/remove/force + +# Add or remove space before the colon in message specs +# '-(int) f: (int) x;' vs '-(int) f : (int) x;' +sp_before_oc_colon = ignore # ignore/add/remove/force + +# Add or remove space after the colon in message specs +# '[object setValue:1];' vs '[object setValue: 1];' +sp_after_send_oc_colon = ignore # ignore/add/remove/force + +# Add or remove space before the colon in message specs +# '[object setValue:1];' vs '[object setValue :1];' +sp_before_send_oc_colon = ignore # ignore/add/remove/force + +# Add or remove space after the (type) in message specs +# '-(int) f: (int) x;' vs '-(int) f: (int)x;' +sp_after_oc_type = ignore # ignore/add/remove/force + +# Add or remove space around the ':' in 'b ? t : f' +sp_cond_colon = ignore # ignore/add/remove/force + +# Add or remove space around the '?' in 'b ? t : f' +sp_cond_question = ignore # ignore/add/remove/force + +# Fix the spacing between 'case' and the label. Only 'ignore' and 'force' make sense here. +sp_case_label = ignore # ignore/add/remove/force + +# Control the space around the D '..' operator. +sp_range = ignore # ignore/add/remove/force + +# Control the space after the opening of a C++ comment '// A' vs '//A' +sp_cmt_cpp_start = ignore # ignore/add/remove/force + +# +# Code alignment (not left column spaces/tabs) +# + +# Whether to keep non-indenting tabs +align_keep_tabs = false # false/true + +# Whether to use tabs for alinging +align_with_tabs = false # false/true + +# Whether to bump out to the next tab when aligning +align_on_tabstop = false # false/true + +# Whether to left-align numbers +align_number_left = false # false/true + +# Align variable definitions in prototypes and functions +align_func_params = false # false/true + +# Align parameters in single-line functions that have the same name. +# The function names must already be aligned with each other. +align_same_func_call_params = false # false/true + +# The span for aligning variable definitions (0=don't align) +align_var_def_span = 1 # number + +# How to align the star in variable definitions. +# 0=Part of the type 'void * foo;' +# 1=Part of the variable 'void *foo;' +# 2=Dangling 'void *foo;' +align_var_def_star_style = 2 # number + +# How to align the '&' in variable definitions. +# 0=Part of the type +# 1=Part of the variable +# 2=Dangling +align_var_def_amp_style = 2 # number + +# The threshold for aligning variable definitions (0=no limit) +align_var_def_thresh = 5 # number + +# The gap for aligning variable definitions +align_var_def_gap = 1 # number + +# Whether to align the colon in struct bit fields +align_var_def_colon = false # false/true + +# Whether to align any attribute after the variable name +align_var_def_attribute = false # false/true + +# Whether to align inline struct/enum/union variable definitions +align_var_def_inline = false # false/true + +# The span for aligning on '=' in assignments (0=don't align) +align_assign_span = 1 # number + +# The threshold for aligning on '=' in assignments (0=no limit) +align_assign_thresh = 5 # number + +# The span for aligning on '=' in enums (0=don't align) +align_enum_equ_span = 1 # number + +# The threshold for aligning on '=' in enums (0=no limit) +align_enum_equ_thresh = 5 # number + +# The span for aligning struct/union (0=don't align) +align_var_struct_span = 1 # number + +# The threshold for aligning struct/union member definitions (0=no limit) +align_var_struct_thresh = 5 # number + +# The gap for aligning struct/union member definitions +align_var_struct_gap = 0 # number + +# The span for aligning struct initializer values (0=don't align) +align_struct_init_span = 1 # number + +# The minimum space between the type and the synonym of a typedef +align_typedef_gap = 0 # number + +# The span for aligning single-line typedefs (0=don't align) +align_typedef_span = 1 # number + +# How to align typedef'd functions with other typedefs +# 0: Don't mix them at all +# 1: align the open paren with the types +# 2: align the function type name with the other type names +align_typedef_func = 0 # number + +# Controls the positioning of the '*' in typedefs. Just try it. +# 0: Align on typdef type, ignore '*' +# 1: The '*' is part of type name: typedef int *pint; +# 2: The '*' is part of the type, but dangling: typedef int *pint; +align_typedef_star_style = 0 # number + +# Controls the positioning of the '&' in typedefs. Just try it. +# 0: Align on typdef type, ignore '&' +# 1: The '&' is part of type name: typedef int &pint; +# 2: The '&' is part of the type, but dangling: typedef int &pint; +align_typedef_amp_style = 0 # number + +# The span for aligning comments that end lines (0=don't align) +align_right_cmt_span = 0 # number + +# If aligning comments, mix with comments after '}' and #endif with less than 3 spaces before the comment +align_right_cmt_mix = false # false/true + +# If a trailing comment is more than this number of columns away from the text it follows, +# it will qualify for being aligned. +align_right_cmt_gap = 0 # number + +# Align trailing comment at or beyond column N; 'pulls in' comments as a bonus side effect (0=ignore) +align_right_cmt_at_col = 0 # number + +# The span for aligning function prototypes (0=don't align) +align_func_proto_span = 0 # number + +# Minimum gap between the return type and the function name. +align_func_proto_gap = 0 # number + +# Align function protos on the 'operator' keyword instead of what follows +align_on_operator = false # false/true + +# Whether to mix aligning prototype and variable declarations. +# If true, align_var_def_XXX options are used instead of align_func_proto_XXX options. +align_mix_var_proto = false # false/true + +# Align single-line functions with function prototypes, uses align_func_proto_span +align_single_line_func = false # false/true + +# Aligning the open brace of single-line functions. +# Requires align_single_line_func=true, uses align_func_proto_span +align_single_line_brace = false # false/true + +# Gap for align_single_line_brace. +align_single_line_brace_gap = 0 # number + +# The span for aligning ObjC msg spec (0=don't align) +align_oc_msg_spec_span = 0 # number + +# Whether to align macros wrapped with a backslash and a newline. +# This will not work right if the macro contains a multi-line comment. +align_nl_cont = false # false/true + +# The minimum space between label and value of a preprocessor define +align_pp_define_gap = 0 # number + +# The span for aligning on '#define' bodies (0=don't align) +align_pp_define_span = 0 # number + +# Align lines that start with '<<' with previous '<<'. Default=true +align_left_shift = true # false/true + +# +# Newline adding and removing options +# + +# Whether to collapse empty blocks between '{' and '}' +nl_collapse_empty_body = true # false/true + +# Don't split one-line braced assignments - 'foo_t f = { 1, 2 };' +nl_assign_leave_one_liners = true # false/true + +# Don't split one-line braced statements inside a class xx { } body +nl_class_leave_one_liners = false # false/true + +# Don't split one-line enums: 'enum foo { BAR = 15 };' +nl_enum_leave_one_liners = false # false/true + +# Don't split one-line get or set functions +nl_getset_leave_one_liners = true # false/true + +# Don't split one-line function definitions - 'int foo() { return 0; }' +nl_func_leave_one_liners = true # false/true + +# Don't split one-line if/else statements - 'if(a) b++;' +nl_if_leave_one_liners = false # false/true + +# Add or remove newlines at the start of the file +nl_start_of_file = ignore # ignore/add/remove/force + +# The number of newlines at the start of the file (only used if nl_start_of_file is 'add' or 'force' +nl_start_of_file_min = 0 # number + +# Add or remove newline at the end of the file +nl_end_of_file = force # ignore/add/remove/force + +# The number of newlines at the end of the file (only used if nl_end_of_file is 'add' or 'force') +nl_end_of_file_min = 1 # number + +# Add or remove newline between '=' and '{' +nl_assign_brace = ignore # ignore/add/remove/force + +# Add or remove newline between '=' and '[' (D only) +nl_assign_square = ignore # ignore/add/remove/force + +# Add or remove newline after '= [' (D only). Will also affect the newline before the ']' +nl_after_square_assign = ignore # ignore/add/remove/force + +# The number of newlines after a block of variable definitions +nl_func_var_def_blk = 0 # number + +# Add or remove newline between a function call's ')' and '{', as in: +# list_for_each(item, &list) { } +nl_fcall_brace = force # ignore/add/remove/force + +# Add or remove newline between 'enum' and '{' +nl_enum_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'struct and '{' +nl_struct_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'union' and '{' +nl_union_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'if' and '{' +nl_if_brace = remove # ignore/add/remove/force + +# Add or remove newline between '}' and 'else' +nl_brace_else = force # ignore/add/remove/force + +# Add or remove newline between 'else if' and '{' +# If set to ignore, nl_if_brace is used instead +nl_elseif_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'else' and '{' +nl_else_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'else' and 'if' +nl_else_if = add # ignore/add/remove/force + +# Add or remove newline between '}' and 'finally' +nl_brace_finally = force # ignore/add/remove/force + +# Add or remove newline between 'finally' and '{' +nl_finally_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'try' and '{' +nl_try_brace = remove # ignore/add/remove/force + +# Add or remove newline between get/set and '{' +nl_getset_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'for' and '{' +nl_for_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'catch' and '{' +nl_catch_brace = remove # ignore/add/remove/force + +# Add or remove newline between '}' and 'catch' +nl_brace_catch = force # ignore/add/remove/force + +# Add or remove newline between 'while' and '{' +nl_while_brace = remove # ignore/add/remove/force + +# Add or remove newline between 'do' and '{' +nl_do_brace = remove # ignore/add/remove/force + +# Add or remove newline between '}' and 'while' of 'do' statement +nl_brace_while = remove # ignore/add/remove/force + +# Add or remove newline between 'switch' and '{' +nl_switch_brace = remove # ignore/add/remove/force + +# Add a newline between ')' and '{' if the ')' is on a different line than the if/for/etc. +# Overrides nl_for_brace, nl_if_brace, nl_switch_brace, nl_while_switch, and nl_catch_brace. +nl_multi_line_cond = false # false/true + +# Force a newline in a define after the macro name for multi-line defines. +nl_multi_line_define = false # false/true + +# Whether to put a newline before 'case' statement +nl_before_case = false # false/true + +# Add or remove newline between ')' and 'throw' +nl_before_throw = ignore # ignore/add/remove/force + +# Whether to put a newline after 'case' statement +nl_after_case = false # false/true + +# Newline between namespace and { +nl_namespace_brace = ignore # ignore/add/remove/force + +# Add or remove newline between 'template<>' and whatever follows. +nl_template_class = ignore # ignore/add/remove/force + +# Add or remove newline between 'class' and '{' +nl_class_brace = force # ignore/add/remove/force + +# Add or remove newline after each ',' in the constructor member initialization +nl_class_init_args = ignore # ignore/add/remove/force + +# Add or remove newline between return type and function name in definition +nl_func_type_name = ignore # ignore/add/remove/force + +# Add or remove newline between function scope and name in a definition +# Controls the newline after '::' in 'void A::f() { }' +nl_func_scope_name = ignore # ignore/add/remove/force + +# Add or remove newline between return type and function name in a prototype +nl_func_proto_type_name = ignore # ignore/add/remove/force + +# Add or remove newline between a function name and the opening '(' +nl_func_paren = remove # ignore/add/remove/force + +# Add or remove newline after '(' in a function declaration +nl_func_decl_start = ignore # ignore/add/remove/force + +# Add or remove newline after each ',' in a function declaration +nl_func_decl_args = ignore # ignore/add/remove/force + +# Add or remove newline before the ')' in a function declaration +nl_func_decl_end = ignore # ignore/add/remove/force + +# Add or remove newline between function signature and '{' +nl_fdef_brace = ignore # ignore/add/remove/force + +# Whether to put a newline after 'return' statement +nl_after_return = false # false/true + +# Add or remove a newline between the return keyword and return expression. +nl_return_expr = ignore # ignore/add/remove/force + +# Whether to put a newline after semicolons, except in 'for' statements +nl_after_semicolon = false # false/true + +# Whether to put a newline after brace open. +# This also adds a newline before the matching brace close. +nl_after_brace_open = true # false/true + +# If nl_after_brace_open and nl_after_brace_open_cmt are true, a newline is +# placed between the open brace and a trailing single-line comment. +nl_after_brace_open_cmt = false # false/true + +# Whether to put a newline after a virtual brace open. +# These occur in un-braced if/while/do/for statement bodies. +nl_after_vbrace_open = true # false/true + +# Whether to put a newline after a brace close. +# Does not apply if followed by a necessary ';'. +nl_after_brace_close = false # false/true + +# Whether to alter newlines in '#define' macros +nl_define_macro = false # false/true + +# Whether to not put blanks after '#ifxx', '#elxx', or before '#endif' +nl_squeeze_ifdef = false # false/true + +# Add or remove newline before 'if' +nl_before_if = ignore # ignore/add/remove/force + +# Add or remove newline after 'if' +nl_after_if = ignore # ignore/add/remove/force + +# Add or remove newline before 'for' +nl_before_for = ignore # ignore/add/remove/force + +# Add or remove newline after 'for' +nl_after_for = ignore # ignore/add/remove/force + +# Add or remove newline before 'while' +nl_before_while = ignore # ignore/add/remove/force + +# Add or remove newline after 'while' +nl_after_while = ignore # ignore/add/remove/force + +# Add or remove newline before 'switch' +nl_before_switch = ignore # ignore/add/remove/force + +# Add or remove newline after 'switch' +nl_after_switch = ignore # ignore/add/remove/force + +# Add or remove newline before 'do' +nl_before_do = ignore # ignore/add/remove/force + +# Add or remove newline after 'do' +nl_after_do = ignore # ignore/add/remove/force + +# Whether to double-space commented-entries in struct/enum +nl_ds_struct_enum_cmt = false # false/true + +# Whether to double-space before the close brace of a struct/union/enum +nl_ds_struct_enum_close_brace = false # false/true + +# Add or remove a newline around a class colon. +# Related to pos_class_colon, nl_class_init_args, and pos_comma. +nl_class_colon = ignore # ignore/add/remove/force + +# Change simple unbraced if statements into a one-liner +# 'if(b)\n i++;' => 'if(b) i++;' +nl_create_if_one_liner = false # false/true + +# Change simple unbraced for statements into a one-liner +# 'for (i=0;i<5;i++)\n foo(i);' => 'for (i=0;i<5;i++) foo(i);' +nl_create_for_one_liner = false # false/true + +# Change simple unbraced while statements into a one-liner +# 'while (i<5)\n foo(i++);' => 'while (i<5) foo(i++);' +nl_create_while_one_liner = false # false/true + +# +# Positioning options +# + +# The position of arithmetic operators in wrapped expressions +pos_arith = lead # ignore/lead/trail + +# The position of assignment in wrapped expressions +pos_assign = trail # ignore/lead/trail + +# The position of boolean operators in wrapped expressions +pos_bool = lead # ignore/lead/trail + +# The position of the comma in wrapped expressions +pos_comma = trail # ignore/lead/trail + +# The position of the comma in the constructor initialization list +pos_class_comma = trail # ignore/lead/trail + +# The position of colons between constructor and member initialization +pos_class_colon = lead # ignore/lead/trail + +# +# Line Splitting options +# + +# Try to limit code width to N number of columns +code_width = 80 # number + +# Whether to fully split long 'for' statements at semi-colons +ls_for_split_full = true # false/true + +# Whether to fully split long function protos/calls at commas +ls_func_split_full = true # false/true + +# +# Blank line options +# + +# The maximum consecutive newlines +nl_max = 0 # number + +# The number of newlines after a function prototype, if followed by another function prototype +nl_after_func_proto = 0 # number + +# The number of newlines after a function prototype, if not followed by another function prototype +nl_after_func_proto_group = 0 # number + +# The number of newlines after '}' of a multi-line function body +nl_after_func_body = 0 # number + +# The number of newlines after '}' of a single line function body +nl_after_func_body_one_liner = 0 # number + +# The minimum number of newlines before a multi-line comment. +# Doesn't apply if after a brace open or another multi-line comment. +nl_before_block_comment = 0 # number + +# The minimum number of newlines before a single-line C comment. +# Doesn't apply if after a brace open or other single-line C comments. +nl_before_c_comment = 0 # number + +# The minimum number of newlines before a CPP comment. +# Doesn't apply if after a brace open or other CPP comments. +nl_before_cpp_comment = 0 # number + +# Whether to force a newline after a mulit-line comment. +nl_after_multiline_comment = false # false/true + +# The number of newlines before a 'private:', 'public:', 'protected:', 'signals:', or 'slots:' label. +# Will not change the newline count if after a brace open. +# 0 = No change. +nl_before_access_spec = 0 # number + +# The number of newlines after a 'private:', 'public:', 'protected:', 'signals:', or 'slots:' label. +# 0 = No change. +nl_after_access_spec = 0 # number + +# The number of newlines between a function def and the function comment. +# 0 = No change. +nl_comment_func_def = 0 # number + +# The number of newlines after a try-catch-finally block that isn't followed by a brace close. +# 0 = No change. +nl_after_try_catch_finally = 0 # number + +# The number of newlines before and after a property, indexer or event decl. +# 0 = No change. +nl_around_cs_property = 0 # number + +# The number of newlines between the get/set/add/remove handlers in C#. +# 0 = No change. +nl_between_get_set = 0 # number + +# Whether to remove blank lines after '{' +eat_blanks_after_open_brace = true # false/true + +# Whether to remove blank lines before '}' +eat_blanks_before_close_brace = true # false/true + +# +# Code modifying options (non-whitespace) +# + +# Add or remove braces on single-line 'do' statement +mod_full_brace_do = ignore # ignore/add/remove/force + +# Add or remove braces on single-line 'for' statement +mod_full_brace_for = remove # ignore/add/remove/force + +# Add or remove braces on single-line function defintions. (Pawn) +mod_full_brace_function = ignore # ignore/add/remove/force + +# Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'. +mod_full_brace_if = remove # ignore/add/remove/force + +# Don't remove braces around statements that span N newlines +mod_full_brace_nl = 0 # number + +# Add or remove braces on single-line 'while' statement +mod_full_brace_while = ignore # ignore/add/remove/force + +# Add or remove unnecessary paren on 'return' statement +mod_paren_on_return = remove # ignore/add/remove/force + +# Whether to change optional semicolons to real semicolons +mod_pawn_semicolon = false # false/true + +# Add parens on 'while' and 'if' statement around bools +mod_full_paren_if_bool = true # false/true + +# Whether to remove superfluous semicolons +mod_remove_extra_semicolon = true # false/true + +# If a function body exceeds the specified number of newlines and doesn't have a comment after +# the close brace, a comment will be added. +mod_add_long_function_closebrace_comment = 0 # number + +# If a switch body exceeds the specified number of newlines and doesn't have a comment after +# the close brace, a comment will be added. +mod_add_long_switch_closebrace_comment = 0 # number + +# If an #ifdef body exceeds the specified number of newlines and doesn't have a comment after +# the #else, a comment will be added. +mod_add_long_ifdef_endif_comment = 0 # number + +# If an #ifdef or #else body exceeds the specified number of newlines and doesn't have a comment after +# the #endif, a comment will be added. +mod_add_long_ifdef_else_comment = 0 # number + +# If TRUE, will sort consecutive single-line 'import' statements [Java, D] +mod_sort_import = false # false/true + +# If TRUE, will sort consecutive single-line 'using' statements [C#] +mod_sort_using = false # false/true + +# If TRUE, will sort consecutive single-line '#include' statements [C/C++] and '#import' statements [Obj-C] +# This is generally a bad idea, as it may break your code. +mod_sort_include = false # false/true + +# If TRUE, it will move a 'break' that appears after a fully braced 'case' before the close brace. +mod_move_case_break = false # false/true + +# If TRUE, it will remove a void 'return;' that appears as the last statement in a function. +mod_remove_empty_return = false # false/true + +# +# Comment modifications +# + +# Try to wrap comments at cmt_width columns +cmt_width = 0 # number + +# If false, disable all multi-line comment changes, including cmt_width and leading chars. +# Default is true. +cmt_indent_multi = false # false/true + +# Whether to group c-comments that look like they are in a block +cmt_c_group = false # false/true + +# Whether to put an empty '/*' on the first line of the combined c-comment +cmt_c_nl_start = false # false/true + +# Whether to put a newline before the closing '*/' of the combined c-comment +cmt_c_nl_end = false # false/true + +# Whether to group cpp-comments that look like they are in a block +cmt_cpp_group = false # false/true + +# Whether to put an empty '/*' on the first line of the combined cpp-comment +cmt_cpp_nl_start = false # false/true + +# Whether to put a newline before the closing '*/' of the combined cpp-comment +cmt_cpp_nl_end = false # false/true + +# Whether to change cpp-comments into c-comments +cmt_cpp_to_c = false # false/true + +# Whether to put a star on subsequent comment lines +cmt_star_cont = false # false/true + +# The number of spaces to insert at the start of subsequent comment lines +cmt_sp_before_star_cont = 0 # number + +# The number of spaces to insert after the star on subsequent comment lines +cmt_sp_after_star_cont = 1 # number + +# For multi-line comments with a '*' lead, remove leading spaces if the first and last lines of +# the comment are the same length. Default=True +cmt_multi_check_last = true # false/true + +# The filename that contains text to insert at the head of a file if the file doesn't start with a C/C++ comment. +# Will substitue $(filename) with the current file's name. +cmt_insert_file_header = "" # string + +# The filename that contains text to insert at the end of a file if the file doesn't end with a C/C++ comment. +# Will substitue $(filename) with the current file's name. +cmt_insert_file_footer = "" # string + +# The filename that contains text to insert before a function implementation if the function isn't preceeded with a C/C++ comment. +# Will substitue $(function) with the function name and $(javaparam) with the javadoc @param and @return stuff. +# Will also substitute $(fclass) with the class name: void CFoo::Bar() { ... } +cmt_insert_func_header = "" # string + +# The filename that contains text to insert before a class if the class isn't preceeded with a C/C++ comment. +# Will substitue $(class) with the class name. +cmt_insert_class_header = "" # string + +# If a preprocessor is encountered when stepping backwards from a function name, then +# this option decides whether the comment should be inserted. +# Affects cmt_insert_func_header and cmt_insert_class_header. +cmt_insert_before_preproc = false # false/true + +# +# Preprocessor options +# + +# Control indent of preprocessors inside #if blocks at brace level 0 +pp_indent = ignore # ignore/add/remove/force + +# Whether to indent #if/#else/#endif at the brace level (true) or from column 1 (false) +pp_indent_at_level = false # false/true + +# If pp_indent_at_level=false, specifies the number of columns to indent per level. Default=1. +pp_indent_count = 1 # number + +# Add or remove space after # based on pp_level of #if blocks +pp_space = ignore # ignore/add/remove/force + +# Sets the number of spaces added with pp_space +pp_space_count = 0 # number + +# The indent for #region and #endregion in C# and '#pragma region' in C/C++ +pp_indent_region = 0 # number + +# Whether to indent the code between #region and #endregion +pp_region_indent_code = false # false/true + +# If pp_indent_at_level=true, sets the indent for #if, #else, and #endif when not at file-level +pp_indent_if = 0 # number + +# Control whether to indent the code between #if, #else and #endif when not at file-level +pp_if_indent_code = false # false/true + +# Whether to indent '#define' at the brace level (true) or from column 1 (false) +pp_define_at_level = false # false/true + +# You can force a token to be a type with the 'type' option. +# Example: +# type myfoo1 myfoo2 +# +# You can create custom macro-based indentation using macro-open, +# macro-else and macro-close. +# Example: +# macro-open BEGIN_TEMPLATE_MESSAGE_MAP +# macro-open BEGIN_MESSAGE_MAP +# macro-close END_MESSAGE_MAP +# +# You can assign any keyword to any type with the set option. +# set func_call_user _ N_ +# +# The full syntax description of all custom definition config entries +# is shown below: +# +# define custom tokens as: +# - embed whitespace in token using '' escape character, or +# put token in quotes +# - these: ' " and ` are recognized as quote delimiters +# +# type token1 token2 token3 ... +# ^ optionally specify multiple tokens on a single line +# define def_token output_token +# ^ output_token is optional, then NULL is assumed +# macro-open token +# macro-close token +# macro-else token +# set id token1 token2 ... +# ^ optionally specify multiple tokens on a single line +# ^ id is one of the names in token_enum.h sans the CT_ prefix, +# e.g. PP_PRAGMA +# +# all tokens are separated by any mix of ',' commas, '=' equal signs +# and whitespace (space, tab) +# diff --git a/style.sh b/style.sh new file mode 100755 index 00000000..0b48a86b --- /dev/null +++ b/style.sh @@ -0,0 +1,3 @@ +#!/bin/sh +uncrustify -c style.cfg --no-backup -l CPP `find . | grep -e "\.h$"` +uncrustify -c style.cfg --no-backup -l CPP `find . | grep -e "\.cpp$"`