com.groovemanager.sampled.nondestructive
Class AudioFileSource

java.lang.Object
  extended by com.groovemanager.sampled.nondestructive.AbstractSource
      extended by com.groovemanager.sampled.nondestructive.AudioFileSource
All Implemented Interfaces:
CutListSource

public class AudioFileSource
extends AbstractSource
implements CutListSource

A CutListSource that gets its audio data from an audio file

Author:
Manu Robledo

Field Summary
private  java.io.File f
          The audio file containing the audio data
private  int frameSize
          The frame size of the audio file´s format
private  int length
          The length of the audio data in the file in sample frames
private  AudioFileWaveForm wf
          The AudioFileWaveForm corresponding to the audio file
 
Constructor Summary
AudioFileSource(java.io.File source, AudioFileWaveForm wf)
          Construct a new AudioFileSource out of the given file and WaveForm
 
Method Summary
 void appendFrames(int numFrames)
          Append the given number of frames to the audio data´s length.
 CutListSource duplicate()
          Create a new CutListSource that represents the same data, but is independent of changes made to this source
 javax.sound.sampled.AudioInputStream getAudioInputStream(int start, int length)
          Get an AudioInputStream from this source
 int getLength()
          Get the total length of this source in sample frames
 WaveForm getWaveForm(int start, int length, int width)
          Get a WaveForm from this source
 boolean isReady()
          Ask this source, if it is ready for providing audio data
 void replaceFile(java.io.File from, java.io.File to)
          Replace all references to the given source file inside this CutListSource with references to the given target file.
 boolean usesFile(java.io.File f)
          Ask this CutListSource whether it relies on the contents of the given file.
 
Methods inherited from class com.groovemanager.sampled.nondestructive.AbstractSource
addModificationListener, notifyListeners, removeModificationListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.groovemanager.sampled.nondestructive.CutListSource
addModificationListener, removeModificationListener
 

Field Detail

f

private java.io.File f
The audio file containing the audio data


frameSize

private int frameSize
The frame size of the audio file´s format


length

private int length
The length of the audio data in the file in sample frames


wf

private AudioFileWaveForm wf
The AudioFileWaveForm corresponding to the audio file

Constructor Detail

AudioFileSource

public AudioFileSource(java.io.File source,
                       AudioFileWaveForm wf)
Construct a new AudioFileSource out of the given file and WaveForm

Parameters:
source - The audio file containing the audio data
wf - The AudioFileWaveForm corresponding to the file
Throws:
java.lang.IllegalArgumentException - If the audio file can not be read
Method Detail

appendFrames

public void appendFrames(int numFrames)
Append the given number of frames to the audio data´s length. This method can be used when the source file is still growing. This will be the case for instance in a recording situation

Parameters:
numFrames - The number of sample frames to append

duplicate

public CutListSource duplicate()
Description copied from interface: CutListSource
Create a new CutListSource that represents the same data, but is independent of changes made to this source

Specified by:
duplicate in interface CutListSource
Returns:
An independent copy of this source
See Also:
CutListSource.duplicate()

getAudioInputStream

public javax.sound.sampled.AudioInputStream getAudioInputStream(int start,
                                                                int length)
                                                         throws NotReadyException
Description copied from interface: CutListSource
Get an AudioInputStream from this source

Specified by:
getAudioInputStream in interface CutListSource
Parameters:
start - The start position of the stream in sample frames
length - The length of the stream in sample frames
Returns:
An AudioInputStream starting at position start of this source with the length of length sample frames.
Throws:
NotReadyException - If the audio data can not be provided
See Also:
CutListSource.getAudioInputStream(int, int)

getLength

public int getLength()
Description copied from interface: CutListSource
Get the total length of this source in sample frames

Specified by:
getLength in interface CutListSource
Returns:
The length of this source in sample frames
See Also:
CutListSource.getLength()

getWaveForm

public WaveForm getWaveForm(int start,
                            int length,
                            int width)
Description copied from interface: CutListSource
Get a WaveForm from this source

Specified by:
getWaveForm in interface CutListSource
Parameters:
start - The start position of the WaveForm in sample frames
length - The length of the audio data represented by the WaveForm in sample frames
width - The width in which the WaveForm should be displayed
Returns:
A WaveForm starting at position start of this source representing length sample frames with the width of width.
See Also:
CutListSource.getWaveForm(int, int, int)

isReady

public boolean isReady()
Description copied from interface: CutListSource
Ask this source, if it is ready for providing audio data

Specified by:
isReady in interface CutListSource
Returns:
true, if this source can provide data, false otherwise
See Also:
CutListSource.isReady()

replaceFile

public void replaceFile(java.io.File from,
                        java.io.File to)
Description copied from interface: CutListSource
Replace all references to the given source file inside this CutListSource with references to the given target file. This may be because the source file is about to change and to avoid inconsistencies. If the given source file is not used by this CutListSource, the call can be ignored.

Specified by:
replaceFile in interface CutListSource
Parameters:
from - The source file to replace
to - The target file to replace with
See Also:
CutListSource.replaceFile(java.io.File, java.io.File)

usesFile

public boolean usesFile(java.io.File f)
Description copied from interface: CutListSource
Ask this CutListSource whether it relies on the contents of the given file. This is needed, if a file should be overwritten and it must be checked that this doesn´t cause any inconsistencies

Specified by:
usesFile in interface CutListSource
Parameters:
f - The file to ask for
Returns:
true, if a change to the given file´s content would also mean a change to this source, false otherwise
See Also:
CutListSource.usesFile(java.io.File)