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