|
| 1 | +/* synth_UniformWhiteNoise_F32.h --- New July 2025 |
| 2 | + Generates a block of uniformly distributed, uncorrelated, white |
| 3 | + noise of a range of (-level, +level) as set by amplitude(level) |
| 4 | + with a default value of level = 0.0. This replaces the class |
| 5 | + synth_whitenoise_F32 and corrects the need for I16 memory as well |
| 6 | + providing output that uses the full F32 mantissa of 24-bits. |
| 7 | +
|
| 8 | + Method is xor shift 64 credited to George Marsaglia. See |
| 9 | + https://en.wikipedia.org/wiki/Xorshift and |
| 10 | + https://forum.pjrc.com/index.php?threads/teensy-4-1-random-number-generator.61125 |
| 11 | + post 13 by #Nominal Animal. |
| 12 | + Bob Larkin July 2025. Thanks #grrrr |
| 13 | +
|
| 14 | + Derived from synth_whitenoise_F32 that was |
| 15 | + extended by: Chip Audette, OpenAudio, Feb 2017 |
| 16 | + |
| 17 | + License: MIT License. Use at your own risk. |
| 18 | +*/ |
| 19 | +/* Audio Library for Teensy 3.X |
| 20 | + * Copyright (c) 2014, Paul Stoffregen, paul@pjrc.com |
| 21 | + * |
| 22 | + * Development of this audio library was funded by PJRC.COM, LLC by sales of |
| 23 | + * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop |
| 24 | + * open source software by purchasing Teensy or other PJRC products. |
| 25 | + * |
| 26 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 27 | + * of this software and associated documentation files (the "Software"), to deal |
| 28 | + * in the Software without restriction, including without limitation the rights |
| 29 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 30 | + * copies of the Software, and to permit persons to whom the Software is |
| 31 | + * furnished to do so, subject to the following conditions: |
| 32 | + * |
| 33 | + * The above copyright notice, development funding notice, and this permission |
| 34 | + * notice shall be included in all copies or substantial portions of the Software. |
| 35 | + * |
| 36 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 37 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 38 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 39 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 40 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 41 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 42 | + * THE SOFTWARE. |
| 43 | + */ |
| 44 | + |
| 45 | +// ** This does not support Teensy LC (KINETISL). Teensy 3.x and 4.x OK. ** |
| 46 | +// Execution time 15 uSec for 128 size block on T4.x. 12 of these are |
| 47 | +// the conversionfrom uint32_t to F32 with offset for DC=0. |
| 48 | + |
| 49 | +#ifndef synth_uniform_white_noise_f32_h_ |
| 50 | +#define synth_uniform_white_noise_f32_h_ |
| 51 | +#include "Arduino.h" |
| 52 | +#include "AudioStream_F32.h" |
| 53 | +#include "utility/dspinst.h" |
| 54 | + |
| 55 | +class AudioSynthUniformWhiteNoise_F32 : public AudioStream_F32 |
| 56 | +{ |
| 57 | +//GUI: inputs:0, outputs:1 //this line used for automatic generation of GUI node |
| 58 | +//GUI: shortName:uniformwhitenoise //this line used for automatic generation of GUI node |
| 59 | +public: |
| 60 | + AudioSynthUniformWhiteNoise_F32() : AudioStream_F32(0, NULL) { setDefaultValues(); } |
| 61 | + AudioSynthUniformWhiteNoise_F32(const AudioSettings_F32 &settings) : |
| 62 | + AudioStream_F32(0, NULL) { setDefaultValues(); } |
| 63 | + void setDefaultValues(void) { |
| 64 | + level = 0.0f; |
| 65 | + rnState = 1ULL + instance_count++; |
| 66 | + } |
| 67 | + |
| 68 | + void amplitude(float nL) { |
| 69 | + if (nL < 0.0) nL = 0.0; |
| 70 | + level = nL; |
| 71 | + } |
| 72 | + |
| 73 | + virtual void update(void); |
| 74 | + |
| 75 | +private: |
| 76 | + float32_t level = 0.0f; |
| 77 | + uint64_t rnState; |
| 78 | + uint64_t instance_count=0ULL; |
| 79 | +}; |
| 80 | +#endif |
0 commit comments