-
-
Save volalex/799789663f8c29f1bb58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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