Gaussian White Noise Generation #427
-
Hi everyone! I've been able to use the GeneratedSoundStream class, with NoiseGenerator to produce noise as the ouput sound in a I2S DAC that I'm using as an audio source for some experiments. However, I've seen that the generation of this stream is made using the "rand()" function, which produces an uniform probability distribution as I'm aware. This isn't a problem in many cases, but for the application I'm researching I'd like to have white noise with gaussian distribution. Doing some research, I´ve found that there's an algorithm called "Box-Muller Transform", that converts random samples with uniform distribution to normal distribution using a simple equation. Here is an article that explains all of this: https://www.baeldung.com/cs/uniform-to-normal-distribution I tried to modify the NoiseGenerator class to implement this algorithm but without success. It generated some output but the audio seemed to be broken, maybe because the operations involved (log, sqrt) are too slow, but this is just an assumption... This was my test code, located in src/AudioEffects/SoundGenerator.h:
Does anyone come up with an idea? It would be very helpful. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I suggest to plot the result to a CsvStream so that you can visually check if the data looks random or if there is another issue. All data should be between -32767.0 and +32767.0 Did you already try to use the standard c++ function instead? Finally I suggest that you create a separate class with a different name. If you have it working I would be interested in a pull request. |
Beta Was this translation helpful? Give feedback.
I suggest to plot the result to a CsvStream so that you can visually check if the data looks random or if there is another issue. All data should be between -32767.0 and +32767.0
If your assumption is right you can try to lower the sample rate or you can measure the number of samples that you can generate in 1 second, to determine the max sample rate that you can use.
Did you already try to use the standard c++ function instead?
Finally I suggest that you create a separate class with a different name. If you have it working I would be interested in a pull request.