Creating noise colors in Java

I would like to create a color noise generator using Java that can generate all the colors defined in this article: http://en.wikipedia.org/wiki/Colors_of_noise

  • Starting with the simplest, White Noise, how would I generate noise so it can play endlessly?
  • From there, how do I change the generator to generate any colors?

I, too, got confused about how to generate noise myself, and got confused about how once generated I can output it through the speakers.

Any links or tips would be greatly appreciated!

I also looked at another question: Java generating sound

But I do not quite understand what is happening in the code given in one of the comments. He also does not tell me what noise will be generated with this code, and therefore I do not know how to modify it so that it generates white noise.

+7
java audio noise noise-generator
source share
2 answers

Here is a program to create white noise in pure Java. It can be easily changed to generate other noise colors.

import javax.sound.sampled.*; import javax.swing.*; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.nio.ByteBuffer; import java.util.Random; public class WhiteNoise extends JFrame { private GeneratorThread generatorThread; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { WhiteNoise frame = new WhiteNoise(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public WhiteNoise() { addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { generatorThread.exit(); System.exit(0); } }); setTitle("White Noise Generator"); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 200, 50); setLocationRelativeTo(null); getContentPane().setLayout(new BorderLayout(0, 0)); generatorThread = new GeneratorThread(); generatorThread.start(); } class GeneratorThread extends Thread { final static public int SAMPLE_SIZE = 2; final static public int PACKET_SIZE = 5000; SourceDataLine line; public boolean exitExecution = false; public void run() { try { AudioFormat format = new AudioFormat(44100, 16, 1, true, true); DataLine.Info info = new DataLine.Info(SourceDataLine.class, format, PACKET_SIZE * 2); if (!AudioSystem.isLineSupported(info)) { throw new LineUnavailableException(); } line = (SourceDataLine)AudioSystem.getLine(info); line.open(format); line.start(); } catch (LineUnavailableException e) { e.printStackTrace(); System.exit(-1); } ByteBuffer buffer = ByteBuffer.allocate(PACKET_SIZE); Random random = new Random(); while (exitExecution == false) { buffer.clear(); for (int i=0; i < PACKET_SIZE /SAMPLE_SIZE; i++) { buffer.putShort((short) (random.nextGaussian() * Short.MAX_VALUE)); } line.write(buffer.array(), 0, buffer.position()); } line.drain(); line.close(); } public void exit() { exitExecution =true; } } } 
+3
source share

I am currently working on a project to get white noise and select it to create random numbers. What you need is the other way around!

Sound is pressure and time. Basically start with pressure 0 and add a random amount of pressure from - (max. Amplitude) to (max. Amplitude). The amplitude of white noise is random and usually distributed, so you can use Random.nextGaussian () to generate random z-points. Multiply the z-scores by the standard deviation (you may have to do some testing to find the standard deviation in amplitude that you like) and then let it be the amplitude for each sample in the audio file.

Regarding the creation of the sound file itself, if you have not already done so, you should study the Java Sound API . It has many good methods for creating sound files, as well as for playing.

The next part of your question, not white noise, I'm afraid I don’t know what the waveforms look like. This probably follows similar generating random z-estimates and multiply them by the standard deviation of the amplitude (or, most likely, by some amplitude function that changes with time).

+1
source share

All Articles