Skip to content

Instantly share code, notes, and snippets.

@volalex
Last active March 23, 2016 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save volalex/799789663f8c29f1bb58 to your computer and use it in GitHub Desktop.
Save volalex/799789663f8c29f1bb58 to your computer and use it in GitHub Desktop.
frequency = new Random.nextInt(30)+220;
public static byte[] genSynNoise(AudioFormat format, double length,int frequency){
int samplesCount = (int) (length * format.getSampleRate());
ByteBuffer noiseBuffer = ByteBuffer.allocate(samplesCount*2);
double period = format.getSampleRate()/frequency;
for (int i=0;i<samplesCount;i++){
double n = Short.MAX_VALUE/4 * Math.sin(2*Math.PI*i/period);
noiseBuffer.putShort((short) n);
}
return noiseBuffer.array();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment