Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to Stereo and Mono static phaser, per github convo #69

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/sst/voice-effects/delay/ShortDelay.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ template <typename VFXConfig> struct ShortDelay : core::VoiceEffectTemplateBase<
{
auto out0 = lines[0]->read(ld[0][i]);
auto out1 = lines[1]->read(ld[1][i]);

lp.process_sample(out0, out1, out0, out1);
hp.process_sample(out0, out1, out0, out1);

dataoutL[i] = out0;
dataoutR[i] = out1;

Expand Down
98 changes: 80 additions & 18 deletions include/sst/voice-effects/filter/StaticPhaser.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,24 @@

namespace sst::voice_effects::filter
{
template <typename VFXConfig> struct StaticPhaser : core::VoiceEffectTemplateBase<VFXConfig>
template <typename VFXConfig, bool stereo>
struct StaticPhaser : core::VoiceEffectTemplateBase<VFXConfig>
{
static constexpr const char *effectName{"Static Phaser"};
static constexpr const char *effectName{stereo ? "StereoStaticPhaser" : "MonoStaticPhaser"};

static constexpr int numFloatParams{4};
static constexpr int numFloatParams{4 + (stereo ? 1 : 0)};
static constexpr int numIntParams{1};

static constexpr int maxPhases{8};
static constexpr int maxPhases{6};

enum FloatParams
{
fpCenterFrequency,
fpFrequencyWidth,
fpSpacing = fpCenterFrequency + (stereo ? 2 : 1),
fpResonance,
fpFeedback
fpFeedback,

fpCenterFrequencyR = fpCenterFrequency + (stereo ? 1 : -100)
};

enum IntParams
Expand All @@ -72,16 +75,27 @@ template <typename VFXConfig> struct StaticPhaser : core::VoiceEffectTemplateBas
switch (idx)
{
case fpCenterFrequency:
return pmd().asAudibleFrequency().withName("Center").withDefault(0);
case fpFrequencyWidth:
return pmd()
.asAudibleFrequency()
.withName(std::string("Ctr") + (stereo ? " L" : ""))
.withDefault(0);

case fpCenterFrequencyR:
return pmd()
.asAudibleFrequency()
.withName(std::string("Ctr") + (stereo ? " R" : ""))
.withDefault(0);

break;
case fpSpacing:
return pmd()
.asFloat()
.withRange(-48, 48)
.withDefault(12)
.withName("Spread")
.withName("Spacing")
.withLinearScaleFormatting("semitones");
case fpResonance:
return pmd().asPercent().withDefault(0.707).withName("Stage Resonance");
return pmd().asPercent().withDefault(0.707).withName("Resonance");
case fpFeedback:
return pmd().asPercent().withDefault(0.f).withName("Feedback");

Expand Down Expand Up @@ -127,7 +141,6 @@ template <typename VFXConfig> struct StaticPhaser : core::VoiceEffectTemplateBas
float fb alignas(16)[VFXConfig::blockSize];
lipolFb.store_block(fb);

// lipol the feedback please
for (int k = 0; k < VFXConfig::blockSize; ++k)
{
auto dL = dataoutL[k] + fbAmt[0];
Expand Down Expand Up @@ -170,19 +183,37 @@ template <typename VFXConfig> struct StaticPhaser : core::VoiceEffectTemplateBas
}
auto mode = sst::filters::CytomicSVF::Mode::ALL;
auto spread{0.f};
auto base{param[fpCenterFrequency]};
auto baseL{param[fpCenterFrequency]}, baseR{baseL};
if (stereo)
{
baseR = param[fpCenterFrequencyR];
}
if (iparam[ipStages] > 1)
{
spread = (param[fpFrequencyWidth] * 2) / (iparam[ipStages] - 1);
base = param[fpCenterFrequency] - param[fpFrequencyWidth];
spread = param[fpSpacing];
auto halfStage = iparam[ipStages] * 0.5;
baseL -= halfStage * spread;
baseR -= halfStage * spread;
}
for (int i = 0; i < iparam[ipStages]; ++i)
{
auto freq = 440.0 * this->note_to_pitch_ignoring_tuning(base + spread * i);
if constexpr (stereo)
{
auto freqL = 440.0 * this->note_to_pitch_ignoring_tuning(baseL + spread * i);
auto freqR = 440.0 * this->note_to_pitch_ignoring_tuning(baseR + spread * i);

auto res = std::clamp(param[fpResonance], 0.f, 1.f);
apfs[i].template setCoeffForBlock<VFXConfig::blockSize>(
mode, freqL, freqR, res, res, this->getSampleRateInv(), 1.f, 1.f);
}
else
{
auto freq = 440.0 * this->note_to_pitch_ignoring_tuning(baseL + spread * i);

auto res = std::clamp(param[fpResonance], 0.f, 1.f);
apfs[i].template setCoeffForBlock<VFXConfig::blockSize>(mode, freq, res,
this->getSampleRateInv());
auto res = std::clamp(param[fpResonance], 0.f, 1.f);
apfs[i].template setCoeffForBlock<VFXConfig::blockSize>(
mode, freq, res, this->getSampleRateInv());
}
}
mLastParam = param;
mLastIParam = iparam;
Expand All @@ -203,5 +234,36 @@ template <typename VFXConfig> struct StaticPhaser : core::VoiceEffectTemplateBas
sst::basic_blocks::dsp::lipol_sse<VFXConfig::blockSize, true> lipolFb;
};

template <typename VFXConfig> using StaticStereoPhaser = StaticPhaser<VFXConfig, true>;

template <typename VFXConfig> struct StaticMonoPhaser : StaticPhaser<VFXConfig, false>
{
void processMonoToMono(float *dataIn, float *dataOut, float pitch)
{
namespace mech = sst::basic_blocks::mechanics;

this->calc_coeffs(pitch);

mech::copy_from_to<VFXConfig::blockSize>(dataIn, dataOut);

this->lipolFb.set_target(
std::sqrt(std::clamp(this->getFloatParam(this->fpFeedback), 0.f, 1.f)));
float fb alignas(16)[VFXConfig::blockSize];
this->lipolFb.store_block(fb);

for (int k = 0; k < VFXConfig::blockSize; ++k)
{
auto dL = dataOut[k] + this->fbAmt[0];
for (int i = 0; i < this->getIntParam(this->ipStages); ++i)
{
float tmp{0};
this->apfs[i].processBlockStep(dL, tmp);
}
this->fbAmt[0] = dL * fb[k];
dataOut[k] = dL;
}
}
};

} // namespace sst::voice_effects::filter
#endif // SHORTCIRCUITXT_CYTOMICSVF_H
3 changes: 2 additions & 1 deletion tests/create-voice-effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ TEST_CASE("Can Create Voice FX")
}
SECTION("Static Phaser")
{
VTester<sst::voice_effects::filter::StaticPhaser<VTestConfig>>::TestVFX();
VTester<sst::voice_effects::filter::StaticStereoPhaser<VTestConfig>>::TestVFX();
VTester<sst::voice_effects::filter::StaticMonoPhaser<VTestConfig>>::TestVFX();
}
}
Loading