I would like to create a colored noise generator using Java that will be able to generate all of the colors defined in this article: http://en.wikipedia.org/wiki/Colors_of_noise
- Starting with the simplest one, White Noise, how would I generate the noise so that it can play indefinitely?
- From there, how would I modify my generator to generate any of the colors?
I am both confused about how to generate the noise itself, and confused about how once generated I can have it be output through the speakers.
Any links or tips would be very appreciated!
I've also looked at another question: Java generating sound
But I don't fully understand what is going on in the code given in one of the comments. It also doesn't tell me what noise would be generated with that code, and so I wouldn't know how to modify it so that it would generate white noise.
I'm actually currently working on a project for taking white noise and sampling it to produce random numbers. What you need is the reverse!
Sound is pressure vs time. Basically start with 0 pressure and add a random amount of pressure from -(max amplitude) to (max amplitude). The amplitude of white noise is random and normally distributed so you can use Random.nextGaussian() to generate random z-scores. Multiply the z-scores by the standard deviation (you may have to do some testing to find a standard deviation in the amplitude you like) and then let that be the amplitude for each sample in the audio file.
As far as generating the sound file itself, if you haven't already, you should look into Java Sound API. It features a lot of nice methods for both creating sound files as well as playback.
The next part of your question, the non-white noise, I'm afraid I'm not sure on what the waveforms look like. It probably follows the similar generate random z-scores and multiply them by some amplitude standard deviation (or more likely by some amplitude function that changes with time).