Skip to content

Commit

Permalink
[kyma] Add FM to oscillators
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed May 19, 2023
1 parent 633d8cb commit 6af9df4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/kyma/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "mc/envelope/adsr.hpp"
#include "mc/math/decibel.hpp"
#include "mc/math/range.hpp"
#include "mc/music/note.hpp"
#include "mc/oscillator/variable_shape_oscillator.hpp"
Expand All @@ -17,7 +18,7 @@ auto adsr = mc::ADSR{};
auto oscillator = mc::VariableShapeOscillator<float>{};
auto subOscillator = mc::VariableShapeOscillator<float>{};

auto audioCallback(daisy::AudioHandle::InputBuffer /*in*/, daisy::AudioHandle::OutputBuffer out, size_t size) -> void
auto audioCallback(daisy::AudioHandle::InputBuffer in, daisy::AudioHandle::OutputBuffer out, size_t size) -> void
{
patch.ProcessAllControls();

Expand Down Expand Up @@ -54,6 +55,10 @@ auto audioCallback(daisy::AudioHandle::InputBuffer /*in*/, daisy::AudioHandle::O

for (size_t i = 0; i < size; ++i)
{
auto const fmModulator = IN_L[i];
auto const fmAmount = IN_R[i];
oscillator.addPhaseOffset(fmModulator * fmAmount);

auto const env = adsr.processSample();
patch.WriteCvOut(daisy::patch_sm::CV_OUT_1, env * 5.0F);

Expand Down
1 change: 1 addition & 0 deletions src/kyma/mc/oscillator/oscillator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ auto Oscillator<SampleType>::setSampleRate(SampleType sampleRate) noexcept -> vo
{
_sampleRate = sampleRate;
}

template<typename SampleType>
auto Oscillator<SampleType>::addPhaseOffset(SampleType offset) noexcept -> void
{
Expand Down
9 changes: 9 additions & 0 deletions src/kyma/mc/oscillator/variable_shape_oscillator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct VariableShapeOscillator
auto setFrequency(SampleType frequency) noexcept -> void;
auto setSampleRate(SampleType sampleRate) noexcept -> void;

auto addPhaseOffset(SampleType offset) noexcept -> void;

[[nodiscard]] auto operator()() noexcept -> SampleType;

private:
Expand Down Expand Up @@ -60,6 +62,13 @@ auto VariableShapeOscillator<SampleType>::setSampleRate(SampleType sampleRate) n
_oscB.setSampleRate(sampleRate);
}

template<typename SampleType>
auto VariableShapeOscillator<SampleType>::addPhaseOffset(SampleType offset) noexcept -> void
{
_oscA.addPhaseOffset(offset);
_oscB.addPhaseOffset(offset);
}

template<typename SampleType>
auto VariableShapeOscillator<SampleType>::operator()() noexcept -> SampleType
{
Expand Down

0 comments on commit 6af9df4

Please sign in to comment.