sampled
Class RawAudioFormat

java.lang.Object
  extended by sampled.RawAudioFormat

public class RawAudioFormat
extends java.lang.Object

Format holder for (raw) audio file formats including WAV. Note that the Java Sound API rejects Mu-law and A-law, and maybe mistaken on WAV files with unsigned data (which is pretty-nonstandard anyways). Multi-channel files are NOT supported.

Author:
sikoried

Constructor Summary
RawAudioFormat()
          Default: 16kHz, 16bit, signed, little endian, no header
RawAudioFormat(javax.sound.sampled.AudioFormat af)
          Construct a RawAudioFormat from an AudioFormat, assuming a WAV header of size WAV_HEADER_SIZE (44) bytes.
 
Method Summary
static RawAudioFormat create(java.lang.String parameterString)
          Generate a RawAudioFormat from the given parameterString.
static RawAudioFormat getAudioFormat(java.lang.String key)
          Query common (headerless) RawAudioFormats:
ssg/16: signed, little endian, 16kHz, 16bit
ssg/8: signed, little endian, 8kHz, 16bit
ulaw/16: Mu-law compressed, little endian, 16kHz
ulaw/8: Mu-law compressed, little endian, 8kHz
alaw/16: A-law compressed, little endian, 16kHz
alaw/8: A-law compressed, little endian, 8kHz
Use RawAudioFormat.setWavHeader() to add the default WAV header; access RawAudioFormat.hs to set header size manually.
 int getBitRate()
           
static java.lang.String getPredefinedAudioFormats()
          Return a (String) list of predefined audio formats
static RawAudioFormat getRawAudioFormatFromFile(java.lang.String fileName)
          Try to query the RawAudioFormat from the header in the given file
 int getSampleRate()
           
static void main(java.lang.String[] args)
           
 void setWavHeader()
          Set the default header size (WAV_HEADER_SIZE)
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RawAudioFormat

public RawAudioFormat()
Default: 16kHz, 16bit, signed, little endian, no header


RawAudioFormat

public RawAudioFormat(javax.sound.sampled.AudioFormat af)
               throws java.io.IOException
Construct a RawAudioFormat from an AudioFormat, assuming a WAV header of size WAV_HEADER_SIZE (44) bytes.

Parameters:
af - AudioFormat (e.g. from AudioSystem.getAudioFileFormat(File).
Throws:
java.io.IOException
Method Detail

create

public static RawAudioFormat create(java.lang.String parameterString)
                             throws MalformedParameterStringException,
                                    javax.sound.sampled.UnsupportedAudioFileException,
                                    java.io.IOException
Generate a RawAudioFormat from the given parameterString. Possible strings are: "f:path-to-file": extract format from file "t:template-name": get format from template: ssg/[8,16], alaw/[8,16], ulaw/[8,16] "r:bit-rate,sample-rate,signed(0|1),little-endian(0|1)": raw as specified (noheader)

Parameters:
parameterString - parameter string (f:filename, t:template, r:raw-params)
Returns:
ready-to-use format instance
Throws:
MalformedParameterStringException
javax.sound.sampled.UnsupportedAudioFileException
java.io.IOException
See Also:
getAudioFormat

getAudioFormat

public static RawAudioFormat getAudioFormat(java.lang.String key)
                                     throws javax.sound.sampled.UnsupportedAudioFileException
Query common (headerless) RawAudioFormats:
ssg/16: signed, little endian, 16kHz, 16bit
ssg/8: signed, little endian, 8kHz, 16bit
ulaw/16: Mu-law compressed, little endian, 16kHz
ulaw/8: Mu-law compressed, little endian, 8kHz
alaw/16: A-law compressed, little endian, 16kHz
alaw/8: A-law compressed, little endian, 8kHz
Use RawAudioFormat.setWavHeader() to add the default WAV header; access RawAudioFormat.hs to set header size manually.

Parameters:
key - Key from list above
Returns:
requested RawAudioFormat
Throws:
javax.sound.sampled.UnsupportedAudioFileException

getBitRate

public int getBitRate()

getPredefinedAudioFormats

public static java.lang.String getPredefinedAudioFormats()
Return a (String) list of predefined audio formats

Returns:
String containing all predefined audio formats

getRawAudioFormatFromFile

public static RawAudioFormat getRawAudioFormatFromFile(java.lang.String fileName)
                                                throws javax.sound.sampled.UnsupportedAudioFileException,
                                                       java.io.IOException
Try to query the RawAudioFormat from the header in the given file

Parameters:
fileName -
Returns:
extracted RawAudioFormat
Throws:
javax.sound.sampled.UnsupportedAudioFileException
java.io.IOException

getSampleRate

public int getSampleRate()

main

public static void main(java.lang.String[] args)

setWavHeader

public void setWavHeader()
Set the default header size (WAV_HEADER_SIZE)


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object