Package samer.audio
Class FileSource
- java.lang.Object
-
- Viewable
-
- samer.audio.FileSource
-
- All Implemented Interfaces:
- AudioSource
public class FileSource 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. If the loop flag is true, then samples are returned indefinitely by looping through the playlist; otherwise, an EOFException is thrown if an attempt is made to read beyond the end of the last file. FileSource is a Viewable called "playlist", and an Agent with commands next, prev, reopen, view, select, loop. Properties read from current environment:- current
- Current file (String)
- loop
- Loop playlist? (Boolean) [true]
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface samer.audio.AudioSource
AudioSource.Util
-
-
Constructor Summary
Constructors Constructor and Description FileSource()
Construct a FileSource initialised with current file and loop initialised from the current Environment.
-
Method Summary
All 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 streamvoid
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
getStreamFormat()
The actual format of the stream in.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.void
prev()
Move to head of previous file in playlistTask
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)
void
reopen()
Reopen current file, so that next read will be from head of file.void
rewind()
Go back to start of playlist.void
setBuffering(boolean b)
void
setDirectory(java.io.File dir, java.lang.String ext)
Set playlist to all WAV files in given directoryvoid
setLoop(boolean f)
If true then loop playlist, otherwise, an Exception will be thrown when the end of the playlist is reached.void
setPlaylist(java.util.List<java.io.File> l)
void
setTargetFormat(javax.sound.sampled.AudioFormat f)
-
-
-
Constructor Detail
-
FileSource
public FileSource()
Construct a FileSource initialised with current file and loop initialised from the current Environment. No exception is thrown if the current file cannot be opened, however, you must be sure to set it to a valid file (or to set a playlist) before trying to read any samples.
-
-
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
-
setBuffering
public void setBuffering(boolean b)
-
getStreamFormat
public javax.sound.sampled.AudioFormat getStreamFormat()
The actual format of the stream in. May not be same as target format.
-
getTargetFormat
public javax.sound.sampled.AudioFormat getTargetFormat()
The requested audio format.
-
setTargetFormat
public void setTargetFormat(javax.sound.sampled.AudioFormat f)
-
setLoop
public void setLoop(boolean f)
If true then loop playlist, otherwise, an Exception will be thrown when the end of the playlist is reached. If there is no playlist, then looping applies to the current file only.
-
setDirectory
public void setDirectory(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()
-
setPlaylist
public void setPlaylist(java.util.List<java.io.File> l)
-
rewind
public void rewind() throws java.lang.Exception
Go back to start of playlist. Next block of samples will be from head of first file in playlist. Will throw an exception if there is no playlist- Throws:
java.lang.Exception
-
next
public void next() throws java.lang.Exception
Move to head of next file in playlist- Throws:
java.lang.Exception
-
prev
public void prev() throws java.lang.Exception
Move to head of previous 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
-
reopen
public void reopen() throws java.lang.Exception
Reopen current file, so that next read will be from head of 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()
-
-