6

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

Community
  • 1
  • 1
Mitchb
  • 159
  • 3
  • 13

2 Answers2

3

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

0

In my Java DSP collection there is a test program named TestSignalPlot.java that can display WAV files. It uses AudioIo.loadWavFile() to load the WAV file content into memory and the SignalPlot class to display the audio signal. All classes are part of the open-source collection.

Christian d'Heureuse
  • 5,090
  • 1
  • 32
  • 28