diff --git a/src/effect_compressor.cpp b/src/effect_compressor.cpp index 785e1a9..d2aaec7 100644 --- a/src/effect_compressor.cpp +++ b/src/effect_compressor.cpp @@ -37,12 +37,7 @@ void Compressor::setDefaultValues(const float32_t sample_rate_Hz) { void Compressor::calcInstantaneousTargetGain(float32_t *audio_level_dB_block, float32_t *inst_targ_gain_dB_block, uint16_t len) { // how much are we above the compression threshold? - float32_t* above_thresh_dB_block=(float32_t*)malloc(sizeof(float32_t)*len); - if(!above_thresh_dB_block) - { - LOGERR("Cannot allocate memory for \"above_thresh_dB_block\" - stopping\n"); - while(1); - } + float32_t above_thresh_dB_block[len]; //arm_copy_f32(zeroblock_f32,above_thresh_dB_block,len); @@ -68,10 +63,6 @@ void Compressor::calcInstantaneousTargetGain(float32_t *audio_level_dB_block, fl if (inst_targ_gain_dB_block[i] > 0.0f) inst_targ_gain_dB_block[i] = 0.0f; } - // release memory before returning - if(above_thresh_dB_block) - delete(above_thresh_dB_block); - return; //output is passed through inst_targ_gain_dB_block } @@ -105,12 +96,7 @@ void Compressor::calcSmoothedGain_dB(float32_t *inst_targ_gain_dB_block, float32 void Compressor::calcAudioLevel_dB(float32_t *wav_block, float32_t *level_dB_block, uint16_t len) { // calculate the instantaneous signal power (square the signal) - float32_t* wav_pow_block=(float32_t*)malloc(sizeof(float32_t)*len); - if(!wav_pow_block) - { - LOGERR("Cannot allocate memory for \"wav_pow_block\" - stopping\n"); - while(1); - } + float32_t wav_pow_block[len]; //arm_copy_f32(zeroblock_f32,wav_pow_block,len); @@ -135,10 +121,6 @@ void Compressor::calcAudioLevel_dB(float32_t *wav_block, float32_t *level_dB_blo //scale the wav_pow_block by 10.0 to complete the conversion to dB arm_scale_f32(level_dB_block, 10.0f, level_dB_block, len); //use ARM DSP for speed! - //release memory and return - if(wav_pow_block) - delete(wav_pow_block); - return; //output is passed through level_dB_block } @@ -147,23 +129,13 @@ void Compressor::calcAudioLevel_dB(float32_t *wav_block, float32_t *level_dB_blo void Compressor::calcGain(float32_t *audio_level_dB_block, float32_t *gain_block,uint16_t len) { //first, calculate the instantaneous target gain based on the compression ratio - float32_t* inst_targ_gain_dB_block=(float32_t*)malloc(sizeof(float32_t)*len); - if(!inst_targ_gain_dB_block) - { - LOGERR("Cannot allocate memory for \"inst_targ_gain_dB_block\" - stopping\n"); - while(1); - } + float32_t inst_targ_gain_dB_block[len]; //arm_copy_f32(zeroblock_f32,inst_targ_gain_dB_block,len); calcInstantaneousTargetGain(audio_level_dB_block, inst_targ_gain_dB_block,len); //second, smooth in time (attack and release) by stepping through each sample - float32_t *gain_dB_block = (float32_t*)malloc(sizeof(float32_t)*len); - if(!gain_dB_block) - { - LOGERR("Cannot allocate memory for \"gain_dB_block\" - stopping\n"); - while(1); - } + float32_t gain_dB_block[len]; //arm_copy_f32(zeroblock_f32,gain_dB_block,len); calcSmoothedGain_dB(inst_targ_gain_dB_block,gain_dB_block, len); @@ -172,13 +144,6 @@ void Compressor::calcGain(float32_t *audio_level_dB_block, float32_t *gain_block arm_scale_f32(gain_dB_block, 1.0f/20.0f, gain_dB_block, len); //divide by 20 for (uint16_t i = 0; i < len; i++) gain_block[i] = pow10f(gain_dB_block[i]); //do the 10^(x) - - //release memory and return - if(inst_targ_gain_dB_block) - delete(inst_targ_gain_dB_block); - if(gain_dB_block) - delete(gain_dB_block); - return; //output is passed through gain_block } @@ -186,7 +151,7 @@ void Compressor::calcGain(float32_t *audio_level_dB_block, float32_t *gain_block void Compressor::doCompression(float32_t *audio_block, uint16_t len) { //Serial.println("AudioEffectGain_F32: updating."); //for debugging. if (!audio_block) { - LOGERR("No audio_block available for Compressor!\n"); + LOGERR("No audio_block available for Compressor!"); return; } @@ -199,41 +164,21 @@ void Compressor::doCompression(float32_t *audio_block, uint16_t len) { arm_scale_f32(audio_block, pre_gain, audio_block, len); //use ARM DSP for speed! //calculate the level of the audio (ie, calculate a smoothed version of the signal power) - float32_t* audio_level_dB_block = (float32_t*)malloc(sizeof(float32_t)*len); - if(!audio_level_dB_block) - { - LOGERR("Cannot allocate memory for \"audio_level_dB_block\" - stopping\n"); - while(1); - } + float32_t audio_level_dB_block[len]; //arm_copy_f32(zeroblock_f32,audio_level_dB_block,len); - if(audio_level_dB_block) - calcAudioLevel_dB(audio_block, audio_level_dB_block, len); //returns through audio_level_dB_block + calcAudioLevel_dB(audio_block, audio_level_dB_block, len); //returns through audio_level_dB_block //compute the desired gain based on the observed audio level - float32_t* gain_block=(float32_t*)malloc(sizeof(float32_t)*len); - if(!gain_block) - { - LOGERR("Cannot allocate memory for \"gain_block\" - stopping\n"); - while(1); - } + float32_t gain_block[len]; //arm_copy_f32(zeroblock_f32,gain_block,len); - if(gain_block) - { - calcGain(audio_level_dB_block, gain_block, len); //returns through gain_block - - //apply the desired gain...store the processed audio back into audio_block - arm_mult_f32(audio_block, gain_block, audio_block, len); - } + calcGain(audio_level_dB_block, gain_block, len); //returns through gain_block - //release memory - if(audio_level_dB_block) - delete(audio_level_dB_block); - if(gain_block) - delete(gain_block); + //apply the desired gain...store the processed audio back into audio_block + arm_mult_f32(audio_block, gain_block, audio_block, len); } //methods to set parameters of this module diff --git a/src/effect_mixer.hpp b/src/effect_mixer.hpp index 26e062c..f8e7865 100644 --- a/src/effect_mixer.hpp +++ b/src/effect_mixer.hpp @@ -24,28 +24,24 @@ public: for (uint8_t i=0; ipan(nTG,mapfloat(nPan,-99,99,0.0f,1.0f)); - reverb_send_mixer->pan(nTG,mapfloat(nPan,-99,99,0.0f,1.0f)); + tg_mixer->pan(nTG,mapfloat(nPan,0,127,0.0f,1.0f)); + reverb_send_mixer->pan(nTG,mapfloat(nPan,0,127,0.0f,1.0f)); m_UI.ParameterChanged (); } @@ -391,7 +391,7 @@ void CMiniDexed::SetReverbSend (unsigned nReverbSend, unsigned nTG) void CMiniDexed::SetMasterTune (int nMasterTune, unsigned nTG) { - constrain((int)nMasterTune,-99,99); + nMasterTune=constrain((int)nMasterTune,-99,99); assert (nTG < CConfig::ToneGenerators); m_nMasterTune[nTG] = nMasterTune; @@ -529,49 +529,49 @@ void CMiniDexed::SetParameter (TParameter Parameter, int nValue) break; case ParameterReverbEnable: - constrain((int)nValue,0,1); + nValue=constrain((int)nValue,0,1); m_ReverbSpinLock.Acquire (); reverb->set_bypass (!nValue); m_ReverbSpinLock.Release (); break; case ParameterReverbSize: - constrain((int)nValue,0,99); + nValue=constrain((int)nValue,0,99); m_ReverbSpinLock.Acquire (); reverb->size (nValue / 99.0f); m_ReverbSpinLock.Release (); break; case ParameterReverbHighDamp: - constrain((int)nValue,0,99); + nValue=constrain((int)nValue,0,99); m_ReverbSpinLock.Acquire (); reverb->hidamp (nValue / 99.0f); m_ReverbSpinLock.Release (); break; case ParameterReverbLowDamp: - constrain((int)nValue,0,99); + nValue=constrain((int)nValue,0,99); m_ReverbSpinLock.Acquire (); reverb->lodamp (nValue / 99.0f); m_ReverbSpinLock.Release (); break; case ParameterReverbLowPass: - constrain((int)nValue,0,99); + nValue=constrain((int)nValue,0,99); m_ReverbSpinLock.Acquire (); reverb->lowpass (nValue / 99.0f); m_ReverbSpinLock.Release (); break; case ParameterReverbDiffusion: - constrain((int)nValue,0,99); + nValue=constrain((int)nValue,0,99); m_ReverbSpinLock.Acquire (); reverb->diffusion (nValue / 99.0f); m_ReverbSpinLock.Release (); break; case ParameterReverbLevel: - constrain((int)nValue,0,99); + nValue=constrain((int)nValue,0,99); m_ReverbSpinLock.Acquire (); reverb->level (nValue / 99.0f); m_ReverbSpinLock.Release (); @@ -699,15 +699,9 @@ void CMiniDexed::ProcessSound (void) float32_t SampleBuffer[nFrames]; m_pTG[0]->getSamples (SampleBuffer, nFrames); - // Convert dual float array (left, right) to single int16 array (left/right) - float32_t tmp_float[nFrames*2]; - int16_t tmp_int[nFrames*2]; - for(uint16_t i=0; iWrite (tmp_int, sizeof(tmp_int)) != (int) sizeof(tmp_int)) { diff --git a/src/performanceconfig.cpp b/src/performanceconfig.cpp index c992ad3..124f2b3 100644 --- a/src/performanceconfig.cpp +++ b/src/performanceconfig.cpp @@ -154,6 +154,9 @@ bool CPerformanceConfig::Save (void) PropertyName.Format ("NoteShift%u", nTG+1); m_Properties.SetSignedNumber (PropertyName, m_nNoteShift[nTG]); + + PropertyName.Format ("ReverbSend%u", nTG+1); + m_Properties.SetNumber (PropertyName, m_nReverbSend[nTG]); } m_Properties.SetNumber ("CompressorEnable", m_bCompressorEnable ? 1 : 0); diff --git a/src/uimenu.cpp b/src/uimenu.cpp index fa38da5..92eeb02 100644 --- a/src/uimenu.cpp +++ b/src/uimenu.cpp @@ -158,6 +158,19 @@ const CUIMenu::TMenuItem CUIMenu::s_SaveMenu[] = {0} }; +// must match CMiniDexed::TParameter +const CUIMenu::TParameter CUIMenu::s_GlobalParameter[CMiniDexed::ParameterUnknown] = +{ + {0, 1, 1, ToOnOff}, // ParameterCompessorEnable + {0, 1, 1, ToOnOff}, // ParameterReverbEnable + {0, 99, 1}, // ParameterReverbSize + {0, 99, 1}, // ParameterReverbHighDamp + {0, 99, 1}, // ParameterReverbLowDamp + {0, 99, 1}, // ParameterReverbLowPass + {0, 99, 1}, // ParameterReverbDiffusion + {0, 99, 1} // ParameterReverbLevel +}; + // must match CMiniDexed::TTGParameter const CUIMenu::TParameter CUIMenu::s_TGParameter[CMiniDexed::TGParameterUnknown] = { @@ -170,17 +183,6 @@ const CUIMenu::TParameter CUIMenu::s_TGParameter[CMiniDexed::TGParameterUnknown] {0, 99, 1} // TGParameterReverbSend }; -// must match CMiniDexed::TTGParameter -const CUIMenu::TParameter CUIMenu::s_TGParameter[CMiniDexed::TGParameterUnknown] = -{ - {0, CSysExFileLoader::MaxVoiceBankID, 1}, // TGParameterVoiceBank - {0, CSysExFileLoader::VoicesPerBank-1, 1}, // TGParameterProgram - {0, 127, 8, ToVolume}, // TGParameterVolume - {0, 127, 8, ToPan}, // TGParameterPan - {-99, 99, 1}, // TGParameterMasterTune - {0, CMIDIDevice::ChannelUnknown-1, 1, ToMIDIChannel} // TGParameterMIDIChannel -}; - // must match DexedVoiceParameters in Synth_Dexed const CUIMenu::TParameter CUIMenu::s_VoiceParameter[] = {