Skip to content

Commit

Permalink
Fix phaseshaper bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Segfault1602 committed Nov 29, 2023
1 parent 878dfb3 commit e0201fb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
14 changes: 9 additions & 5 deletions src/phaseshapers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tools/audio_test/effect_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion tools/audio_test/phaseshapers_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void PhaseShaperTest::Init(size_t samplerate)
phaseshaper_.Init(static_cast<float>(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
Expand Down

0 comments on commit e0201fb

Please sign in to comment.