ddf.minim
Class AudioFileIn

java.lang.Object
  extended byddf.minim.Controller
      extended byddf.minim.AudioObject
          extended byddf.minim.AudioFileIn
All Implemented Interfaces:
AWListener

public class AudioFileIn
extends AudioObject
implements AWListener

AudioFileIn is used for playing audio files, whether they are on the local file system or streaming from the web. The interface is identical to an AudioClip, the only difference being that samples are available. This means that you can do things like draw the waveform, attach AudioEffects, and use different audio analysis classes with it. You get an AudioFileIn by asking Minim for one.

Author:
Damien Di Fede

Field Summary
protected  javax.sound.sampled.AudioInputStream ais
           
protected  long bytesRead
           
protected  int lengthInMillis
           
protected  boolean loop
           
protected  int numLoops
           
protected  boolean play
           
 
Fields inherited from class ddf.minim.AudioObject
doEffects, effects, left, mix, right
 
Fields inherited from class ddf.minim.Controller
BALANCE, GAIN, line, MUTE, PAN, VOLUME
 
Constructor Summary
AudioFileIn(javax.sound.sampled.AudioInputStream ais, javax.sound.sampled.SourceDataLine line, int bufferSize)
          Constructs an AudioFileIn object.
 
Method Summary
 void cue(int millis)
          Sets the position of the file to millis milliseconds from the beginning.
 boolean isPlaying()
          Returns true if the AudioFileIn is currently playing.
 int length()
          Returns the length of the file in milliseconds.
 void loop()
          Sets the clip to loop continuously.
 void loop(int n)
          Sets the clip to loop n times.
 void pause()
          Pauses playback.
 void play()
          Starts playback from the current position.
 void play(int millis)
          Starts playback millis from the beginning.
 int position()
          Returns the current position of the "playhead" in the clip (ie how much of the clip has already been played)
 void rewind()
          Rewinds the clip to the beginning.
 void writeSamples(org.tritonus.share.sampled.FloatSampleBuffer fsb)
          Fills fsb with samples from the file.
 
Methods inherited from class ddf.minim.AudioObject
addEffect, applyEffects, applyEffects, clearEffects, effects, getEffect, getFormat, isEffected, noEffects, removeEffect, removeEffect, type
 
Methods inherited from class ddf.minim.Controller
getBalance, getGain, getPan, getVolume, isMuted, mute, printControls, setBalance, setGain, setPan, setVolume, shiftBalance, shiftGain, shiftPan, shiftVolume, unmute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bytesRead

protected long bytesRead

lengthInMillis

protected int lengthInMillis

play

protected boolean play

loop

protected boolean loop

numLoops

protected int numLoops

ais

protected javax.sound.sampled.AudioInputStream ais
Constructor Detail

AudioFileIn

public AudioFileIn(javax.sound.sampled.AudioInputStream ais,
                   javax.sound.sampled.SourceDataLine line,
                   int bufferSize)
Constructs an AudioFileIn object.

Parameters:
ais - the AudioInputStream that contains the audio samples
line - the SourceDataLine that will be used to play the samples
bufferSize - the size of the float buffers
Method Detail

play

public void play()
Starts playback from the current position.


play

public void play(int millis)
Starts playback millis from the beginning.

Parameters:
millis -

isPlaying

public boolean isPlaying()
Returns true if the AudioFileIn is currently playing.

Returns:
a boolean indicating whether this file is currently playing

pause

public void pause()
Pauses playback.


rewind

public void rewind()
Rewinds the clip to the beginning. This does not stop playback.


loop

public void loop()
Sets the clip to loop continuously. If it is already playing, this will not reset the position to the beginning. If it is not playing, this will cause the clip to start playing.


loop

public void loop(int n)
Sets the clip to loop n times. If it is already playing, this will not reset the position to the beginning. If it is not playing, this will cause the clip to start playing.

Parameters:
n - the number of times to loop

length

public int length()
Returns the length of the file in milliseconds.

Returns:
the length of the file in milliseconds

position

public int position()
Returns the current position of the "playhead" in the clip (ie how much of the clip has already been played)

Returns:
the current position of the "playhead" in the file

cue

public void cue(int millis)
Sets the position of the file to millis milliseconds from the beginning. This will not change the playstate of the file. If an error occurs while trying to cue the file, it will be reported and the file will be rewound.

Parameters:
millis -

writeSamples

public void writeSamples(org.tritonus.share.sampled.FloatSampleBuffer fsb)
Fills fsb with samples from the file. If an error occurs while reading from the file, it will be reported and fsb will be filled with silence.

Specified by:
writeSamples in interface AWListener
Parameters:
fsb - the FloatSampleBuffer to be filled