Package org.jamdev.jpamutils.wavFiles
Class WavFile
java.lang.Object
javax.sound.sampled.spi.AudioFileReader
org.jamdev.jpamutils.wavFiles.WavFile
public class WavFile extends AudioFileReader
A WAV file reader. Modified to be more object orientated.
This code reads WAV files.
There are many decent documents on the web describing the WAV file
format. I didn't bother looking for the official document. If it
exists, I'm not even sure if it is freely available. We should
update this comment if we find out anything helpful here. I used
http://www.sonicspot.com/guide/wavefiles.html
- Author:
- Anthony Green (green@redhat.com), Jamie Macaulay
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description AudioFileFormatgetAudioFileFormat()AudioFileFormatgetAudioFileFormat(File file)AudioFileFormatgetAudioFileFormat(InputStream in)AudioFileFormatgetAudioFileFormat(URL url)AudioInputStreamgetAudioInputStream()AudioInputStreamgetAudioInputStream(File file)AudioInputStreamgetAudioInputStream(InputStream stream)AudioInputStreamgetAudioInputStream(URL url)intgetByteLength()Get the length of the file in bytes,FilegetFile()Get the file object for the .wav file.URLgetFileURL()Get the file object for the .wav file.static int[]getSampleAmplitudes(AudioFormat wavHeader, byte[] data)Get the amplitudes of the wave samples (depends on the header)static byte[]getSingleChannelByte(AudioFormat wavHeader, byte[] bytes, int channel)Get a multi channel .wav file and return the byte stream for just one of the channels.static byte[]trim(AudioFormat wavHeader, byte[] bytes, int maxSamples)Trim the byte data.
-
Constructor Details
-
Method Details
-
getAudioFileFormat
public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException- Specified by:
getAudioFileFormatin classAudioFileReader- Throws:
UnsupportedAudioFileExceptionIOException
-
getAudioFileFormat
-
getAudioFileFormat
public AudioFileFormat getAudioFileFormat(InputStream in) throws UnsupportedAudioFileException, IOException- Specified by:
getAudioFileFormatin classAudioFileReader- Throws:
UnsupportedAudioFileExceptionIOException
-
getAudioFileFormat
public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException- Specified by:
getAudioFileFormatin classAudioFileReader- Throws:
UnsupportedAudioFileExceptionIOException
-
getAudioInputStream
public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException- Specified by:
getAudioInputStreamin classAudioFileReader- Throws:
UnsupportedAudioFileExceptionIOException
-
getAudioInputStream
-
getAudioInputStream
public AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException- Specified by:
getAudioInputStreamin classAudioFileReader- Throws:
UnsupportedAudioFileExceptionIOException
-
getAudioInputStream
public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException- Specified by:
getAudioInputStreamin classAudioFileReader- Throws:
UnsupportedAudioFileExceptionIOException
-
getSampleAmplitudes
Get the amplitudes of the wave samples (depends on the header)- Returns:
- amplitudes array (signed 16-bit)
-
trim
Trim the byte data. Trimmed from center left and right so that the size is no larger than maxSamples.- Parameters:
wavHeader- - the wave file headerbytes- - a SINGLE-channel byte arraymaxSamples- - the sample size of the trimmed clip.- Returns:
- the byte array for one channel.
-
getSingleChannelByte
Get a multi channel .wav file and return the byte stream for just one of the channels.- Parameters:
wavHeader- - the wave file headerbytes- - the multi-channel byte arraychannel- - the channel to extract. This should never be higher than the total number of channels.- Returns:
- the byte array for one channel.
-
getFile
Get the file object for the .wav file.- Returns:
- the file object.
-
getFileURL
Get the file object for the .wav file.- Returns:
- the file object.
-
getByteLength
public int getByteLength()Get the length of the file in bytes,- Returns:
- the length of the file in bytes
-