danger.audio
Class Stream

java.lang.Object
  extended by danger.audio.Stream
All Implemented Interfaces:
Playable, PlayableAudio, PlayableMedia


public abstract class Stream
extends Object

Stream a PCM audio file for playback OS 2.3


Field Summary
static int MAX_SAMPLE_RATE
          max sample rate = 48 kHz
static int MIN_SAMPLE_RATE
          min sample rate = 1 kHz
static int SAMPLE_RATE_11K
           
static int SAMPLE_RATE_22K
           
static int SAMPLE_RATE_44K
           
static int SAMPLE_RATE_8K
          common sample rates
 
Fields inherited from interface danger.media.PlayableMedia
DEFAULT_PRIORITY, PRIORITY_1, PRIORITY_2, PRIORITY_3, PRIORITY_4, PRIORITY_5
 
Constructor Summary
Stream()
           
 
Method Summary
 void destroy()
          free internal resources for this object
abstract  void fadeFromToInTime(int sourceVolume, int destVolume, int timeInMiliseconds)
          fade from source volume, to dest volume in time miliseconds.
 int framesToMicroseconds(int frames)
          Given sample frames, return microseconds.
 int getCurrentLoopNumber()
          Gets the number of times the looped media has looped back to the loop start.
abstract  int getLoopCount()
          Gets the loop count; which is the total number of times an object is played.
abstract  int getLoops()
          Deprecated. - use getLoopCount() instead.
 int getMarkerCount()
          Gets the number of markers contained by the currently loaded media.
 int getMarkerID(int index)
          Return the integer ID associated with the marker at the given index.
 String getMarkerName(int index)
          Return the name associated with the marker at the given index.
 int getMarkerPosition(int index)
          Return the position in milliseconds of the marker at the given index.
 int getMediaType()
          Returns file type of media.
 int getMicrosecondLength()
          Deprecated. - use getMillisecondLength() instead.
 int getMicrosecondPosition()
          Deprecated. - use getMillisecondPosition() instead.
abstract  int getMillisecondLength()
          get the length of the stream in milliseconds
abstract  int getMillisecondPosition()
          get the current playback position of the stream in milliseconds
abstract  int getPlaybackLength()
          get playback length in sample frames
abstract  int getPlaybackPosition()
          Get the position in sample frames
 int getPlaybackRate()
          Get the playback rate of the media. 100 is default rate.
abstract  int getPriority()
          Get stream priority level.
abstract  int getRate()
           
 int getStereoPosition()
          Returns current stereo position.
 int getTranspose()
          Return tuning in semitones.
 int getTuning()
          Return tuning in cents (1200 is down an octave, -1200 is up an octave) This interacts with PlayableAudio.setTranspose(int) and PlayableAudio.getTranspose()
 int getUniqueID()
          return runtime ID.
abstract  int getVolume()
          Returns current volume in percent.
 int getVolumeClass()
          Get the current volume class.
abstract  boolean isDone()
          Returns true if done playing
abstract  boolean isLoaded()
          is stream loaded
 boolean isLoopingEnabled()
          Return whether looping is enabled (set by a call to PlayableMedia.setLoopingEnabled(boolean)).
 boolean isMuted()
          Return true if the audio is muted
abstract  boolean isPaused()
          pause, resume and test stream object
 boolean isPlaying()
          Returns true if object is playing.
static Stream load(byte[] data)
          Given an array of bytes, try and load a Stream (Can be a WAV, AIF file) Will return null if data is invalid.
static Stream load(byte[] data, boolean autoDelete)
          Given an array of bytes, try and load a Stream (Can be a WAV, AIF file) Will return null if data is invalid.
static Stream load(File f)
          Given a file, try and load a Stream.
static Stream load(File f, boolean autoDelete)
          Given a file, try and load a Stream.
static Stream load(int resourceID)
          Given an resource ID, try and load a Stream (Can be a WAV, AIF file) Will return null if data is invalid.
static Stream load(int resourceID, boolean autoDelete)
          Given an resource ID, try and load a Stream (Can be a WAV, AIF file) Will return null if data is invalid.
abstract  boolean loadFromFile(byte[] data)
          pass in data formatted as a AIF, WAV, or au file.
abstract  boolean loadFromFileName(String fileName)
          pass in filename as a string.
 boolean loadFromResource(int id)
          pass and ID, and read data from the application resource file.
 boolean loadFromResource(int id, Application app)
           
 int microsecondsToFrames(int uSec)
          Given microseconds, return sample frames.
abstract  void pause()
          Will pause object
 void play()
          Given a stream, start it playing, and auto delete it when done playing.
static Stream play(byte[] data)
          Given an array of bytes load a stream file, start it playing, and auto delete it when done playing.
static Stream play(File f)
          Given a file, try and load a Stream, start it playing, and auto delete it when done playing.
static Stream play(File f, boolean autoDelete)
          Given a file, try and load a Stream, start it playing, and auto delete it when done playing if requested.
static Stream play(int resourceID)
          method to load a stream file from a resource, start it playing, and auto delete it when done playing.
static Stream play(int resourceID, int filter)
          method to load a stream file from a resource, start it playing, and auto delete it when done playing.
abstract  void resume()
          Will resume object if paused.
abstract  void setBuzzFlash(boolean buzzOn, boolean flashOn)
          Set auto generate buzz/flash on or off
abstract  void setBuzzFlashEnable(boolean buzzOn, boolean flashOn)
          Set buzz/flash enable or off.
 void setDoneCallbackEvent(Event done)
          Set the event that is called when this media is finished.
 void setDoneCallbackEvent(Event done, boolean doEventOnce)
          Set the event that is called when this media is finished.
abstract  void setLoopCount(int loopCount)
          Sets the loop count; which is the total number of times an object is played.
 void setLoopingEnabled(boolean on)
          Enable looping.
abstract  void setLoops(int loops)
          Deprecated. - use setLoopCount(int) instead.
 void setMicrosecondPosition(int uSec)
          Deprecated. - use setMillisecondPosition(int) instead.
abstract  void setMillisecondPosition(int mSec)
          set the current playback position of the stream in milliseconds
 void setMute(boolean mute)
          Mute or unmute the audio.
abstract  void setPlaybackPosition(int sampleFrame)
          Set the position in sample frames
 void setPlaybackRate(int newRate)
          Set the playback rate of the media.
 void setPositionCallbackEvent(Event event, int position)
          Set an event that is called when this media reaches the given position during playback.
 void setPositionToMarker(int markerID)
          Set the media playback position to the position associated with the marker with the given markerID
abstract  void setPriority(int priority)
          Set stream priority level.
abstract  void setRate(int newRate)
          get/set the sample rate of an object
abstract  void setRouteBus(int routeBus)
           
 void setStereoPosition(int position)
          Set the stereo position of sound.
 void setStoppedCallbackEvent(Event stopped)
          Set the event that is called when this media is stopped by stop().
 void setStoppedCallbackEvent(Event stopped, boolean doEventOnce)
          Set the event that is called when this media is stopped by stop().
 void setTranspose(int semitones)
          Set tuning in semitones.
 void setTuning(int cents)
          Set tuning in cents (1200 is down an octave, -1200 is up an octave) This interacts with PlayableAudio.setTranspose(int) and PlayableAudio.getTranspose()
abstract  void setVolume(int volume)
          get/set playback volume of object.
 void setVolumeClass(int volumeClass)
          Set the volume class.
 boolean start()
          start stream playing, will return false if failed to start
 boolean start(int sampleFrameStart)
          start stream playing.
 boolean start(int sampleFrameStart, int filter)
          start a stream playing, but filter content types from ToneFilter.
 boolean startAtOffset(int startOffset)
           
 boolean startDefault()
          Start Stream with defaults Returns true if started NOTE: This is the same as start().
 void startPlaying()
          Start media playback with default attributes.
 void startPlaying(int attributes)
          Start media playback with specified attributes.
 boolean startWithFilter(int filter)
          Start Sound with a filter Returns true if started NOTE: This is implemented in Playable OS 2.3
 void stop()
          Will stop the object and reset to begining
 void stopPlaying()
          Stop media playback
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_SAMPLE_RATE

public static final int MIN_SAMPLE_RATE
min sample rate = 1 kHz

See Also:
Constant Field Values

MAX_SAMPLE_RATE

public static final int MAX_SAMPLE_RATE
max sample rate = 48 kHz

See Also:
Constant Field Values

SAMPLE_RATE_8K

public static final int SAMPLE_RATE_8K
common sample rates

See Also:
Constant Field Values

SAMPLE_RATE_11K

public static final int SAMPLE_RATE_11K
See Also:
Constant Field Values

SAMPLE_RATE_22K

public static final int SAMPLE_RATE_22K
See Also:
Constant Field Values

SAMPLE_RATE_44K

public static final int SAMPLE_RATE_44K
See Also:
Constant Field Values
Constructor Detail

Stream

public Stream()
Method Detail

destroy

public void destroy()
free internal resources for this object

Specified by:
destroy in interface Playable
Specified by:
destroy in interface PlayableMedia

load

public static Stream load(byte[] data,
                          boolean autoDelete)
Given an array of bytes, try and load a Stream (Can be a WAV, AIF file) Will return null if data is invalid. This Stream will auto delete once its been played if requested OS 3.0


load

public static Stream load(byte[] data)
Given an array of bytes, try and load a Stream (Can be a WAV, AIF file) Will return null if data is invalid. This Stream will auto delete once its been played.


play

public static Stream play(byte[] data)
Given an array of bytes load a stream file, start it playing, and auto delete it when done playing. This Stream will be played with the filter ToneFilter.BUZZER | ToneFilter.FLASHER, which will create buzz and flash. If you don't want to do that, do a Stream.load() then Stream.start() without the filters.


load

public static Stream load(int resourceID,
                          boolean autoDelete)
Given an resource ID, try and load a Stream (Can be a WAV, AIF file) Will return null if data is invalid. This stream will auto delete once its been played if requested. OS 3.0


load

public static Stream load(int resourceID)
Given an resource ID, try and load a Stream (Can be a WAV, AIF file) Will return null if data is invalid. This stream will auto delete once its been played.


play

public static Stream play(int resourceID)
method to load a stream file from a resource, start it playing, and auto delete it when done playing. This Stream will be played with the filter ToneFilter.BUZZER | ToneFilter.FLASHER, which will create buzz and flash. If you don't want to do that, do a Stream.load() then Stream.start() without the filters.


play

public static Stream play(int resourceID,
                          int filter)
method to load a stream file from a resource, start it playing, and auto delete it when done playing. You can also pass in a different ToneFilter.* for playback. ToneFilter.BUZZER - enables the buzzer ToneFilter.FLASHER - enables the flasher ToneFilter.NONE - disables all but playback


load

public static Stream load(File f,
                          boolean autoDelete)
Given a file, try and load a Stream. Will return null if data is invalid. This Stream will auto delete once its been played if requested. OS 3.0


load

public static Stream load(File f)
Given a file, try and load a Stream. Will return null if data is invalid. This Stream will auto delete once its been played.


play

public static Stream play(File f,
                          boolean autoDelete)
Given a file, try and load a Stream, start it playing, and auto delete it when done playing if requested. This Stream will be played with the filter ToneFilter.BUZZER | ToneFilter.FLASHER, which will create buzz and flash. If you don't want to do that, do a Stream.load() then Stream.start() without the filters. OS 3.0


play

public static Stream play(File f)
Given a file, try and load a Stream, start it playing, and auto delete it when done playing. This Stream will be played with the filter ToneFilter.BUZZER | ToneFilter.FLASHER, which will create buzz and flash. If you don't want to do that, do a Stream.load() then Stream.start() without the filters.


play

public final void play()
Given a stream, start it playing, and auto delete it when done playing. This Stream will be played with the filter ToneFilter.BUZZER | ToneFilter.FLASHER, which will create buzz and flash. If you don't want to do that, do a Stream.load() then Stream.start() without the filters.


loadFromFile

public abstract boolean loadFromFile(byte[] data)
pass in data formatted as a AIF, WAV, or au file. Will return false if failed to parse.


loadFromFileName

public abstract boolean loadFromFileName(String fileName)
pass in filename as a string. Will return false if it fails to either create an AudioFilePlayer or preroll.


loadFromResource

public boolean loadFromResource(int id)
pass and ID, and read data from the application resource file. Parsed data is a WAV, AIF, or au data. Will return false if failed to parse.


loadFromResource

public boolean loadFromResource(int id,
                                Application app)

setRouteBus

public abstract void setRouteBus(int routeBus)

setVolume

public abstract void setVolume(int volume)
get/set playback volume of object. Normal is 100 (100%). You can overdrive.


getVolume

public abstract int getVolume()
Description copied from interface: Playable
Returns current volume in percent. The value 100 is 100% of normal.


setPriority

public abstract void setPriority(int priority)
Set stream priority level. Higher values will allow for better voice stealing.

Parameters:
priority - - priority level for media

getPriority

public abstract int getPriority()
Get stream priority level. Higher values will allow for better voice stealing.

Returns:
current priority level

getPlaybackLength

public abstract int getPlaybackLength()
get playback length in sample frames


getPlaybackPosition

public abstract int getPlaybackPosition()
Get the position in sample frames


setPlaybackPosition

public abstract void setPlaybackPosition(int sampleFrame)
Set the position in sample frames


getMicrosecondLength

public int getMicrosecondLength()
Deprecated. - use getMillisecondLength() instead.

Description copied from interface: Playable
get ticks in microseconds of length of object


setMicrosecondPosition

public void setMicrosecondPosition(int uSec)
Deprecated. - use setMillisecondPosition(int) instead.

Description copied from interface: Playable
set the current playback position of object in microseconds. Must call after starting object.


getMicrosecondPosition

public int getMicrosecondPosition()
Deprecated. - use getMillisecondPosition() instead.

Description copied from interface: Playable
get the current playback position of a object in microseconds


getMillisecondLength

public abstract int getMillisecondLength()
get the length of the stream in milliseconds


setMillisecondPosition

public abstract void setMillisecondPosition(int mSec)
set the current playback position of the stream in milliseconds

Parameters:
mSec - - position in media to seek to

getMillisecondPosition

public abstract int getMillisecondPosition()
get the current playback position of the stream in milliseconds


microsecondsToFrames

public int microsecondsToFrames(int uSec)
Given microseconds, return sample frames. This figures this using this Stream's sample rate


framesToMicroseconds

public int framesToMicroseconds(int frames)
Given sample frames, return microseconds. This figures this using this Stream's sample rate


isDone

public abstract boolean isDone()
Returns true if done playing


setLoops

public abstract void setLoops(int loops)
Deprecated. - use setLoopCount(int) instead.


getLoops

public abstract int getLoops()
Deprecated. - use getLoopCount() instead.


setLoopCount

public abstract void setLoopCount(int loopCount)
Sets the loop count; which is the total number of times an object is played.

Parameters:
loopCount - - total number of times to play; 0 means loop forever.

getLoopCount

public abstract int getLoopCount()
Gets the loop count; which is the total number of times an object is played.

Returns:
loopCount - total number of times to play; 0 means loop forever. OS 3.0

setRate

public abstract void setRate(int newRate)
get/set the sample rate of an object


getRate

public abstract int getRate()

startDefault

public boolean startDefault()
Start Stream with defaults Returns true if started NOTE: This is the same as start(). This is implmented to support Playable OS 2.3


startWithFilter

public boolean startWithFilter(int filter)
Start Sound with a filter Returns true if started NOTE: This is implemented in Playable OS 2.3


start

public boolean start()
start stream playing, will return false if failed to start


start

public boolean start(int sampleFrameStart)
start stream playing. Pass in a sample frame offset to start from other than the begining


start

public boolean start(int sampleFrameStart,
                     int filter)
start a stream playing, but filter content types from ToneFilter.


setBuzzFlashEnable

public abstract void setBuzzFlashEnable(boolean buzzOn,
                                        boolean flashOn)
Set buzz/flash enable or off. Will only buzz/flash if this is true


setBuzzFlash

public abstract void setBuzzFlash(boolean buzzOn,
                                  boolean flashOn)
Set auto generate buzz/flash on or off


fadeFromToInTime

public abstract void fadeFromToInTime(int sourceVolume,
                                      int destVolume,
                                      int timeInMiliseconds)
fade from source volume, to dest volume in time miliseconds. Always async


isLoaded

public abstract boolean isLoaded()
is stream loaded


isPaused

public abstract boolean isPaused()
pause, resume and test stream object


pause

public abstract void pause()
Description copied from interface: Playable
Will pause object


resume

public abstract void resume()
Description copied from interface: Playable
Will resume object if paused. Does nothing if already resumed


getUniqueID

public int getUniqueID()
Description copied from interface: Playable
return runtime ID. Unique every time object is started

Specified by:
getUniqueID in interface Playable
Specified by:
getUniqueID in interface PlayableMedia

getMediaType

public int getMediaType()
Description copied from interface: PlayableMedia
Returns file type of media.

Specified by:
getMediaType in interface PlayableMedia

setVolumeClass

public void setVolumeClass(int volumeClass)
Description copied from interface: PlayableAudio
Set the volume class. This determines how the media responds to changes in the system sound profile.

Specified by:
setVolumeClass in interface PlayableAudio

getVolumeClass

public int getVolumeClass()
Description copied from interface: PlayableAudio
Get the current volume class. This determines how the media responds to changes in the system sound profile.

Specified by:
getVolumeClass in interface PlayableAudio

setLoopingEnabled

public void setLoopingEnabled(boolean on)
Description copied from interface: PlayableMedia
Enable looping. This will use the loop counter mLoopCount, which is either set via a call to PlayableMedia.setLoopCount(int) or is 0 (loop forever) by default.

Specified by:
setLoopingEnabled in interface PlayableMedia
Parameters:
on - - enable or disable looping.

isLoopingEnabled

public boolean isLoopingEnabled()
Description copied from interface: PlayableMedia
Return whether looping is enabled (set by a call to PlayableMedia.setLoopingEnabled(boolean)).

Specified by:
isLoopingEnabled in interface PlayableMedia
Returns:
enabled - true or false.

getCurrentLoopNumber

public int getCurrentLoopNumber()
Description copied from interface: PlayableMedia
Gets the number of times the looped media has looped back to the loop start.

Specified by:
getCurrentLoopNumber in interface PlayableMedia

getMarkerCount

public int getMarkerCount()
Description copied from interface: PlayableMedia
Gets the number of markers contained by the currently loaded media. These can be video, MIDI, or audio markers.

Specified by:
getMarkerCount in interface PlayableMedia

getMarkerID

public int getMarkerID(int index)
Description copied from interface: PlayableMedia
Return the integer ID associated with the marker at the given index.

Specified by:
getMarkerID in interface PlayableMedia

getMarkerName

public String getMarkerName(int index)
Description copied from interface: PlayableMedia
Return the name associated with the marker at the given index. May return null.

Specified by:
getMarkerName in interface PlayableMedia

getMarkerPosition

public int getMarkerPosition(int index)
Description copied from interface: PlayableMedia
Return the position in milliseconds of the marker at the given index.

Specified by:
getMarkerPosition in interface PlayableMedia

setPositionToMarker

public void setPositionToMarker(int markerID)
Description copied from interface: PlayableMedia
Set the media playback position to the position associated with the marker with the given markerID

Specified by:
setPositionToMarker in interface PlayableMedia
Parameters:
markerID - - integer ID of the marker (retrieved via PlayableMedia.getMarkerID(int))

setStereoPosition

public void setStereoPosition(int position)
Description copied from interface: PlayableAudio
Set the stereo position of sound. The range is -100 (full left) to 100 (full right). Default is 0 (center)

Specified by:
setStereoPosition in interface PlayableAudio

getStereoPosition

public int getStereoPosition()
Description copied from interface: PlayableAudio
Returns current stereo position. The range is -100 (full left) to 100 (full right). Default is 0 (center)

Specified by:
getStereoPosition in interface PlayableAudio

setMute

public void setMute(boolean mute)
Description copied from interface: PlayableAudio
Mute or unmute the audio. This is independent of the volume.

Specified by:
setMute in interface PlayableAudio

isMuted

public boolean isMuted()
Description copied from interface: PlayableAudio
Return true if the audio is muted

Specified by:
isMuted in interface PlayableAudio

startPlaying

public void startPlaying()
Description copied from interface: PlayableMedia
Start media playback with default attributes.

Specified by:
startPlaying in interface PlayableMedia

startPlaying

public void startPlaying(int attributes)
Description copied from interface: PlayableMedia
Start media playback with specified attributes.

Specified by:
startPlaying in interface PlayableMedia
Parameters:
attributes - - class-specific attributes applied to this playback

isPlaying

public boolean isPlaying()
Description copied from interface: PlayableMedia
Returns true if object is playing.

Specified by:
isPlaying in interface PlayableMedia

stopPlaying

public void stopPlaying()
Description copied from interface: PlayableMedia
Stop media playback

Specified by:
stopPlaying in interface PlayableMedia

setPlaybackRate

public void setPlaybackRate(int newRate)
Description copied from interface: PlayableMedia
Set the playback rate of the media.

Specified by:
setPlaybackRate in interface PlayableMedia
Parameters:
newRate - - new playback rate; 100 is default rate.

getPlaybackRate

public int getPlaybackRate()
Description copied from interface: PlayableMedia
Get the playback rate of the media. 100 is default rate.

Specified by:
getPlaybackRate in interface PlayableMedia

setTranspose

public void setTranspose(int semitones)
Description copied from interface: PlayableAudio
Set tuning in semitones. This interacts with PlayableAudio.setTuning(int) and PlayableAudio.getTuning()

Specified by:
setTranspose in interface PlayableAudio

getTranspose

public int getTranspose()
Description copied from interface: PlayableAudio
Return tuning in semitones. If PlayableAudio.setTuning(int) has been called, This will truncate actual value to nearest 100 cents

Specified by:
getTranspose in interface PlayableAudio

setTuning

public void setTuning(int cents)
Description copied from interface: PlayableAudio
Set tuning in cents (1200 is down an octave, -1200 is up an octave) This interacts with PlayableAudio.setTranspose(int) and PlayableAudio.getTranspose()

Specified by:
setTuning in interface PlayableAudio

getTuning

public int getTuning()
Description copied from interface: PlayableAudio
Return tuning in cents (1200 is down an octave, -1200 is up an octave) This interacts with PlayableAudio.setTranspose(int) and PlayableAudio.getTranspose()

Specified by:
getTuning in interface PlayableAudio

setPositionCallbackEvent

public void setPositionCallbackEvent(Event event,
                                     int position)
Description copied from interface: PlayableMedia
Set an event that is called when this media reaches the given position during playback. Any number of these may be set. Set event to null to disable a given position's callback.

Specified by:
setPositionCallbackEvent in interface PlayableMedia
Parameters:
event - - event to be posted
position - - time in milliseconds at which the event should be posted

setDoneCallbackEvent

public void setDoneCallbackEvent(Event done)
Description copied from interface: PlayableMedia
Set the event that is called when this media is finished.

Specified by:
setDoneCallbackEvent in interface PlayableMedia
Parameters:
done - - event to be posted

setDoneCallbackEvent

public void setDoneCallbackEvent(Event done,
                                 boolean doEventOnce)
Description copied from interface: PlayableMedia
Set the event that is called when this media is finished.

Specified by:
setDoneCallbackEvent in interface PlayableMedia
Parameters:
done - - event to be posted
doEventOnce - - if true, callback only called once for a given playback

setStoppedCallbackEvent

public void setStoppedCallbackEvent(Event stopped)
Description copied from interface: PlayableMedia
Set the event that is called when this media is stopped by stop().

Specified by:
setStoppedCallbackEvent in interface PlayableMedia
Parameters:
stopped - - event to be posted

setStoppedCallbackEvent

public void setStoppedCallbackEvent(Event stopped,
                                    boolean doEventOnce)
Description copied from interface: PlayableMedia
Set the event that is called when this media is stopped by stop().

Specified by:
setStoppedCallbackEvent in interface PlayableMedia
Parameters:
stopped - - event to be posted
doEventOnce - - if true, callback only called once for a given playback

startAtOffset

public boolean startAtOffset(int startOffset)

stop

public void stop()
Description copied from interface: Playable
Will stop the object and reset to begining

Specified by:
stop in interface Playable