--- linuxsampler/trunk/src/engines/gig/Voice.cpp 2006/05/14 07:15:52 865 +++ linuxsampler/trunk/src/engines/gig/Voice.cpp 2006/10/02 18:40:10 922 @@ -29,12 +29,6 @@ namespace LinuxSampler { namespace gig { - const float Voice::FILTER_CUTOFF_COEFF(CalculateFilterCutoffCoeff()); - - float Voice::CalculateFilterCutoffCoeff() { - return log(CONFIG_FILTER_CUTOFF_MAX / CONFIG_FILTER_CUTOFF_MIN); - } - Voice::Voice() { pEngine = NULL; pDiskThread = NULL; @@ -104,7 +98,10 @@ // calculate volume const double velocityAttenuation = pDimRgn->GetVelocityAttenuation(itNoteOnEvent->Param.Note.Velocity); - float volume = velocityAttenuation / 32768.0f; // we downscale by 32768 to convert from int16 value range to DSP value range (which is -1.0..1.0) + // For 16 bit samples, we downscale by 32768 to convert from + // int16 value range to DSP value range (which is + // -1.0..1.0). For 24 bit, we downscale from int32. + float volume = velocityAttenuation / (pSample->BitDepth == 16 ? 32768.0f : 32768.0f * 65536.0f); volume *= pDimRgn->SampleAttenuation; @@ -119,12 +116,14 @@ // select channel mode (mono or stereo) SYNTHESIS_MODE_SET_CHANNELS(SynthesisMode, pSample->Channels == 2); + // select bit depth (16 or 24) + SYNTHESIS_MODE_SET_BITDEPTH24(SynthesisMode, pSample->BitDepth == 24); // get starting crossfade volume level float crossfadeVolume; switch (pDimRgn->AttenuationController.type) { case ::gig::attenuation_ctrl_t::type_channelaftertouch: - crossfadeVolume = 1.0f; //TODO: aftertouch not supported yet + crossfadeVolume = Engine::CrossfadeCurve[CrossfadeAttenuation(pEngineChannel->ControllerTable[128])]; break; case ::gig::attenuation_ctrl_t::type_velocity: crossfadeVolume = Engine::CrossfadeCurve[CrossfadeAttenuation(itNoteOnEvent->Param.Note.Velocity)]; @@ -201,7 +200,7 @@ eg1controllervalue = 0; break; case ::gig::eg1_ctrl_t::type_channelaftertouch: - eg1controllervalue = 0; // TODO: aftertouch not yet supported + eg1controllervalue = pEngineChannel->ControllerTable[128]; break; case ::gig::eg1_ctrl_t::type_velocity: eg1controllervalue = itNoteOnEvent->Param.Note.Velocity; @@ -259,7 +258,7 @@ eg2controllervalue = 0; break; case ::gig::eg2_ctrl_t::type_channelaftertouch: - eg2controllervalue = 0; // TODO: aftertouch not yet supported + eg2controllervalue = pEngineChannel->ControllerTable[128]; break; case ::gig::eg2_ctrl_t::type_velocity: eg2controllervalue = itNoteOnEvent->Param.Note.Velocity; @@ -339,7 +338,7 @@ } if (bLFO1Enabled) { pLFO1->trigger(pDimRgn->LFO1Frequency, - start_level_max, + start_level_min, lfo1_internal_depth, pDimRgn->LFO1ControlDepth, pDimRgn->LFO1FlipPhase, @@ -411,8 +410,8 @@ break; case ::gig::lfo3_ctrl_aftertouch: lfo3_internal_depth = 0; - pLFO3->ExtController = 0; // TODO: aftertouch not implemented yet - bLFO3Enabled = false; // see TODO comment in line above + pLFO3->ExtController = 128; + bLFO3Enabled = true; break; case ::gig::lfo3_ctrl_internal_modwheel: lfo3_internal_depth = pDimRgn->LFO3InternalDepth; @@ -421,8 +420,8 @@ break; case ::gig::lfo3_ctrl_internal_aftertouch: lfo3_internal_depth = pDimRgn->LFO3InternalDepth; - pLFO1->ExtController = 0; // TODO: aftertouch not implemented yet - bLFO3Enabled = (lfo3_internal_depth > 0 /*|| pDimRgn->LFO3ControlDepth > 0*/); // see TODO comment in line above + pLFO1->ExtController = 128; + bLFO3Enabled = (lfo3_internal_depth > 0 || pDimRgn->LFO3ControlDepth > 0); break; default: lfo3_internal_depth = 0; @@ -479,7 +478,9 @@ case ::gig::vcf_cutoff_ctrl_genpurpose8: VCFCutoffCtrl.controller = 83; break; - case ::gig::vcf_cutoff_ctrl_aftertouch: //TODO: not implemented yet + case ::gig::vcf_cutoff_ctrl_aftertouch: + VCFCutoffCtrl.controller = 128; + break; case ::gig::vcf_cutoff_ctrl_none: default: VCFCutoffCtrl.controller = 0; @@ -537,15 +538,13 @@ else { cvalue = pDimRgn->VCFCutoff; } - cutoff *= float(cvalue) * 0.00787402f; // (1 / 127) - if (cutoff > 1.0) cutoff = 1.0; - cutoff = (cutoff < 0.5 ? cutoff * 4826 - 1 : cutoff * 5715 - 449); - if (cutoff < 1.0) cutoff = 1.0; + cutoff *= float(cvalue); + if (cutoff > 127.0f) cutoff = 127.0f; // calculate resonance - float resonance = (float) (VCFResonanceCtrl.controller ? VCFResonanceCtrl.value : pDimRgn->VCFResonance) * 0.00787f; // 0.0..1.0 + float resonance = (float) (VCFResonanceCtrl.controller ? VCFResonanceCtrl.value : pDimRgn->VCFResonance); - VCFCutoffCtrl.fvalue = cutoff - 1.0; + VCFCutoffCtrl.fvalue = cutoff; VCFResonanceCtrl.fvalue = resonance; } else { @@ -622,7 +621,7 @@ } } - sample_t* ptr = DiskStreamRef.pStream->GetReadPtr(); // get the current read_ptr within the ringbuffer where we read the samples from + sample_t* ptr = (sample_t*)DiskStreamRef.pStream->GetReadPtr(); // get the current read_ptr within the ringbuffer where we read the samples from // render current audio fragment Synthesize(Samples, ptr, Delay); @@ -743,12 +742,10 @@ VCFCutoffCtrl.value == ccvalue; if (pDimRgn->VCFCutoffControllerInvert) ccvalue = 127 - ccvalue; if (ccvalue < pDimRgn->VCFVelocityScale) ccvalue = pDimRgn->VCFVelocityScale; - float cutoff = CutoffBase * float(ccvalue) * 0.00787402f; // (1 / 127) - if (cutoff > 1.0) cutoff = 1.0; - cutoff = (cutoff < 0.5 ? cutoff * 4826 - 1 : cutoff * 5715 - 449); - if (cutoff < 1.0) cutoff = 1.0; + float cutoff = CutoffBase * float(ccvalue); + if (cutoff > 127.0f) cutoff = 127.0f; - VCFCutoffCtrl.fvalue = cutoff - 1.0; // needed for initialization of fFinalCutoff next time + VCFCutoffCtrl.fvalue = cutoff; // needed for initialization of fFinalCutoff next time fFinalCutoff = cutoff; } @@ -756,10 +753,10 @@ // convert absolute controller value to differential const int ctrldelta = itEvent->Param.CC.Value - VCFResonanceCtrl.value; VCFResonanceCtrl.value = itEvent->Param.CC.Value; - const float resonancedelta = (float) ctrldelta * 0.00787f; // 0.0..1.0 + const float resonancedelta = (float) ctrldelta; fFinalResonance += resonancedelta; // needed for initialization of parameter - VCFResonanceCtrl.fvalue = itEvent->Param.CC.Value * 0.00787f; + VCFResonanceCtrl.fvalue = itEvent->Param.CC.Value; } /** @@ -838,14 +835,14 @@ if (EG3.active()) finalSynthesisParameters.fFinalPitch *= EG3.render(); // process low frequency oscillators - if (bLFO1Enabled) fFinalVolume *= pLFO1->render(); + if (bLFO1Enabled) fFinalVolume *= (1.0f - pLFO1->render()); if (bLFO2Enabled) fFinalCutoff *= pLFO2->render(); if (bLFO3Enabled) finalSynthesisParameters.fFinalPitch *= RTMath::CentsToFreqRatio(pLFO3->render()); // if filter enabled then update filter coefficients if (SYNTHESIS_MODE_GET_FILTER(SynthesisMode)) { - finalSynthesisParameters.filterLeft.SetParameters(fFinalCutoff + 1.0, fFinalResonance, pEngine->SampleRate); - finalSynthesisParameters.filterRight.SetParameters(fFinalCutoff + 1.0, fFinalResonance, pEngine->SampleRate); + finalSynthesisParameters.filterLeft.SetParameters(fFinalCutoff, fFinalResonance, pEngine->SampleRate); + finalSynthesisParameters.filterRight.SetParameters(fFinalCutoff, fFinalResonance, pEngine->SampleRate); } // do we need resampling?