Skip to content

Instantly share code, notes, and snippets.

Last active March 23, 2016 19:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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