From 0077ef85e0bb8d98dbf0b4c1df120cec28d29266 Mon Sep 17 00:00:00 2001
From: dandistine <34634876+dandistine@users.noreply.github.com>
Date: Mon, 29 Aug 2022 20:24:15 -0500
Subject: [PATCH 1/3] Add a few basic, useful modules
---
source/olcSoundWaveEngine.vcxproj | 494 +++++++++++-----------
source/olcSoundWaveEngine.vcxproj.filters | 268 ++++++------
source/swe_synth_delay.cpp | 24 ++
source/swe_synth_delay.h | 23 +
source/swe_synth_first_order_filter.cpp | 18 +
source/swe_synth_first_order_filter.h | 22 +
source/swe_synth_n_mixer.cpp | 23 +
source/swe_synth_n_mixer.h | 23 +
source/swe_synth_pinkifier.cpp | 22 +
source/swe_synth_pinkifier.h | 23 +
10 files changed, 575 insertions(+), 365 deletions(-)
create mode 100644 source/swe_synth_delay.cpp
create mode 100644 source/swe_synth_delay.h
create mode 100644 source/swe_synth_first_order_filter.cpp
create mode 100644 source/swe_synth_first_order_filter.h
create mode 100644 source/swe_synth_n_mixer.cpp
create mode 100644 source/swe_synth_n_mixer.h
create mode 100644 source/swe_synth_pinkifier.cpp
create mode 100644 source/swe_synth_pinkifier.h
diff --git a/source/olcSoundWaveEngine.vcxproj b/source/olcSoundWaveEngine.vcxproj
index 5ca0955..adf0916 100644
--- a/source/olcSoundWaveEngine.vcxproj
+++ b/source/olcSoundWaveEngine.vcxproj
@@ -1,245 +1,253 @@
-
-
-
-
- Debug
- Win32
-
-
- Release
- Win32
-
-
- Debug
- x64
-
-
- Release
- x64
-
-
-
- 16.0
- Win32Proj
- {4ae3b973-fddc-4efe-8955-299b51dfd990}
- olcSoundWaveEngine
- 10.0
-
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
-
-
- false
-
-
- true
-
-
- false
-
-
-
- Level3
- true
- WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp17
-
-
- Console
- true
-
-
-
-
-
-
-
-
-
-
- ..\Demos\HeaderMaker.exe olc_swe_template.h olcSoundWaveEngine.h
-
-
- Creating Deployable Single Header - olcSoundWaveEngine.h
-
-
-
-
- Level3
- true
- true
- true
- WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp17
-
-
- Console
- true
- true
- true
-
-
-
-
-
-
-
-
-
-
- ..\Demos\HeaderMaker.exe olc_swe_template.h olcSoundWaveEngine.h
-
-
- Creating Deployable Single Header - olcSoundWaveEngine.h
-
-
-
-
- Level3
- true
- _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp17
-
-
- Console
- true
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 16.0
+ Win32Proj
+ {4ae3b973-fddc-4efe-8955-299b51dfd990}
+ olcSoundWaveEngine
+ 10.0
+
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+ false
+
+
+ true
+
+
+ false
+
+
+
+ Level3
+ true
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp17
+
+
+ Console
+ true
+
+
+
+
+
+
+
+
+
+
+ ..\Demos\HeaderMaker.exe olc_swe_template.h olcSoundWaveEngine.h
+
+
+ Creating Deployable Single Header - olcSoundWaveEngine.h
+
+
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp17
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+ ..\Demos\HeaderMaker.exe olc_swe_template.h olcSoundWaveEngine.h
+
+
+ Creating Deployable Single Header - olcSoundWaveEngine.h
+
+
+
+
+ Level3
+ true
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp17
+
+
+ Console
+ true
+
+
+
+
+
+
+
+
+
+
..\Demos\HeaderMaker.exe olc_swe_template.h olcSoundWaveEngine.h
-copy olcSoundWaveEngine.h ..\olcSoundWaveEngine.h
-
-
- Creating Deployable Single Header - olcSoundWaveEngine.h
-
-
-
-
- Level3
- true
- true
- true
- NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp17
-
-
- Console
- true
- true
- true
-
-
-
-
-
-
-
-
-
-
- ..\Demos\HeaderMaker.exe olc_swe_template.h olcSoundWaveEngine.h
-
-
- Creating Deployable Single Header - olcSoundWaveEngine.h
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+copy olcSoundWaveEngine.h ..\olcSoundWaveEngine.h
+
+
+ Creating Deployable Single Header - olcSoundWaveEngine.h
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp17
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+ ..\Demos\HeaderMaker.exe olc_swe_template.h olcSoundWaveEngine.h
+
+
+ Creating Deployable Single Header - olcSoundWaveEngine.h
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/source/olcSoundWaveEngine.vcxproj.filters b/source/olcSoundWaveEngine.vcxproj.filters
index 22e1b1e..55f2686 100644
--- a/source/olcSoundWaveEngine.vcxproj.filters
+++ b/source/olcSoundWaveEngine.vcxproj.filters
@@ -1,123 +1,147 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
-
-
- {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
- rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
-
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
-
-
-
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+
\ No newline at end of file
diff --git a/source/swe_synth_delay.cpp b/source/swe_synth_delay.cpp
new file mode 100644
index 0000000..957f680
--- /dev/null
+++ b/source/swe_synth_delay.cpp
@@ -0,0 +1,24 @@
+#pragma once
+#include "swe_synth_delay.h"
+
+
+namespace olc::sound::synth
+{
+ ///[OLC_HM] START SYNTH_DELAY_CPP
+ namespace modules
+ {
+ template
+ void Delay::Update(uint32_t nChannel, double dTime, double dTimeStep)
+ {
+ for (size_t i = state.size() - 1; i > 0; i--) {
+ state[i] = state[i - 1];
+ }
+
+ //Based on the delay value, sample from the delay line buffer
+ size_t out_index = std::min(state.size() - 1, static_cast(delay.value * samplerate));
+ state[0] = input.value * decay.value;
+ output = state[out_index];
+ }
+ }
+ ///[OLC_HM] END SYNTH_DELAY_CPP
+}
\ No newline at end of file
diff --git a/source/swe_synth_delay.h b/source/swe_synth_delay.h
new file mode 100644
index 0000000..df8731b
--- /dev/null
+++ b/source/swe_synth_delay.h
@@ -0,0 +1,23 @@
+#pragma once
+#include "swe_prefix.h"
+#include "swe_synth_modular.h"
+
+namespace olc::sound::synth
+{
+ ///[OLC_HM] START SYNTH_DELAY_H
+ namespace modules
+ {
+ template
+ class Delay : public olc::sound::synth::Module {
+ public:
+ olc::sound::synth::Property input = 0.0;
+ olc::sound::synth::Property output = 0.0;
+ olc::sound::synth::Property decay = 1.0;
+ olc::sound::synth::Property delay = max_ms / 1000.0;
+ std::array state{0.0};
+
+ virtual void Update(uint32_t nChannel, double dTime, double dTimeStep) override;
+ };
+ }
+ ///[OLC_HM] END SYNTH_DELAY_H
+}
\ No newline at end of file
diff --git a/source/swe_synth_first_order_filter.cpp b/source/swe_synth_first_order_filter.cpp
new file mode 100644
index 0000000..9d5b4e9
--- /dev/null
+++ b/source/swe_synth_first_order_filter.cpp
@@ -0,0 +1,18 @@
+#pragma once
+#include "swe_synth_first_order_filter.h"
+
+
+namespace olc::sound::synth
+{
+ ///[OLC_HM] START SYNTH_FIRST_ORDER_FILTER_CPP
+ namespace modules
+ {
+ void FirstOrderFilter::Update(uint32_t nChannel, double dTime, double dTimeStep)
+ {
+ double new_state = input.value + pole.value * state.value;
+ output = new_state - zero.value * state.value;
+ state = new_state;
+ }
+ }
+ ///[OLC_HM] END SYNTH_FIRST_ORDER_FILTER_CPP
+}
\ No newline at end of file
diff --git a/source/swe_synth_first_order_filter.h b/source/swe_synth_first_order_filter.h
new file mode 100644
index 0000000..66fe329
--- /dev/null
+++ b/source/swe_synth_first_order_filter.h
@@ -0,0 +1,22 @@
+#pragma once
+#include "swe_prefix.h"
+#include "swe_synth_modular.h"
+
+namespace olc::sound::synth
+{
+ ///[OLC_HM] START SYNTH_FIRST_ORDER_FILTER_H
+ namespace modules
+ {
+ class FirstOrderFilter : public olc::sound::synth::Module {
+ public:
+ FirstOrderFilter(double p, double z) : pole(p), zero(z) {};
+ olc::sound::synth::Property pole;
+ olc::sound::synth::Property zero;
+ olc::sound::synth::Property state = 0.0;
+ olc::sound::synth::Property input = 0.0;
+ olc::sound::synth::Property output = 0.0;
+ virtual void Update(uint32_t nChannel, double dTime, double dTimeStep) override;
+ };
+ }
+ ///[OLC_HM] END SYNTH_FIRST_ORDER_FILTER_H
+}
\ No newline at end of file
diff --git a/source/swe_synth_n_mixer.cpp b/source/swe_synth_n_mixer.cpp
new file mode 100644
index 0000000..aaa2b24
--- /dev/null
+++ b/source/swe_synth_n_mixer.cpp
@@ -0,0 +1,23 @@
+#pragma once
+#include "swe_synth_n_mixer.h"
+
+
+namespace olc::sound::synth
+{
+ ///[OLC_HM] START SYNTH_N_MIXER_CPP
+ namespace modules
+ {
+ template
+ void Mixer::Update(uint32_t nChannel, double dTime, double dTimeStep)
+ {
+ double out = 0.0;
+
+ for (size_t i = 0; i < N; i++) {
+ out += amplitude[i].value * inputs[i].value;
+ }
+
+ output = out / N;
+ }
+ }
+ ///[OLC_HM] END SYNTH_N_MIXER_CPP
+}
\ No newline at end of file
diff --git a/source/swe_synth_n_mixer.h b/source/swe_synth_n_mixer.h
new file mode 100644
index 0000000..1cbfd31
--- /dev/null
+++ b/source/swe_synth_n_mixer.h
@@ -0,0 +1,23 @@
+#pragma once
+#include "swe_prefix.h"
+#include "swe_synth_modular.h"
+
+namespace olc::sound::synth
+{
+ ///[OLC_HM] START SYNTH_N_MIXER_H
+ namespace modules
+ {
+ template
+ class Mixer : public Module
+ {
+ public:
+ std::array inputs = {};
+ std::array amplitude = {};
+ Property output;
+
+ virtual void Update(uint32_t nChannel, double dTime, double dTimeStep) override;
+
+ };
+ }
+ ///[OLC_HM] END SYNTH_N_MIXER_H
+}
\ No newline at end of file
diff --git a/source/swe_synth_pinkifier.cpp b/source/swe_synth_pinkifier.cpp
new file mode 100644
index 0000000..97a3b27
--- /dev/null
+++ b/source/swe_synth_pinkifier.cpp
@@ -0,0 +1,22 @@
+#pragma once
+#include "swe_synth_pinkifier.h"
+
+
+namespace olc::sound::synth
+{
+ ///[OLC_HM] START SYNTH_PINKIFIER_CPP
+ namespace modules
+ {
+ void Pinkifier::Update(uint32_t nChannel, double dTime, double dTimeStep)
+ {
+ f1.input = input;
+ f1.Update(nChannel, dTime, dTimeStep);
+ f2.input = f1.output;
+ f2.Update(nChannel, dTime, dTimeStep);
+ f3.input = f2.output;
+ f3.Update(nChannel, dTime, dTimeStep);
+ output = f3.output;
+ }
+ }
+ ///[OLC_HM] END SYNTH_PINKIFIER_CPP
+}
\ No newline at end of file
diff --git a/source/swe_synth_pinkifier.h b/source/swe_synth_pinkifier.h
new file mode 100644
index 0000000..9955616
--- /dev/null
+++ b/source/swe_synth_pinkifier.h
@@ -0,0 +1,23 @@
+#pragma once
+#include "swe_prefix.h"
+#include "swe_synth_modular.h"
+#include "swe_synth_first_order_filter.h"
+
+namespace olc::sound::synth
+{
+ ///[OLC_HM] START SYNTH_PINKIFIER_H
+ namespace modules
+ {
+ class Pinkifier : public olc::sound::synth::Module {
+ FirstOrderFilter f1 = { 0.99572754 , 0.98443604};
+ FirstOrderFilter f2 = { 0.94790649 , 0.83392334 };
+ FirstOrderFilter f3 = { 0.53567505 , 0.07568359 };
+
+ public:
+ olc::sound::synth::Property input = 0.0;
+ olc::sound::synth::Property output = 0.0;
+ virtual void Update(uint32_t nChannel, double dTime, double dTimeStep) override;
+ };
+ }
+ ///[OLC_HM] END SYNTH_PINKIFIER_H
+}
\ No newline at end of file
From 8f6fc0b6c50eab611057ba8d14ee20ad3f5d3aba Mon Sep 17 00:00:00 2001
From: dandistine <34634876+dandistine@users.noreply.github.com>
Date: Wed, 31 Aug 2022 20:02:28 -0500
Subject: [PATCH 2/3] Update swe_synth_delay.h
---
source/swe_synth_delay.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/source/swe_synth_delay.h b/source/swe_synth_delay.h
index df8731b..b3471fb 100644
--- a/source/swe_synth_delay.h
+++ b/source/swe_synth_delay.h
@@ -13,11 +13,14 @@ namespace olc::sound::synth
olc::sound::synth::Property input = 0.0;
olc::sound::synth::Property output = 0.0;
olc::sound::synth::Property decay = 1.0;
- olc::sound::synth::Property delay = max_ms / 1000.0;
+ olc::sound::synth::Property delay = 1.0;
std::array state{0.0};
-
virtual void Update(uint32_t nChannel, double dTime, double dTimeStep) override;
+ private:
+ double max_delay = static_cast(max_ms) / 1000.0;
+ size_t input_index = 0;
+ size_t output_index = 1;
};
}
///[OLC_HM] END SYNTH_DELAY_H
-}
\ No newline at end of file
+}
From e12d66533392a10579110cf2bfa04ca9af6464a2 Mon Sep 17 00:00:00 2001
From: dandistine <34634876+dandistine@users.noreply.github.com>
Date: Wed, 31 Aug 2022 20:03:09 -0500
Subject: [PATCH 3/3] Update swe_synth_delay.cpp
Changes the delay to use a circular buffer instead of shifting every element every time.
---
source/swe_synth_delay.cpp | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/source/swe_synth_delay.cpp b/source/swe_synth_delay.cpp
index 957f680..cfffbb8 100644
--- a/source/swe_synth_delay.cpp
+++ b/source/swe_synth_delay.cpp
@@ -10,15 +10,14 @@ namespace olc::sound::synth
template
void Delay::Update(uint32_t nChannel, double dTime, double dTimeStep)
{
- for (size_t i = state.size() - 1; i > 0; i--) {
- state[i] = state[i - 1];
- }
+ state[input_index] = input.value * decay.value;
+ input_index = (input_index + 1) % state.size();
- //Based on the delay value, sample from the delay line buffer
- size_t out_index = std::min(state.size() - 1, static_cast(delay.value * samplerate));
- state[0] = input.value * decay.value;
- output = state[out_index];
+ //Determine where we should sample from based on the desired delay amount
+ size_t out_dist = std::min(state.size() - 1, static_cast(delay.value * max_delay * samplerate));
+ output_index = (input_index - out_dist + state.size()) % state.size();
+ output = state[output_index];
}
}
///[OLC_HM] END SYNTH_DELAY_CPP
-}
\ No newline at end of file
+}