Hi does anyone know how to find the amplitudes within a WAV file in Java? If the file was stereo (or has more channels) how can the data be put into arrays?
Thanks!
Hi does anyone know how to find the amplitudes within a WAV file in Java? If the file was stereo (or has more channels) how can the data be put into arrays?
Thanks!
Processing a WAV file header
Next trick is a bit more of a challenge as the internal data format could be a variety of data types. If you are looking at your classic windows WAV file, it is probably just PCM 16 bit or maybe 8 bit. Which, means, you can easily load the data into a byte or short array.
However, you will find other formats. When you know the type you have, google it. You'll find information for most.
How to open a WAVE from inputStream
After that, a typicall WAVE file is PCM encoded (there a other codecs, like floats). You have to read the samples from
markSupportedInputStream
.PCM includes many combinations of parameters: (Mono|Stereo), (Signed|Unsigned), (8 Bit|16 Bit), (Big Endian|Little Endian for more than 8 Bit). You can figure out this on the
format
object likeformat.getChannels()
. For this reason I have written aPcmCodec
class with methods likedecodeUnsigned16BitLittleEndian(buffer, offset)
. And I normalize the sample values to [-1,1].Here is how I figure out what PCM it is:
Here is an example how I decode a special PCM: You need to read from
markSupportedInputStream
into a byte array (buffer). After that, you can decode the bytes: