From 2ae7aaef0fd34b6ad78c86bc923d0ed202571d9e Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Tue, 12 Dec 2023 12:46:26 -0500 Subject: [PATCH] VoiceEffect Init to PMD Default The initVoiceEffectParams() call now just initalizes to eh default values on the param meta data; the param meta data has correct default values. --- include/sst/voice-effects/VoiceEffectCore.h | 15 ++++++++++++ .../sst/voice-effects/distortion/BitCrusher.h | 23 ++++++++----------- .../sst/voice-effects/distortion/Microgate.h | 16 ++++--------- .../sst/voice-effects/waveshaper/WaveShaper.h | 11 ++------- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/include/sst/voice-effects/VoiceEffectCore.h b/include/sst/voice-effects/VoiceEffectCore.h index f9e30c1..e265fcd 100644 --- a/include/sst/voice-effects/VoiceEffectCore.h +++ b/include/sst/voice-effects/VoiceEffectCore.h @@ -139,6 +139,21 @@ template struct VoiceEffectTemplateBase : public VFXConfig: void preReservePool(size_t s) { VFXConfig::preReservePool(asBase(), s); } uint8_t *checkoutBlock(size_t s) { return VFXConfig::checkoutBlock(asBase(), s); } void returnBlock(uint8_t *d, size_t s) { VFXConfig::returnBlock(asBase(), d, s); } + + template void initToParamMetadataDefault(T *that) + { + for (int i = 0; i < T::numFloatParams; ++i) + { + that->setFloatParam(i, that->paramAt(i).defaultVal); + } + if constexpr (T::numIntParams) + { + for (int i = 0; i < T::numIntParams; ++i) + { + that->setIntParam(i, that->intParamAt(i).defaultVal); + } + } + } }; } // namespace sst::voice_effects::core diff --git a/include/sst/voice-effects/distortion/BitCrusher.h b/include/sst/voice-effects/distortion/BitCrusher.h index dc5a40e..9b2a6ed 100644 --- a/include/sst/voice-effects/distortion/BitCrusher.h +++ b/include/sst/voice-effects/distortion/BitCrusher.h @@ -58,15 +58,19 @@ template struct BitCrusher : core::VoiceEffectTemplateBase< switch ((bc_fparams)idx) { case bc_samplerate: - return pmd().asAudibleFrequency().withRange(-12, 80).withName("sampleRate"); + return pmd() + .asAudibleFrequency() + .withRange(-12, 80) + .withName("sampleRate") + .withDefault(7.5); case bc_bitdepth: - return pmd().asPercent().withName("bitdepth"); + return pmd().asPercent().withName("bitdepth").withDefault(1.f); case bc_zeropoint: - return pmd().asPercent().withName("zeropoint"); + return pmd().asPercent().withName("zeropoint").withDefault(0.f); case bc_cutoff: - return pmd().asAudibleFrequency().withName("cutoff"); + return pmd().asAudibleFrequency().withName("cutoff").withDefault(5.f); case bc_resonance: - return pmd().asPercent().withName("resonance"); + return pmd().asPercent().withName("resonance").withDefault(0.f); default: break; } @@ -74,14 +78,7 @@ template struct BitCrusher : core::VoiceEffectTemplateBase< return pmd().withName("Unknown " + std::to_string(idx)); } - void initVoiceEffectParams() - { - this->setFloatParam(bc_samplerate, 7.5f); - this->setFloatParam(bc_bitdepth, 1.f); - this->setFloatParam(bc_zeropoint, 0.f); - this->setFloatParam(bc_cutoff, 5.0f); - this->setFloatParam(bc_resonance, 0.f); - } + void initVoiceEffectParams() { this->initToParamMetadataDefault(this); } void processStereo(float *datainL, float *datainR, float *dataoutL, float *dataoutR, float pitch) diff --git a/include/sst/voice-effects/distortion/Microgate.h b/include/sst/voice-effects/distortion/Microgate.h index 810f474..38c5227 100644 --- a/include/sst/voice-effects/distortion/Microgate.h +++ b/include/sst/voice-effects/distortion/Microgate.h @@ -70,13 +70,13 @@ template struct MicroGate : core::VoiceEffectTemplateBase struct MicroGate : core::VoiceEffectTemplateBasesetFloatParam(0, -3.f); - this->setFloatParam(1, 0.5f); - this->setFloatParam(2, -12.f); - this->setFloatParam(3, -96.f); - } + void initVoiceEffectParams() { this->initToParamMetadataDefault(this); } void processStereo(float *datainL, float *datainR, float *dataoutL, float *dataoutR, float pitch) diff --git a/include/sst/voice-effects/waveshaper/WaveShaper.h b/include/sst/voice-effects/waveshaper/WaveShaper.h index 489ddbe..158c36d 100644 --- a/include/sst/voice-effects/waveshaper/WaveShaper.h +++ b/include/sst/voice-effects/waveshaper/WaveShaper.h @@ -96,7 +96,7 @@ template struct WaveShaper : core::VoiceEffectTemplateBase< .withRange(0, 2) .withName("Type") .withUnorderedMapFormatting({{0, "Soft"}, {1, "OJD"}, {2, "WCFold"}}) - .withDefault(0); + .withDefault(1); case WaveShaperIntParams::oversample: return pmd().asBool().withName("OverSample").withDefault(0); default: @@ -106,14 +106,7 @@ template struct WaveShaper : core::VoiceEffectTemplateBase< return pmd().asInt().withRange(0, 1).withName("Error"); } - void initVoiceEffectParams() - { - this->setFloatParam((int)WaveShaperFloatParams::drive, 0.f); - this->setFloatParam((int)WaveShaperFloatParams::bias, 0.f); - this->setFloatParam((int)WaveShaperFloatParams::postgain, 0.f); - - this->setIntParam((int)WaveShaperIntParams::type, 1); // force to ojd for now - } + void initVoiceEffectParams() { this->initToParamMetadataDefault(this); } template void processInternalOS(float *datainL, float *datainR, float *dataoutL, float *dataoutR)