BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

commit 9a908fe50e58802e716fd013f981f0a31d95f84e
parent 7694531322e6f47e03e0a1c3a31be2da76c10b25
Author: Matt Demanett <matt@demanett.net>
Date:   Fri, 24 Nov 2017 18:10:44 -0500

Split up dsp.hpp header.

Diffstat:
Asrc/dsp/base.hpp | 13+++++++++++++
Msrc/dsp/dsp.hpp | 65++---------------------------------------------------------------
Asrc/dsp/noise.hpp | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+), 63 deletions(-)

diff --git a/src/dsp/base.hpp b/src/dsp/base.hpp @@ -0,0 +1,13 @@ + +namespace bogaudio { +namespace dsp { + +struct Generator { + Generator() {} + virtual ~Generator() {} + + virtual float next() = 0; +}; + +} // namespace dsp +} // namespace bogaudio diff --git a/src/dsp/dsp.hpp b/src/dsp/dsp.hpp @@ -1,66 +1,5 @@ #include "rack.hpp" -namespace bogaudio { -namespace dsp { - -struct Generator { - Generator() {} - virtual ~Generator() {} - - virtual float next() = 0; -}; - -struct NoiseGenerator : Generator { - NoiseGenerator() {} -}; - -struct WhiteNoiseGenerator : NoiseGenerator { - WhiteNoiseGenerator() {} - - virtual float next() { - return rack::randomf(); - } -}; - -struct PinkNoiseGenerator : NoiseGenerator { - static const int _n = 7; - uint64_t _g; - uint64_t _gs[_n]; - uint32_t _count; - uint64_t _sum; - - PinkNoiseGenerator() { - _sum = _g = rack::randomu64(); - for (int i = 0; i < _n; ++i) { - _sum += _gs[i] = rack::randomu64(); - } - _count = rack::randomu32(); - } - - virtual float next() { - // See: http://www.firstpr.com.au/dsp/pink-noise/ - _sum -= _g; - _sum += _g = rack::randomu64(); - for (int i = 0, bit = 1; i < _n; ++i, bit <<= 1) { - if (_count & bit) { - _sum -= _gs[i]; - _sum += _gs[i] = rack::randomu64(); - break; - } - } - ++_count; - return (_sum >> (64 - 24)) / powf(2, 24); - } -}; - -struct GaussianNoiseGenerator : NoiseGenerator { - GaussianNoiseGenerator() {} - - virtual float next() { - return rack::randomNormal(); - } -}; - -} // namespace dsp -} // namespace bogaudio +#include "base.hpp" +#include "noise.hpp" diff --git a/src/dsp/noise.hpp b/src/dsp/noise.hpp @@ -0,0 +1,57 @@ + +namespace bogaudio { +namespace dsp { + +struct NoiseGenerator : Generator { + NoiseGenerator() {} +}; + +struct WhiteNoiseGenerator : NoiseGenerator { + WhiteNoiseGenerator() {} + + virtual float next() { + return rack::randomf(); + } +}; + +struct PinkNoiseGenerator : NoiseGenerator { + static const int _n = 7; + uint64_t _g; + uint64_t _gs[_n]; + uint32_t _count; + uint64_t _sum; + + PinkNoiseGenerator() { + _sum = _g = rack::randomu64(); + for (int i = 0; i < _n; ++i) { + _sum += _gs[i] = rack::randomu64(); + } + _count = rack::randomu32(); + } + + virtual float next() { + // See: http://www.firstpr.com.au/dsp/pink-noise/ + _sum -= _g; + _sum += _g = rack::randomu64(); + for (int i = 0, bit = 1; i < _n; ++i, bit <<= 1) { + if (_count & bit) { + _sum -= _gs[i]; + _sum += _gs[i] = rack::randomu64(); + break; + } + } + ++_count; + return (_sum >> (64 - 24)) / powf(2, 24); + } +}; + +struct GaussianNoiseGenerator : NoiseGenerator { + GaussianNoiseGenerator() {} + + virtual float next() { + return rack::randomNormal(); + } +}; + +} // namespace dsp +} // namespace bogaudio