Skip to content

Commit

Permalink
SineWave: Add quadrature output option
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Jan 6, 2024
1 parent 67e3f53 commit af87f55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/dsp/chowdsp_sources/Oscillators/chowdsp_SineWave.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class SineWave
return y;
}

/** Returns a single-sample sin/cosine pair. */
inline auto processSampleQuadrature() noexcept
{
return std::make_pair (processSample(), -x1);
}

/** Processes a block of samples. */
void processBlock (const BufferView<T>& buffer) noexcept;

Expand Down
18 changes: 18 additions & 0 deletions tests/dsp_tests/chowdsp_sources_test/SineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ TEST_CASE ("Sine Test", "[dsp][sources]")
}
}

SECTION ("Single-Sample Quadrature Processing Test")
{
chowdsp::SineWave<double> chowSine;
juce::dsp::ProcessSpec spec { fs, 512, 1 };
chowSine.prepare (spec);
chowSine.setFrequency (freq1);

// process samples one at a time, and compare to std::sin and std::cos
for (int i = 0; i < 2000; i++)
{
auto [actual_sin, actual_cos] = chowSine.processSampleQuadrature();
auto expected_sin = std::sin (juce::MathConstants<double>::twoPi * freq1 * i / fs);
auto expected_cos = std::cos (juce::MathConstants<double>::twoPi * freq1 * i / fs);
REQUIRE_MESSAGE (actual_sin == Catch::Approx (expected_sin).margin (err), "Sine Wave is inaccurate");
REQUIRE_MESSAGE (actual_cos == Catch::Approx (expected_cos).margin (10.0 * err), "Cosine Wave is inaccurate");
}
}

SECTION ("Buffer Processing Test")
{
chowdsp::SineWave<double> chowSine;
Expand Down

0 comments on commit af87f55

Please sign in to comment.