From e0201fb227f7699475ba67d0999e7920a7f96fd2 Mon Sep 17 00:00:00 2001 From: Segfault1602 Date: Wed, 29 Nov 2023 13:00:52 -0800 Subject: [PATCH] Fix phaseshaper bug --- .vscode/launch.json | 6 +++--- src/phaseshapers.cpp | 14 +++++++++----- tools/audio_test/effect_player.cpp | 2 +- tools/audio_test/phaseshapers_tests.cpp | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index bf729af..e6e3113 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -111,13 +111,13 @@ "console": "externalTerminal" }, { - "name": "Debug Player.exe", + "name": "Debug AudioTest.exe", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceFolder}/build/tools/effect_player.exe", + "program": "${workspaceFolder}/build/tools/audio_test/effect_player.exe", "args": [ "-t", - "1" + "7" ], "stopAtEntry": false, "cwd": "${fileDirname}", diff --git a/src/phaseshapers.cpp b/src/phaseshapers.cpp index 765f13d..df999b5 100644 --- a/src/phaseshapers.cpp +++ b/src/phaseshapers.cpp @@ -41,8 +41,12 @@ inline float g_tri(float x, float a1 = 1, float a0 = 0) inline float g_pulse(float x, float phaseIncrement, float width = 0.5f, float period = 100.f) { - float d = std::floor(width * period); - return x - MOD1(x + phaseIncrement * d) + (1 - width); + if (x < width) + { + return 0.f; + } + + return 1.f; } inline float s_tri(float x) @@ -156,7 +160,7 @@ float Phaseshaper::Process() float Phaseshaper::ProcessWaveSlice() const { // a1 vary from 0.25 to 0.40 - float a1 = 0.25f + (m_mod * 0.15f); + float a1 = 0.25f + (m_mod * 0.50f); float slicePhase = g_lin(m_phase, a1); float trivial = G_B(sfdsp::Sine(slicePhase)); @@ -206,9 +210,9 @@ float Phaseshaper::ProcessSupersaw() const float Phaseshaper::ProcessVarSlope() const { // Width can vary from 0.1 to 0.5 - float width = 0.10f + (m_mod * 0.40f); + float width = 0.5f + (m_mod * 0.25f); - float pulse = g_pulse(m_phase, m_phaseIncrement, width, m_period); + float pulse = 0.5 * g_pulse(m_phase, m_phaseIncrement, width, m_period); float vslope = 0.5f * m_phase * (1.0f - pulse) / width + pulse * (m_phase - width) / (1 - width); return sfdsp::Sine(vslope); } diff --git a/tools/audio_test/effect_player.cpp b/tools/audio_test/effect_player.cpp index d2b4ce1..91f5144 100644 --- a/tools/audio_test/effect_player.cpp +++ b/tools/audio_test/effect_player.cpp @@ -85,7 +85,7 @@ int main(int argc, char** argv) } } - uint32_t samplerate = 44100; + uint32_t samplerate = 48000; uint32_t frame_count = 0; if (!input_file.empty()) diff --git a/tools/audio_test/phaseshapers_tests.cpp b/tools/audio_test/phaseshapers_tests.cpp index 14a111e..10e9f22 100644 --- a/tools/audio_test/phaseshapers_tests.cpp +++ b/tools/audio_test/phaseshapers_tests.cpp @@ -6,7 +6,7 @@ void PhaseShaperTest::Init(size_t samplerate) phaseshaper_.Init(static_cast(samplerate)); phaseshaper_.SetWaveform(current_waveform_); phaseshaper_.SetMod(0.5f); - phaseshaper_.SetFreq(220.f); + phaseshaper_.SetFreq(200.f); frame_per_wave_ = (uint32_t)samplerate_; // 4 periods per waveform