sampled
Class AudioFileReader

java.lang.Object
  extended by sampled.AudioFileReader
All Implemented Interfaces:
AudioSource

public final class AudioFileReader
extends java.lang.Object
implements AudioSource

Use the AudioFileReader to read from an audio file. Supported are all kinds of raw, Mu- and A-law compressed data in various frame and bit rates. Check the RawAudioFormat class for more details on supported file types. Can use the WAV headers to automatically adjust the parameters.

Author:
sikoried

Field Summary
static double DEFAULT_PREEMPHASIS_FACTOR
           
static java.lang.String synopsis
           
 
Constructor Summary
AudioFileReader(RawAudioFormat format, byte[] data)
          Construct an AudioFileReader which reads from an already available byte array.
AudioFileReader(java.lang.String fileName, boolean cacheFile)
          Construct an AudioFileReader using WAV header data
AudioFileReader(java.lang.String fileName, RawAudioFormat format, boolean cacheFile)
          Construct an AudioFileReader using a custom RawAudioFormat
 
Method Summary
 boolean getPreEmphasis()
          Does the AudioSource perform pre-emphasis?
 int getSampleRate()
          Return the sampling rate of the loaded audio file
static void main(java.lang.String[] args)
           
static void preEmphasize(double[] buf, double a, double s0)
          Perform a pre-emphasis on the given signal vector: x'(n) = x(n) - a * x(n-1) with s0 = x(-1)
 int read(double[] buf)
          Read a number of samples from the audio file and save it to the given buffer.
 void setPreEmphasis(boolean applyPreEmphasis, double a)
          Toggle the pre-emphasis of the audio signal
 void tearDown()
          Tear down the AudioSource (i.e.
 java.lang.String toString()
          Get a string representation of the source
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_PREEMPHASIS_FACTOR

public static double DEFAULT_PREEMPHASIS_FACTOR

synopsis

public static java.lang.String synopsis
Constructor Detail

AudioFileReader

public AudioFileReader(RawAudioFormat format,
                       byte[] data)
                throws java.io.IOException
Construct an AudioFileReader which reads from an already available byte array.

Parameters:
format - RawAudioFormat describing the data
data - byte array with read audio data
Throws:
java.io.IOException

AudioFileReader

public AudioFileReader(java.lang.String fileName,
                       boolean cacheFile)
                throws javax.sound.sampled.UnsupportedAudioFileException,
                       java.io.IOException
Construct an AudioFileReader using WAV header data

Parameters:
fileName -
cacheFile - use buffered reader?
Throws:
javax.sound.sampled.UnsupportedAudioFileException
java.io.IOException

AudioFileReader

public AudioFileReader(java.lang.String fileName,
                       RawAudioFormat format,
                       boolean cacheFile)
                throws java.io.IOException
Construct an AudioFileReader using a custom RawAudioFormat

Parameters:
fileName -
format - if null, it will be determined by the header
cacheFile - use buffered reader?
Throws:
javax.sound.sampled.UnsupportedAudioFileException
java.io.IOException
See Also:
RawAudioFormat.create
Method Detail

getPreEmphasis

public boolean getPreEmphasis()
Description copied from interface: AudioSource
Does the AudioSource perform pre-emphasis?

Specified by:
getPreEmphasis in interface AudioSource

getSampleRate

public int getSampleRate()
Return the sampling rate of the loaded audio file

Specified by:
getSampleRate in interface AudioSource
Returns:
number of samples per second

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        javax.sound.sampled.UnsupportedAudioFileException,
                        MalformedParameterStringException
Throws:
java.io.IOException
javax.sound.sampled.UnsupportedAudioFileException
MalformedParameterStringException

preEmphasize

public static void preEmphasize(double[] buf,
                                double a,
                                double s0)
Perform a pre-emphasis on the given signal vector: x'(n) = x(n) - a * x(n-1) with s0 = x(-1)

Parameters:
buf - audio frame; in-place transformation!
a - pre-emphasis factor
s0 - value to use for first element

read

public int read(double[] buf)
         throws java.io.IOException
Read a number of samples from the audio file and save it to the given buffer. Takes care of signedness and endianess. Samples are normalized by the bit rate (and thus [-1;1])

Specified by:
read in interface AudioSource
Parameters:
buf - double buffer; will try to read as many samples as fit in the buffer
Returns:
number of samples actually read
Throws:
java.io.IOException

setPreEmphasis

public void setPreEmphasis(boolean applyPreEmphasis,
                           double a)
Description copied from interface: AudioSource
Toggle the pre-emphasis of the audio signal

Specified by:
setPreEmphasis in interface AudioSource
Parameters:
applyPreEmphasis - apply pre-emphasis?
a - the pre-emphasis factor: x'(n) = x(n) - a*x(n-1)

tearDown

public void tearDown()
Description copied from interface: AudioSource
Tear down the AudioSource (i.e. release file handlers, etc)

Specified by:
tearDown in interface AudioSource

toString

public java.lang.String toString()
Description copied from interface: AudioSource
Get a string representation of the source

Specified by:
toString in interface AudioSource
Overrides:
toString in class java.lang.Object