net.charlesames.utility.audio
Class AudioSampleReader

java.lang.Object
  extended by net.charlesames.utility.audio.AudioSampleReader

public class AudioSampleReader
extends java.lang.Object

Example methods for processing audio files.
The code source is http://www.builogic.com/java/javasound-read-write.html

Author:
Unknown

Constructor Summary
AudioSampleReader(java.io.File file)
          Constructor for AudioSampleReader instances
 
Method Summary
 void getChannelSamples(int channel, double[] interleavedSamples, double[] channelSamples)
          Extract samples of a particular channel.
 javax.sound.sampled.AudioFormat getFormat()
           
 void getInterleavedSamples(long begin, long end, double[] samples)
          Get the interleaved decoded samples for all channels.
 long getSampleCount()
           
 void getStereoSamples(double[] leftSamples, double[] rightSamples)
          Convenience module.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AudioSampleReader

public AudioSampleReader(java.io.File file)
                  throws javax.sound.sampled.UnsupportedAudioFileException,
                         java.io.IOException
Constructor for AudioSampleReader instances

Parameters:
file - The Audio File
Throws:
javax.sound.sampled.UnsupportedAudioFileException
java.io.IOException
Method Detail

getFormat

public javax.sound.sampled.AudioFormat getFormat()
Returns:
The audio format contains most properties of the audio file: sample size, sample rate, etc.

getSampleCount

public long getSampleCount()
Returns:
The number of samples of all channels.

getInterleavedSamples

public void getInterleavedSamples(long begin,
                                  long end,
                                  double[] samples)
                           throws java.io.IOException
Get the interleaved decoded samples for all channels. The number of samples must not be so large that the associated byte array cannot be allocated.

Parameters:
begin - Starting sample index (included)
end - Ending sample index (excluded). Must not exceed getSampleCount().
samples - Receives the decoded samples.
Throws:
java.io.IOException
java.lang.IllegalArgumentException

getChannelSamples

public void getChannelSamples(int channel,
                              double[] interleavedSamples,
                              double[] channelSamples)
Extract samples of a particular channel.

Parameters:
channel - The desired channel
interleavedSamples - An array of interleaved samples.
channelSamples - Receives the extracted samples.

getStereoSamples

public void getStereoSamples(double[] leftSamples,
                             double[] rightSamples)
                      throws java.io.IOException
Convenience module. Extract left and right channels for common stereo files.

Parameters:
leftSamples - Receives samples extracted for the left channel. Must be of size getSampleCount().
rightSamples - Receives samples extracted for the right channel. Must be of size getSampleCount().
Throws:
java.io.IOException