commit ab615e5b889eaa6f10d013b24cca4edc17b3d8cd
parent 99c3cd2e9132674bad67796ddd1433e62b40ecf4
Author: Matt Demanett <matt@demanett.net>
Date: Sun, 25 Feb 2018 21:35:14 -0500
Oversampling/decimation experiment.
Diffstat:
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/src/Test.cpp b/src/Test.cpp
@@ -59,6 +59,35 @@ void Test::step() {
_sineBank.setSampleRate(engineGetSampleRate());
_sineBank.setFrequency(oscillatorPitch());
outputs[OUT_OUTPUT].value = _sineBank.next();
+
+#elif OVERSAMPLING
+ _saw1.setSampleRate(engineGetSampleRate());
+ _saw1.setFrequency(oscillatorPitch() / (float)OVERSAMPLEN);
+ float buf[OVERSAMPLEN];
+ for (int i = 0; i < OVERSAMPLEN; ++i) {
+ buf[i] = _saw1.next();
+ }
+ outputs[OUT_OUTPUT].value = _rackDecimator.process(buf);
+
+ _saw2.setSampleRate(engineGetSampleRate());
+ _saw2.setFrequency(oscillatorPitch() / (float)OVERSAMPLEN);
+ _lpf.setParams(
+ engineGetSampleRate(),
+ engineGetSampleRate() / 4.0f,
+ 0.03
+ );
+ _lpf2.setParams(
+ engineGetSampleRate(),
+ engineGetSampleRate() / 4.0f,
+ 0.03
+ );
+ float s = 0.0f;
+ for (int i = 0; i < OVERSAMPLEN; ++i) {
+ // s = _lpf2.next(_lpf.next(_saw2.next()));
+ s = _lpf.next(_saw2.next());
+ // s = _saw2.next();
+ }
+ outputs[OUT2_OUTPUT].value = s * 5.0;
#endif
}
diff --git a/src/Test.hpp b/src/Test.hpp
@@ -5,12 +5,13 @@
extern Model* modelTest;
// #define LPF 1
-#define LPFNOISE 1
+// #define LPFNOISE 1
// #define SINE 1
// #define SQUARE 1
// #define SAW 1
// #define TRIANGLE 1
// #define SINEBANK 1
+#define OVERSAMPLING 1
#include "pitch.hpp"
#ifdef LPF
@@ -28,6 +29,11 @@ extern Model* modelTest;
#include "dsp/oscillator.hpp"
#elif SINEBANK
#include "dsp/oscillator.hpp"
+#elif OVERSAMPLING
+#include "dsp/oscillator.hpp"
+#include "dsp/decimator.hpp" // rack
+#include "dsp/filter.hpp"
+#define OVERSAMPLEN 16
#else
#error what
#endif
@@ -76,6 +82,12 @@ struct Test : Module {
TriangleOscillator _triangle;
#elif SINEBANK
SineBankOscillator _sineBank;
+#elif OVERSAMPLING
+ SawOscillator _saw1;
+ rack::Decimator<OVERSAMPLEN, OVERSAMPLEN> _rackDecimator;
+ SawOscillator _saw2;
+ LowPassFilter _lpf;
+ LowPassFilter _lpf2;
#endif
Test()
@@ -94,6 +106,11 @@ struct Test : Module {
, _triangle(44100.0, 1000.0, 5.0)
#elif SINEBANK
, _sineBank(44101.0, 1000.0, 50)
+#elif OVERSAMPLING
+ , _saw1(44100.0, 1000.0, 5.0)
+ , _saw2(44100.0, 1000.0, 1.0)
+ , _lpf(44100.0, 1000.0, 1.0)
+ , _lpf2(44100.0, 1000.0, 1.0)
#endif
{
onReset();