Test.hpp (8548B)
1 #pragma once 2 3 #include "bogaudio.hpp" 4 5 extern Model* modelTest; 6 7 //#define LPF 1 8 // #define LPFNOISE 1 9 // #define SINE 1 10 // #define SQUARE 1 11 // #define SAW 1 12 // #define SATSAW 1 13 // #define TRIANGLE 1 14 // #define SAMPLED_TRIANGLE 1 15 // #define SINEBANK 1 16 // #define OVERSAMPLING 1 17 // #define OVERSAMPLED_BL 1 18 // #define ANTIALIASING 1 19 // #define DECIMATORS 1 20 // #define INTERPOLATOR 1 21 // #define FM 1 22 // #define PM 1 23 // #define FEEDBACK_PM 1 24 // #define EG 1 25 // #define TABLES 1 26 // #define SLEW 1 27 // #define RMS 1 28 // #define FASTRMS 1 29 // #define RAVG 1 30 // #define SATURATOR 1 31 // #define BROWNIAN 1 32 // #define INTEGRATOR 1 33 // #define RANDOMWALK 1 34 // #define DCBLOCKER 1 35 // #define LFO_SMOOTHER 1 36 #define STEPPED_RANDOM 1 37 38 #include "pitch.hpp" 39 #ifdef LPF 40 #include "dsp/filters/filter.hpp" 41 #elif LPFNOISE 42 #include "dsp/filters/filter.hpp" 43 #include "dsp/noise.hpp" 44 #elif SINE 45 #include "dsp/oscillator.hpp" 46 #elif SQUARE 47 #include "dsp/oscillator.hpp" 48 #elif SAW 49 #include "dsp/oscillator.hpp" 50 #elif SATSAW 51 #include "dsp/oscillator.hpp" 52 #elif TRIANGLE 53 #include "dsp/oscillator.hpp" 54 #elif SAMPLED_TRIANGLE 55 #include "dsp/oscillator.hpp" 56 #elif SINEBANK 57 #include "dsp/oscillator.hpp" 58 #elif OVERSAMPLING 59 #include "dsp/oscillator.hpp" 60 #include "dsp/decimator.hpp" // rack 61 #include "dsp/filters/resample.hpp" 62 #define OVERSAMPLEN 16 63 #elif OVERSAMPLED_BL 64 #include "dsp/oscillator.hpp" 65 #include "dsp/filters/resample.hpp" 66 #elif ANTIALIASING 67 #include "dsp/oscillator.hpp" 68 #include "dsp/decimator.hpp" // rack 69 #include "dsp/filters/resample.hpp" 70 #elif DECIMATORS 71 #include "dsp/oscillator.hpp" 72 #include "dsp/filters/resample.hpp" 73 #include "dsp/decimator.hpp" // rack 74 #elif INTERPOLATOR 75 #include "dsp/oscillator.hpp" 76 #include "dsp/filters/resample.hpp" 77 #elif FM 78 #include "dsp/oscillator.hpp" 79 #elif PM 80 #include "dsp/oscillator.hpp" 81 #elif FEEDBACK_PM 82 #include "dsp/oscillator.hpp" 83 #elif EG 84 #include "dsp/envelope.hpp" 85 #elif TABLES 86 #include "dsp/oscillator.hpp" 87 #elif SLEW 88 #include "dsp/signal.hpp" 89 #elif RMS 90 #include "dsp/signal.hpp" 91 #include "dsp/filters/utility.hpp" 92 #elif FASTRMS 93 #include "dsp/signal.hpp" 94 #include "dsp/filters/utility.hpp" 95 #elif RAVG 96 #include "dsp/signal.hpp" 97 #elif SATURATOR 98 #include "dsp/oscillator.hpp" 99 #include "dsp/signal.hpp" 100 #elif BROWNIAN 101 #include "dsp/noise.hpp" 102 #elif INTEGRATOR 103 #include "dsp/noise.hpp" 104 #elif RANDOMWALK 105 #include "dsp/noise.hpp" 106 #elif DCBLOCKER 107 #include "dsp/filters/experiments.hpp" 108 #elif LFO_SMOOTHER 109 #include "dsp/signal.hpp" 110 #include "dsp/pitch.hpp" 111 #include "lfo_base.hpp" 112 #elif STEPPED_RANDOM 113 #include "dsp/oscillator.hpp" 114 #include "dsp/noise.hpp" 115 #else 116 #error what 117 #endif 118 119 using namespace bogaudio::dsp; 120 121 namespace bogaudio { 122 123 struct Test : BGModule { 124 enum ParamsIds { 125 PARAM1_PARAM, 126 PARAM2_PARAM, 127 PARAM3_PARAM, 128 NUM_PARAMS 129 }; 130 131 enum InputsIds { 132 CV1_INPUT, 133 CV2_INPUT, 134 CV3_INPUT, 135 IN_INPUT, 136 NUM_INPUTS 137 }; 138 139 enum OutputsIds { 140 OUT_OUTPUT, 141 OUT2_OUTPUT, 142 NUM_OUTPUTS 143 }; 144 145 #ifdef LPF 146 LowPassFilter _lpf; 147 #elif LPFNOISE 148 WhiteNoiseGenerator _noise; 149 LowPassFilter _lpf; 150 #elif SINE 151 SineOscillator _sine; 152 SineTable _table; 153 TablePhasor _sine2; 154 #elif SQUARE 155 SquareOscillator _square; 156 BandLimitedSquareOscillator _square2; 157 #elif SAW 158 SawOscillator _saw; 159 BandLimitedSawOscillator _saw2; 160 #elif SATSAW 161 SaturatingSawOscillator _saw; 162 BandLimitedSawOscillator _saw2; 163 #elif TRIANGLE 164 TriangleOscillator _triangle; 165 #elif SAMPLED_TRIANGLE 166 TriangleOscillator _triangle; 167 TriangleOscillator _triangle2; 168 int _sampleSteps = 1 << 20; 169 int _sampleStep = 0; 170 float _sample = 0.0f; 171 #elif SINEBANK 172 SineBankOscillator _sineBank; 173 #elif OVERSAMPLING 174 SawOscillator _saw1; 175 SawOscillator _saw2; 176 LowPassFilter _lpf; 177 LowPassFilter _lpf2; 178 rack::Decimator<OVERSAMPLEN, OVERSAMPLEN> _rackDecimator; 179 #elif OVERSAMPLED_BL 180 BandLimitedSawOscillator _saw1; 181 BandLimitedSawOscillator _saw2; 182 LowPassFilter _lpf; 183 #elif ANTIALIASING 184 #define OVERSAMPLEN 8 185 Phasor _phasor; 186 Phasor _oversampledPhasor; 187 BandLimitedSawOscillator _saw; 188 BandLimitedSquareOscillator _square; 189 bogaudio::dsp::LPFDecimator _sawDecimator; 190 bogaudio::dsp::LPFDecimator _squareDecimator; 191 rack::Decimator<OVERSAMPLEN, OVERSAMPLEN> _sawRackDecimator; 192 rack::Decimator<OVERSAMPLEN, OVERSAMPLEN> _squareRackDecimator; 193 #elif DECIMATORS 194 #define OVERSAMPLEN 8 195 #define STAGES 4 196 BandLimitedSawOscillator _saw; 197 bogaudio::dsp::CICDecimator _cicDecimator; 198 bogaudio::dsp::LPFDecimator _lpfDecimator; 199 rack::Decimator<OVERSAMPLEN, OVERSAMPLEN> _rackDecimator; 200 #elif INTERPOLATOR 201 #define FACTOR 8 202 #define STAGES 4 203 BandLimitedSawOscillator _saw; 204 bogaudio::dsp::CICDecimator _decimator; 205 bogaudio::dsp::CICInterpolator _interpolator; 206 int _steps; 207 float _rawSamples[FACTOR] {}; 208 float _processedSamples[FACTOR] {}; 209 #elif FM 210 float _baseHz = 0.0f; 211 float _ratio = 0.0f; 212 float _index = 0.0f; 213 float _sampleRate = 0.0f; 214 SineTableOscillator _modulator; 215 SineTableOscillator _carrier; 216 SineTableOscillator _modulator2; 217 SineTableOscillator _carrier2; 218 #elif PM 219 SineTableOscillator _modulator; 220 SineTableOscillator _carrier; 221 #elif FEEDBACK_PM 222 SineTableOscillator _carrier; 223 float _feedbackSample = 0.0f; 224 #elif EG 225 ADSR _envelope; 226 #elif TABLES 227 SineTableOscillator _sine; 228 TablePhasor _table; 229 #elif SLEW 230 bogaudio::dsp::SlewLimiter _slew; 231 ShapedSlewLimiter _slew2; 232 #elif RMS 233 RootMeanSquare _rms; 234 PucketteEnvelopeFollower _pef; 235 #elif FASTRMS 236 PureRootMeanSquare _pure; 237 FastRootMeanSquare _fast; 238 #elif RAVG 239 RunningAverage _average; 240 Trigger _reset; 241 #elif SATURATOR 242 Saturator _saturator; 243 #elif BROWNIAN 244 WhiteNoiseGenerator _noise1; 245 GaussianNoiseGenerator _noise2; 246 LowPassFilter _filter1; 247 LowPassFilter _filter2; 248 float _last1 = 0.0f; 249 float _last2 = 0.0f; 250 #elif INTEGRATOR 251 WhiteNoiseGenerator _noise; 252 Integrator _integrator; 253 #elif RANDOMWALK 254 RandomWalk _walk1; 255 RandomWalk _walk2; 256 #elif DCBLOCKER 257 DCBlocker _filter; 258 #elif LFO_SMOOTHER 259 LFOBase::Smoother _smoother; 260 #elif STEPPED_RANDOM 261 PositiveZeroCrossing _trigger; 262 SteppedRandomOscillator _stepped; 263 SteppedRandomOscillator::phase_t _lastPhase = 0; 264 WhiteNoiseGenerator _noise; 265 float _lastNoise = 0.0f; 266 #endif 267 268 Test() 269 #if SINE 270 : _table(12) 271 , _sine2(_table) 272 #elif DECIMATORS 273 : _cicDecimator(STAGES) 274 #elif INTERPOLATOR 275 : _decimator(STAGES) 276 , _interpolator(STAGES) 277 #elif TABLES 278 : _table(StaticBlepTable::table(), 44100.0, 1000.0) 279 #elif RAVG 280 : _average(APP->engine->getSampleRate(), 1.0f, 1000.0f) 281 #endif 282 { 283 config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS); 284 configParam(PARAM1_PARAM, 0.0f, 1.0f, 0.5f, "param1"); 285 configParam(PARAM2_PARAM, 0.0f, 1.0f, 0.5f, "param2"); 286 configParam(PARAM3_PARAM, 0.0f, 1.0f, 0.5f, "param3"); 287 288 #ifdef SINE 289 _table.generate(); 290 _sine2.setPhase(M_PI); 291 292 #elif SAW 293 _saw2.setPhase(M_PI); 294 295 #elif SATSAW 296 _saw2.setPhase(M_PI); 297 298 #elif SAMPLED_TRIANGLE 299 _triangle2.setPhase(M_PI); 300 301 #elif SINEBANK 302 const float baseAmplitude = 5.0; 303 switch (5) { 304 case 1: { 305 // saw 306 for (int i = 1, n = _sineBank.partialCount(); i <= n; ++i) { 307 _sineBank.setPartial(i, i, baseAmplitude / (float)i); 308 } 309 _sineBank.syncToPhase(M_PI); 310 break; 311 } 312 313 case 2: { 314 // square 315 for (int i = 1, n = _sineBank.partialCount(); i <= n; ++i) { 316 _sineBank.setPartial(i, i, i % 2 == 1 ? baseAmplitude / (float)i : 0.0); 317 } 318 break; 319 } 320 321 case 3: { 322 // triangle 323 if (false) { 324 for (int i = 1, n = _sineBank.partialCount(); i <= n; ++i) { 325 _sineBank.setPartial(i, i, i % 2 == 1 ? baseAmplitude / (float)(i * i) : 0.0); 326 } 327 _sineBank.syncToPhase(M_PI / 2.0); 328 } 329 else { 330 _sineBank.setPartial(1, 1.0f, baseAmplitude); 331 for (int i = 2, n = _sineBank.partialCount(); i < n; ++i) { 332 float k = 2*i - 1; 333 _sineBank.setPartial(i, k, powf(-1.0f, k) * baseAmplitude/(k * k)); 334 } 335 } 336 break; 337 } 338 339 case 4: { 340 // saw-square 341 for (int i = 1, n = _sineBank.partialCount(); i <= n; ++i) { 342 _sineBank.setPartial(i, i, i % 2 == 1 ? baseAmplitude / (float)i : baseAmplitude / (float)(2 * i)); 343 } 344 break; 345 } 346 347 case 5: { 348 // ? 349 float factor = 0.717; 350 float factor2 = factor; 351 float multiple = 1.0; 352 for (int i = 1, n = _sineBank.partialCount(); i <= n; ++i) { 353 _sineBank.setPartial(i, multiple, baseAmplitude / multiple); 354 multiple += i % 2 == 1 ? factor : factor2; 355 } 356 break; 357 } 358 } 359 360 #elif OVERSAMPLED_BL 361 _saw2.setPhase(M_PI); 362 #endif 363 } 364 365 void reset() override; 366 void processAll(const ProcessArgs& args) override; 367 float oscillatorPitch(float max = 10000.0); 368 float oscillatorPitch2(float max = 10000.0); 369 float ratio2(); 370 float index3(); 371 }; 372 373 } // namespace bogaudio