Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphing/Plotting a Wav File java

Tags:

java

im fairly new to java... i would like to plot a frequency/time graph or sample image from a wav file. to start off i am struggling to get the raw data array from the Wav file using AudioInputStream also referencing from Reading wav file in Java. I also tried the WavFile class referring http://www.labbookpages.co.uk/audio/javaWavFiles.html but when testing, i was unable to find the correct packages to satisfy the "WavFile" - "cannot find symbol" error. the supplied import java.io.*; for that sample didn't satisfy this...

to reiterate i wish to get a the raw data in array format of a Wav file.

i would love any small examples of this, as i learn from examples much easier! thanks for your time

like image 635
Mitchb Avatar asked May 19 '12 16:05

Mitchb


1 Answers

Skip first 44 bytes from the wav file (header), then read data using this function:

private static double readLEShort(RandomAccessFile f) {
try {
    byte b1 = (byte) f.read();
    byte b2 = (byte) f.read();
    return (double) (b2 << 8 | b1 & 0xFF) / 32767.0;
} catch (IOException e) {
    e.printStackTrace();
}
return 0;
}

One value for each channel. This will give you number between -1 and 1, which you can draw on your graph. I hope that may work

like image 176
Edgar Andrés Margffoy Tuay Avatar answered Oct 25 '22 07:10

Edgar Andrés Margffoy Tuay