I have some code that collects amplitudes from a complex sound like a song. I now want to plot a graph of amplitude vs time, for the graph plotting I use JavaFX. However I get about 9 million amplitude shorts for each channel, so how to I select a few samples to plot (as plotting 9 million points is obviously out of the question)? Do I need to use the sample rate or sample size? Is there a particular way I should go about this?
Is this post more suited for StackOverflow?
AudioInputStream in = AudioSystem.getAudioInputStream(file);
AudioInputStream din = null;
AudioFormat baseFormat = in.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(), //sample rate
16, //sample size (bits)
baseFormat.getChannels(), //channels
baseFormat.getChannels() * 2,//frame size
baseFormat.getSampleRate(), //frame rate
false); //little-endian
din = AudioSystem.getAudioInputStream(decodedFormat, in);
byte[] temp = new byte[4];
//....
//leftDos and rightDos are streams of shorts
//....
int i = 0;
while (din.read(temp, 0, 4) != -1) {
if (decodedFormat.getChannels() == 2) {
leftDos.writeShort(temp[1] * 256 + temp[0]);
rightDos.writeShort(temp[3] * 256 + temp[2]);
i++;
}
}
//...retrieve shorts...//
short[] left = new short[(bytes.length / 2)];
int len = 0;
try {
while (1 > 0) {
left[len] = leftDIS.readShort();
len++;
}
} catch (EOFException e) {
System.err.println("End of stream");
}