ddf.minim
Class AudioFileOut

java.lang.Object
  extended byddf.minim.AudioFileOut
All Implemented Interfaces:
ARListener
Direct Known Subclasses:
BufferedFileOut, StreamFileOut

public abstract class AudioFileOut
extends java.lang.Object
implements ARListener

AudioFileOut acts as the base class for classes that write audio files to disk. When you ask Minim for an AudioFileOut you will be returned a specific derived class, depending on whether you requested buffered recording or not. The difference between buffered recording and unbuffered recording is that buffered recording writes to an in-memory array and then pushes the entire array into a file when you call save, while unbuffered recording writes directly to disk as it receives data and then back-patches the file when asked to save. Back-patching is simply modifying the file header to reflect the actual length of the file, since it could not be known at the outset.

It should be noted that currently the only file formats supported by unbuffered recording are AIFF, AU, and WAV. Whereas buffered recording can also save as AIFC and SND (or at least is should be able to, it may depend on the system). A second major difference is that with buffered recording the file format can be specified at save time. This is because the file is not actually created until save is called. This fact also makes it possible to save the same recording buffer to multiple file formats by simply calling save(javax.sound.sampled.AudioFileFormat.Type) with each format desired. This is not possible with unbuffered recording because the file must be opened before any audio is written and therefore the file format must be specified at the outset and cannot be changed later.

When specifying the name for the file in the constructor or in setName(), do not include the file extension, it will be added based on the file format you request.

Author:
Damien Di Fede

Field Summary
static javax.sound.sampled.AudioFileFormat.Type AIFC
          The .aifc file format.
static javax.sound.sampled.AudioFileFormat.Type AIFF
          The .aiff file format.
static javax.sound.sampled.AudioFileFormat.Type AU
          The .au file format.
protected  java.lang.String filename
           
protected  javax.sound.sampled.AudioFileFormat.Type fileType
           
protected  javax.sound.sampled.AudioFormat format
           
protected  boolean recording
           
static javax.sound.sampled.AudioFileFormat.Type SND
          The .snd file format.
static javax.sound.sampled.AudioFileFormat.Type WAV
          The .wav file format.
 
Constructor Summary
AudioFileOut(javax.sound.sampled.AudioFormat format, java.lang.String name)
          Constructs an AudioFileOut from the passed AudioFormat and filename.
 
Method Summary
 boolean isRecording()
           
abstract  void save()
          Saves the recorded audio.
abstract  void save(javax.sound.sampled.AudioFileFormat.Type fileType)
          Saves the recorded audio in the requested file format.
 void setName(java.lang.String name)
          Sets the name of the file being saved to.
 void setType(javax.sound.sampled.AudioFileFormat.Type type)
          Sets the file format that will be used for saving.
 void startRecording()
          Starts recording audio.
 void stopRecording()
          Stops recording audio.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ddf.minim.ARListener
readSamples
 

Field Detail

WAV

public static javax.sound.sampled.AudioFileFormat.Type WAV
The .wav file format.


AIFF

public static javax.sound.sampled.AudioFileFormat.Type AIFF
The .aiff file format.


AIFC

public static javax.sound.sampled.AudioFileFormat.Type AIFC
The .aifc file format.


AU

public static javax.sound.sampled.AudioFileFormat.Type AU
The .au file format.


SND

public static javax.sound.sampled.AudioFileFormat.Type SND
The .snd file format.


format

protected javax.sound.sampled.AudioFormat format

filename

protected java.lang.String filename

fileType

protected javax.sound.sampled.AudioFileFormat.Type fileType

recording

protected boolean recording
Constructor Detail

AudioFileOut

public AudioFileOut(javax.sound.sampled.AudioFormat format,
                    java.lang.String name)
Constructs an AudioFileOut from the passed AudioFormat and filename.

Parameters:
format - the audio format of the audio that will be recorded
name - the name of the file to save to (without the extension)
Method Detail

startRecording

public void startRecording()
Starts recording audio. This also works as a resume function because the recorded material is kept until save is called.


stopRecording

public void stopRecording()
Stops recording audio. This also works as a pause function because the recorded material is kept until save is called.


isRecording

public boolean isRecording()
Returns:
whether or not recording is in process

setName

public void setName(java.lang.String name)
Sets the name of the file being saved to. In the case of buffered recording this could be called between sucessive calls to save. In the case of unbuffered recording this must be called before recording begins.

Parameters:
name - the name of the file (without the extension)
See Also:
#setName(String)

setType

public void setType(javax.sound.sampled.AudioFileFormat.Type type)
Sets the file format that will be used for saving. In the case of buffered recording this could be called between sucessive calls to save. In the case of unbuffered recording this must be called before recording begins.

Parameters:
type -
See Also:
#setType(javax.sound.sampled.AudioFileFormat.Type)

save

public abstract void save()
Saves the recorded audio.

See Also:
#save(), #save()

save

public abstract void save(javax.sound.sampled.AudioFileFormat.Type fileType)
Saves the recorded audio in the requested file format.

Parameters:
fileType - the file format to save the recorded audio as
See Also:
#save(javax.sound.sampled.AudioFileFormat.Type), #save(javax.sound.sampled.AudioFileFormat.Type)