/* * synth_GaussianWhiteNoise_F32.cpp * by Bob Larkin W7PUA 15 June 2020 * * Created: Chip Audette, OpenAudio, Feb 2017 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice, development funding notice, and this permission * notice shall be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "synth_GaussianWhiteNoise_F32.h" // Park-Miller-Carta Pseudo-Random Number Generator // http://www.firstpr.com.au/dsp/rand31/ // Rev - Lower limit on sd changed, 0.01 to 1.0e-20f RSL 19Jan2022 void AudioSynthGaussian_F32::update(void) { audio_block_f32_t *blockOut; uint32_t it; float32_t rdev = 0.0f; float32_t* pd; if (sd < 1.000e-20f) { return; // Not enabled } #if TEST_TIME_GWN if (iitt++ >1000000) iitt = -10; uint32_t t1, t2; t1 = tElapse; #endif blockOut = AudioStream_F32::allocate_f32(); if (!blockOut) { if(errorPrint) Serial.println("GWN-ERR: No output memory"); return; } pd = &blockOut->data[0]; // Pointer to write data /* The "Even Quicker" uniform random sample generator from D. E. Knuth and * H. W. Lewis and described in Chapter 7 of "Numerical Receipes in C", * 2nd ed, with the comment "this is about as good as any 32-bit linear * congruential generator, entirely adequate for many uses." */ union { uint32_t i32; float32_t f32; } uinf; for(int i=0; i