net.beadsproject.beads.data.audiofile
Class JavaSoundAudioFile

java.lang.Object
  extended by net.beadsproject.beads.data.audiofile.AudioFile
      extended by net.beadsproject.beads.data.audiofile.JavaSoundAudioFile

public class JavaSoundAudioFile
extends AudioFile

Uses javasound to load audio files located on disk or via a URL. KNOWN ISSUE: Certain .wav files will be not be able to be loaded. This is due to mp3spi recognizing them incorrectly as mp3s. This will hopefull be fixed in the future, but until then resaving your .wavs with a different audio util may help.

Author:
ben

Nested Class Summary
 
Nested classes/interfaces inherited from class net.beadsproject.beads.data.audiofile.AudioFile
AudioFile.OperationUnsupportedException
 
Field Summary
protected  javax.sound.sampled.AudioFileFormat audioFileFormat
           
protected  javax.sound.sampled.AudioInputStream audioInputStream
           
protected  java.io.File file
           
protected  java.net.URL url
           
 
Fields inherited from class net.beadsproject.beads.data.audiofile.AudioFile
audioFormat, audioInfo, length, name, nFrames, trace
 
Constructor Summary
JavaSoundAudioFile(java.io.InputStream stream)
           
JavaSoundAudioFile(java.io.InputStream stream, int bufferSize)
           
JavaSoundAudioFile(java.lang.String filename)
          Load an audio file from disk.
JavaSoundAudioFile(java.lang.String filename, int bufferSize)
          Advanced: Create an input stream from a file, but don't keep more than numBytes of data in memory.
 
Method Summary
 void close()
          Close the audio file.
static AudioFormat convertJavasoundAudioFormatToBeadsAudioFormat(javax.sound.sampled.AudioFormat af)
           
 javax.sound.sampled.AudioFormat getDecodedFormat()
           
 javax.sound.sampled.AudioFormat getEncodedFormat()
           
 java.lang.String getInformation()
           
 java.util.Map<java.lang.String,java.lang.Object> getProperties()
           
 long getTimeLengthEstimation(java.util.Map properties)
          THIS CODE IS FROM jlGui PlayerUI.java.
 boolean isClosed()
          Is the file stream closed?
 void open()
          Opens the audio file, ready for data access.
 int read(byte[] buffer)
          Read bytes directly from the decoded audiofile.
 int read(float[][] buffer)
          Read decoded audio data in a non-interleaved, Beads-friendly format.
 void reset()
          Reset the audio input stream.
 void seek(int frame)
          Seek to a specific frame number.
 void skip(long frames)
          Skips a number of frames.
 
Methods inherited from class net.beadsproject.beads.data.audiofile.AudioFile
getFormat, getFrameSize, getLength, getName, getNumChannels, getNumFrames, isOpen, setLength, setNumFrames, setTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

protected java.io.File file

url

protected java.net.URL url

audioInputStream

protected javax.sound.sampled.AudioInputStream audioInputStream

audioFileFormat

protected javax.sound.sampled.AudioFileFormat audioFileFormat
Constructor Detail

JavaSoundAudioFile

public JavaSoundAudioFile(java.lang.String filename)
                   throws java.io.IOException,
                          javax.sound.sampled.UnsupportedAudioFileException
Load an audio file from disk. The audiofile needs to be open()'ed before it's data can be read. Note: AudioFile provides low-level access to audio files -- If you just want to access the data of a sound file use a Sample.

Parameters:
filename - The name of the file to open.
Throws:
java.io.IOException - If the file cannot be found or opened.
javax.sound.sampled.UnsupportedAudioFileException - If the file is of an unsupported audio type.
See Also:
Sample

JavaSoundAudioFile

public JavaSoundAudioFile(java.lang.String filename,
                          int bufferSize)
                   throws java.io.IOException,
                          javax.sound.sampled.UnsupportedAudioFileException
Advanced: Create an input stream from a file, but don't keep more than numBytes of data in memory.

Parameters:
filename -
bufferSize - The maximum number of bytes the AudioFile can keep in memory. If it is <0 then the length of the audio file is used.
Throws:
java.io.IOException - If the file cannot be found or opened.
javax.sound.sampled.UnsupportedAudioFileException - If the file is of an unsupported audio type.
javax.sou

JavaSoundAudioFile

public JavaSoundAudioFile(java.io.InputStream stream)
                   throws java.io.IOException,
                          javax.sound.sampled.UnsupportedAudioFileException
Throws:
java.io.IOException
javax.sound.sampled.UnsupportedAudioFileException

JavaSoundAudioFile

public JavaSoundAudioFile(java.io.InputStream stream,
                          int bufferSize)
                   throws java.io.IOException,
                          javax.sound.sampled.UnsupportedAudioFileException
Throws:
java.io.IOException
javax.sound.sampled.UnsupportedAudioFileException
Method Detail

reset

public void reset()
Reset the audio input stream. For some audio formats, this may involve re-opening the associated file.

Overrides:
reset in class AudioFile

skip

public void skip(long frames)
Skips a number of frames. Note: this function skips frames, not bytes. Doesn't work for vbr! TODO: Known issue, MP3 seeking is not precise. Why?

Overrides:
skip in class AudioFile
Parameters:
frames - Number of frames to skip

seek

public void seek(int frame)
Seek to a specific frame number. Note that seeking is slower than skipping forward.

Overrides:
seek in class AudioFile
Parameters:
frame - The frame number, relative to the start of the audio data.

open

public void open()
          throws javax.sound.sampled.UnsupportedAudioFileException,
                 java.io.IOException
Opens the audio file, ready for data access.

Specified by:
open in class AudioFile
Throws:
javax.sound.sampled.UnsupportedAudioFileException
java.io.IOException

getInformation

public java.lang.String getInformation()
Overrides:
getInformation in class AudioFile
Returns:
Information about this audio file. The file should be open if specific information is required.

close

public void close()
           throws java.io.IOException
Close the audio file. Can be re-opened.

Specified by:
close in class AudioFile
Throws:
java.io.IOException

isClosed

public boolean isClosed()
Is the file stream closed?

Specified by:
isClosed in class AudioFile

getDecodedFormat

public javax.sound.sampled.AudioFormat getDecodedFormat()

getEncodedFormat

public javax.sound.sampled.AudioFormat getEncodedFormat()

read

public int read(byte[] buffer)
Read bytes directly from the decoded audiofile. The bytes will be in an interleaved format. It is the responsibility of the caller to interpret this data correctly. The number of bytes read is equal to the size of the byte buffer. If that many bytes aren't available the buffer will only be partially filled.

Specified by:
read in class AudioFile
Parameters:
buffer - A buffer to fill.
Returns:
The number of bytes read. A value of -1 indicates the file has no data left.

read

public int read(float[][] buffer)
Read decoded audio data in a non-interleaved, Beads-friendly format. Note: This function is extremely inefficient if the buffer size is constant. Use Sample, it is very efficient!

Specified by:
read in class AudioFile
Parameters:
buffer - The buffer to fill. After execution buffer[i][j] will contain the sample in channel i, frame j. Buffer has size (numChannels,numFramesRequested).
Returns:
The number of frames read.

getProperties

public java.util.Map<java.lang.String,java.lang.Object> getProperties()
Overrides:
getProperties in class AudioFile
Returns:
Any additional properties associated with this AudioFile.

getTimeLengthEstimation

public long getTimeLengthEstimation(java.util.Map properties)
THIS CODE IS FROM jlGui PlayerUI.java. jlGui can be obtained at: http://www.javazoom.net/jlgui/jlgui.html


convertJavasoundAudioFormatToBeadsAudioFormat

public static AudioFormat convertJavasoundAudioFormatToBeadsAudioFormat(javax.sound.sampled.AudioFormat af)