Package samer.audio
Class FileSource2
- java.lang.Object
-
- Viewable
-
- samer.audio.FileSource2
-
- All Implemented Interfaces:
- AudioSource
public class FileSource2 extends Viewable implements AudioSource
An AudioSource that read from multiple audio files. Can read any format for which the appropriate JavaSound plug-in is installed on your system, eg WAV, AU, MP3, OGG. The implementation of AudioSource.reader() returns a Task which gets samples from the audio files, going through the play list one by one. An EOFException is thrown if an attempt is made to read beyond the end of the last file. FileSource2 is a Viewable called "playlist", and an Agent with commands next, view.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface samer.audio.AudioSource
AudioSource.Util
-
-
Constructor Summary
Constructors Constructor and Description FileSource2(javax.sound.sampled.AudioFormat targetFormat, java.util.List<java.io.File> files)
Construct a FileSource2.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description int
available()
Returns number of bytes available in current filevoid
close()
Closes current input streamstatic java.util.List<java.io.File>
directory(java.io.File dir, java.lang.String ext)
Set playlist to all WAV files in given directoryvoid
dispose()
void
execute(java.lang.String cmd, Environment env)
int
getChannels()
void
getCommands(Agent.Registry r)
java.io.File
getFile()
Returns current filejava.util.List<java.io.File>
getPlaylist()
float
getRate()
javax.sound.sampled.AudioFormat
getTargetFormat()
The requested audio format.Viewer
getViewer()
boolean
isOpen()
void
next()
Move to head of next file in playlistvoid
open()
Opens the playlist starting with the first file.Task
reader(double[] dbuf, int off, int len)
Returns a Task which copies samples as doubles into the given buffer between the given positions.Task
reader(float[] dbuf, int off, int len)
Returns a Task which copies samples as floats into the given buffer between the given positions.int
readInto(java.nio.ByteBuffer buf, int offset, int len)
-
-
-
Constructor Detail
-
FileSource2
public FileSource2(javax.sound.sampled.AudioFormat targetFormat, java.util.List<java.io.File> files)
Construct a FileSource2.
-
-
Method Detail
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceAudioSource
-
getChannels
public int getChannels()
- Specified by:
getChannels
in interfaceAudioSource
-
getRate
public float getRate()
- Specified by:
getRate
in interfaceAudioSource
-
getFile
public java.io.File getFile()
Returns current file
-
getTargetFormat
public javax.sound.sampled.AudioFormat getTargetFormat()
The requested audio format.
-
directory
public static java.util.List<java.io.File> directory(java.io.File dir, java.lang.String ext)
Set playlist to all WAV files in given directory
-
getPlaylist
public java.util.List<java.io.File> getPlaylist()
-
next
public void next() throws java.lang.Exception
Move to head of next file in playlist- Throws:
java.lang.Exception
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfaceAudioSource
-
close
public void close()
Closes current input stream- Specified by:
close
in interfaceAudioSource
-
open
public void open() throws java.lang.Exception
Opens the playlist starting with the first file.- Specified by:
open
in interfaceAudioSource
- Throws:
java.lang.Exception
-
available
public int available() throws java.lang.Exception
Returns number of bytes available in current file- Throws:
java.lang.Exception
-
readInto
public int readInto(java.nio.ByteBuffer buf, int offset, int len) throws java.io.IOException
- Throws:
java.io.IOException
-
reader
public Task reader(double[] dbuf, int off, int len)
Returns a Task which copies samples as doubles into the given buffer between the given positions.- Specified by:
reader
in interfaceAudioSource
-
reader
public Task reader(float[] dbuf, int off, int len)
Returns a Task which copies samples as floats into the given buffer between the given positions.- Specified by:
reader
in interfaceAudioSource
-
getCommands
public void getCommands(Agent.Registry r)
-
execute
public void execute(java.lang.String cmd, Environment env) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getViewer
public Viewer getViewer()
-
-