javax.media.j3d
Class SoundScheduler

java.lang.Object
  extended by javax.media.j3d.J3dStructure
      extended by javax.media.j3d.SoundScheduler

 class SoundScheduler
extends J3dStructure

This structure parallels the RenderBin structure and is used for sounds


Field Summary
(package private)  AuralAttributesRetained aaImmed
          Current active (selected) attribute node in the sceneGraph
(package private)  AuralAttributesRetained aaRetained
          Current active (selected) attribute node in the sceneGraph
(package private)  AudioDevice audioDevice
          Audio Device
(package private)  AudioDevice3D audioDevice3D
           
(package private)  AudioDevice3DL2 audioDevice3DL2
           
private  boolean auralAttribsChanged
          Temporary flag that's denotes that some field auralAttribute was changed
(package private) static boolean debugFlag
           
(package private) static int EAR_POSITIONS_CHANGED
           
(package private) static int EYE_POSITIONS_CHANGED
           
(package private)  GraphicsContext3D graphicsCtx
          The GraphicContext3D that we are currently unning in.
(package private) static int HEAD_TO_VWORLD_CHANGED
           
(package private) static int IMAGE_PLATE_TO_VWORLD_CHANGED
           
(package private) static boolean internalErrors
           
(package private)  Bounds[] intersectedRegions
          Array of Bounds nodes for the corresponding intersectedSoundscapes array.
(package private)  SoundscapeRetained[] intersectedSoundscapes
          Array of SoundScapeRetained nodes that intersect the viewPlatform This list is a subset of the soundscapes array, and is used when selecting the closest Soundscape.
(package private)  AuralAttributesRetained lastAA
          Maintain what reference to the last AuralAttributes found active was so that only if there was a change do we need to reset these parameters in the AudioDevice3D.
(package private)  int lastEventReceived
           
(package private) static int LISTENER_CHANGED
           
private  int listenerUpdated
           
(package private)  int nImmedSounds
          Current number of immediate mode sound nodes in the universe
(package private)  int nRetainedSounds
          Current number of scene graph sound nodes in the universe
private  boolean positionalSoundUpdated
          Temporary flag that's denotes that a positional sound was processed in the current loop of renderChange().
(package private)  java.util.ArrayList prioritizedSounds
          An array of prioritized sounds currently playing "live" sounds.
(package private)  boolean ready
          This boolean tells the thread to suspend itself.
(package private)  Bounds region
          Reference to last processed region within run().
(package private)  boolean resetAA
          Since AuralAttribute gain scale factor is multipled with sound's initialGain scale factor, any change in AuralAttrib gain scale factor should force an update of all active sounds' gains Also, change in AuralAttributes should force a sound update even if no other sound field changes occurred.
private  boolean stallThread
           
(package private)  UpdateTargets targets
           
(package private)  int totalChannels
           
(package private)  boolean transformMsg
           
(package private)  View view
          The View that owns this SoundScheduler
(package private)  ViewPlatformRetained viewPlatform
          The ViewPlatform that is associated with this SoundScheduler
 
Fields inherited from class javax.media.j3d.J3dStructure
messageList, msgList, nMessage, threadData, threadType, universe, updateThread
 
Constructor Summary
SoundScheduler(VirtualUniverse u, View v)
          Constructs a new SoundScheduler
 
Method Summary
(package private)  void activate()
           
(package private)  void addPrioritizedSound(SoundRetained mirSound)
           
(package private)  void addSound(SoundRetained sound)
          Add sound to sounds list.
(package private)  void attachSoundData(SoundSchedulerAtom soundAtom, MediaContainer soundData, boolean forceReload)
          Attempts to load sound data for a particular sound source onto the chosen/initialized audio device If this called, it is assumed that SoundRetained.audioDevice is NOT null.
(package private)  int calcSchedulingAction()
          Determine scheduling action for each live sound
(package private)  void changeNodeAttrib(J3dMessage m)
           
(package private)  void changeNodeState(J3dMessage m)
           
(package private)  boolean checkAudioDevice3D()
          Check (and set if necessary) AudioDevice3D field
(package private)  boolean checkState()
           
(package private)  void cleanup()
          Release resource associate with this structure before GC We need to clear all those IndexedUnorderSet/WakeupIndexedList so that the listIdx associate with IndexedObject reset to -1.
(package private)  void clearListenerFlag()
           
(package private)  void clearSoundData(SoundSchedulerAtom soundAtom)
          Clears the fields associated with sample data for this sound.
(package private)  void deactivate()
           
(package private)  void deactivateAllSounds()
          Deactive all playing sounds If the sound is continuous thendSilence it but leave it playing otherwise stop sound
(package private)  void debugPrint(java.lang.String message)
           
(package private)  void deleteSound(SoundRetained sound)
           
(package private)  void enableSound(SoundRetained sound)
           
(package private)  int findActiveSoundscapes()
          Process active Soundscapes (if there are any) and intersect these soundscapes with the viewPlatform.
(package private)  AuralAttributesRetained findClosestAAttribs(int nSelectedSScapes)
           
(package private)  SoundSchedulerAtom findSoundAtom(SoundRetained node, int nthInstance)
           
(package private)  void insertNodes(J3dMessage m)
           
(package private)  void loadSound(SoundRetained sound, boolean forceReload)
           
(package private)  void muteSilentSound(SoundSchedulerAtom soundAtom)
           
(package private)  void muteSilentSounds()
          Mute sounds that are to be played silently.
(package private)  void muteSound(SoundRetained sound)
           
(package private)  void pause(SoundSchedulerAtom soundAtom)
          pause the sample associated with this sound
(package private)  void pauseAllSounds()
          Pause all activity playing sounds
(package private)  void pauseSound(SoundRetained sound)
           
(package private)  int performActions()
          Perform the scheduling action for each prioritized sound.
(package private)  void printAtomState(SoundSchedulerAtom atom)
           
(package private)  int prioritizeSounds()
          Prioritize all sounds associated with SoundScheduler (view) This only need be done once when scheduler is initialized since the priority list is updated when: a) PRIORITY_DIRTY_BIT in soundDirty field set; or b) sound added or removed from live array list
(package private)  void processBoundingLeafChanged(J3dMessage m)
           
(package private)  void processImmediateNodes(java.lang.Object[] args, long referenceTime)
           
(package private)  void processMessages(long referenceTime)
          This gets overriden by the structure
(package private)  void processSoundAtom(SoundSchedulerAtom soundAtom)
           
(package private)  void processViewSpecificGroupChanged(J3dMessage m)
           
(package private)  void receiveAWTEvent(java.awt.AWTEvent evt)
           
(package private)  void removeNodes(J3dMessage m)
          Node removed from tree
(package private)  void render(boolean startFlag, SoundSchedulerAtom soundAtom, AuralAttributesRetained attribs)
          render (start or update) the oscillator associated with this sound
(package private)  void renderChanges()
          The main loop for the Sound Scheduler.
(package private)  void reset()
           
(package private)  void resumeAllSounds()
          Resume playing all paused active sounds
(package private)  void setAttribsDirtyFlag(SoundRetained node, int dirtyFlag)
          set dirty flags associated with SoundSchedulerAtom
(package private)  void setListenerFlag(int flag)
          'Dirty' flag == listenerUpdated flag The ambiguous name 'dirtyFlag' is a legacy from when there was only a single dirty flag set by Core yet tested and cleared in this scheduler.
(package private)  void setStateDirtyFlag(SoundRetained node, int dirtyFlag)
           
(package private)  long shortestTimeToFinish()
          Determine amount of time before next playing sound will be is complete.
(package private)  void shuffleSound(SoundRetained sound)
           
(package private)  void start(SoundSchedulerAtom soundAtom)
          Start the sample associated with this sound Do everything necessary to start the sound: set start time the oscillator associated with this sound
(package private)  void stopAllSounds()
          Stop all activity playing sounds
(package private)  void stopAllSounds(boolean setPlayingSoundsPending)
           
(package private)  void stopSound(SoundSchedulerAtom soundAtom, boolean setPending)
          stop playing one specific sound node If setPending flag true, sound is stopped but enable state is set to pending-on so that it is restarted.
(package private)  boolean testListenerFlag()
           
(package private)  void turnOff(SoundSchedulerAtom soundAtom)
          stop the sample associated with this sound
(package private)  void unpause(SoundSchedulerAtom soundAtom)
           
(package private)  void update(SoundSchedulerAtom soundAtom)
          Exlicitly update the sound parameters associated with a sample
(package private)  void updateAuralAttribs(AuralAttributesRetained attribs)
          Send current aural attributes to audio device Note that a AA's dirtyFlag is clear only after parameters are sent to audio device.
(package private)  void updateSoundParams(boolean updateAll, SoundSchedulerAtom soundAtom, AuralAttributesRetained attribs)
           
(package private)  void updateTransformChange(UpdateTargets targets, long referenceTime)
           
(package private)  void updateTransformedFields(SoundRetained mirSound)
           
(package private)  void updateXformedParams(boolean updateAll, SoundSchedulerAtom soundAtom)
          Update VirtualWorld local transform, sound position and direction.
 
Methods inherited from class javax.media.j3d.J3dStructure
addMessage, clearMessages, getMessages, getNumMessage, getUpdateThreadData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

view

View view
The View that owns this SoundScheduler


ready

boolean ready
This boolean tells the thread to suspend itself. This is true ONLY when everythings ready to render using run loop


viewPlatform

ViewPlatformRetained viewPlatform
The ViewPlatform that is associated with this SoundScheduler


graphicsCtx

GraphicsContext3D graphicsCtx
The GraphicContext3D that we are currently unning in.


lastAA

AuralAttributesRetained lastAA
Maintain what reference to the last AuralAttributes found active was so that only if there was a change do we need to reset these parameters in the AudioDevice3D.


resetAA

boolean resetAA
Since AuralAttribute gain scale factor is multipled with sound's initialGain scale factor, any change in AuralAttrib gain scale factor should force an update of all active sounds' gains Also, change in AuralAttributes should force a sound update even if no other sound field changes occurred.


audioDevice

AudioDevice audioDevice
Audio Device


audioDevice3D

AudioDevice3D audioDevice3D

audioDevice3DL2

AudioDevice3DL2 audioDevice3DL2

totalChannels

int totalChannels

intersectedSoundscapes

SoundscapeRetained[] intersectedSoundscapes
Array of SoundScapeRetained nodes that intersect the viewPlatform This list is a subset of the soundscapes array, and is used when selecting the closest Soundscape. Maintained as an expandable array.


intersectedRegions

Bounds[] intersectedRegions
Array of Bounds nodes for the corresponding intersectedSoundscapes array. This array is used when selecting the closest Soundscape. This list is used when selecting the closest Soundscape. Maintained as an expandable array.


region

Bounds region
Reference to last processed region within run(). Maintained to avoid re-transforming this bounds.


prioritizedSounds

java.util.ArrayList prioritizedSounds
An array of prioritized sounds currently playing "live" sounds. This prioritized sound list is NO longer re-create instead sounds are insert, shuffled or removed as messages are processed.


nRetainedSounds

int nRetainedSounds
Current number of scene graph sound nodes in the universe


nImmedSounds

int nImmedSounds
Current number of immediate mode sound nodes in the universe


aaRetained

AuralAttributesRetained aaRetained
Current active (selected) attribute node in the sceneGraph


transformMsg

boolean transformMsg

targets

UpdateTargets targets

aaImmed

AuralAttributesRetained aaImmed
Current active (selected) attribute node in the sceneGraph


EAR_POSITIONS_CHANGED

static final int EAR_POSITIONS_CHANGED
See Also:
Constant Field Values

EYE_POSITIONS_CHANGED

static final int EYE_POSITIONS_CHANGED
See Also:
Constant Field Values

IMAGE_PLATE_TO_VWORLD_CHANGED

static final int IMAGE_PLATE_TO_VWORLD_CHANGED
See Also:
Constant Field Values

HEAD_TO_VWORLD_CHANGED

static final int HEAD_TO_VWORLD_CHANGED
See Also:
Constant Field Values

LISTENER_CHANGED

static final int LISTENER_CHANGED
See Also:
Constant Field Values

listenerUpdated

private int listenerUpdated

positionalSoundUpdated

private boolean positionalSoundUpdated
Temporary flag that's denotes that a positional sound was processed in the current loop of renderChange().


auralAttribsChanged

private boolean auralAttribsChanged
Temporary flag that's denotes that some field auralAttribute was changed


stallThread

private boolean stallThread

lastEventReceived

int lastEventReceived

debugFlag

static final boolean debugFlag
See Also:
Constant Field Values

internalErrors

static final boolean internalErrors
See Also:
Constant Field Values
Constructor Detail

SoundScheduler

SoundScheduler(VirtualUniverse u,
               View v)
Constructs a new SoundScheduler

Method Detail

processMessages

void processMessages(long referenceTime)
Description copied from class: J3dStructure
This gets overriden by the structure

Specified by:
processMessages in class J3dStructure

insertNodes

void insertNodes(J3dMessage m)

addSound

void addSound(SoundRetained sound)
Add sound to sounds list.


removeNodes

void removeNodes(J3dMessage m)
Node removed from tree

Specified by:
removeNodes in class J3dStructure

deleteSound

void deleteSound(SoundRetained sound)

changeNodeAttrib

void changeNodeAttrib(J3dMessage m)

changeNodeState

void changeNodeState(J3dMessage m)

shuffleSound

void shuffleSound(SoundRetained sound)

loadSound

void loadSound(SoundRetained sound,
               boolean forceReload)

enableSound

void enableSound(SoundRetained sound)

muteSound

void muteSound(SoundRetained sound)

pauseSound

void pauseSound(SoundRetained sound)

processImmediateNodes

void processImmediateNodes(java.lang.Object[] args,
                           long referenceTime)

updateTransformChange

void updateTransformChange(UpdateTargets targets,
                           long referenceTime)

updateTransformedFields

void updateTransformedFields(SoundRetained mirSound)

activate

void activate()

deactivate

void deactivate()

checkState

boolean checkState()

reset

void reset()

receiveAWTEvent

void receiveAWTEvent(java.awt.AWTEvent evt)

renderChanges

void renderChanges()
The main loop for the Sound Scheduler.


prioritizeSounds

int prioritizeSounds()
Prioritize all sounds associated with SoundScheduler (view) This only need be done once when scheduler is initialized since the priority list is updated when: a) PRIORITY_DIRTY_BIT in soundDirty field set; or b) sound added or removed from live array list


addPrioritizedSound

void addPrioritizedSound(SoundRetained mirSound)

findActiveSoundscapes

int findActiveSoundscapes()
Process active Soundscapes (if there are any) and intersect these soundscapes with the viewPlatform. Returns the number of soundscapes that intesect with view volume.


findClosestAAttribs

AuralAttributesRetained findClosestAAttribs(int nSelectedSScapes)

updateAuralAttribs

void updateAuralAttribs(AuralAttributesRetained attribs)
Send current aural attributes to audio device Note that a AA's dirtyFlag is clear only after parameters are sent to audio device.


processSoundAtom

void processSoundAtom(SoundSchedulerAtom soundAtom)

calcSchedulingAction

int calcSchedulingAction()
Determine scheduling action for each live sound


muteSilentSounds

void muteSilentSounds()
Mute sounds that are to be played silently. Not all the sound in the prioritized enabled sound list may be able to be played. Due to low priority, some sounds must be muted/silenced (if such an action frees up channel resources) to make way for sounds with higher priority. For each sound in priority list: For sounds whose actions are X_SILENT: Mute sounds to be silenced Add the number of channels used by this muted sound to current total number of channels used For all remaining sounds (with actions other than above) The number of channels that 'would be used' to play potentially audible sounds is compared with the number left on the device: If this sound would use more channels than available Change it's X_AUDIBLE action to X_SILENT Mute sounds to be silenced Add the number of channels used by this sound, muted or not, to current total number of channels used NOTE: requests for sounds to play beyond channel capability of the audio device do NOT throw an exception when more sounds are started than can be played. Rather the unplayable sounds are muted. It is up to the AudioDevice3D implementation to determine how muted/silent sounds are implememted (playing with gain zero and thus using up channel resources, or stop and restarted with correct offset when inactivated then re-actived.


muteSilentSound

void muteSilentSound(SoundSchedulerAtom soundAtom)

shortestTimeToFinish

long shortestTimeToFinish()
Determine amount of time before next playing sound will be is complete. find the atom that has the least amount of time before is finished playing and return this time

Returns:
length of time in millisecond until the next active sound will be complete. Returns -1 if no sounds are playing (or all are complete).

performActions

int performActions()
Perform the scheduling action for each prioritized sound. Now, finally, the scheduling action value reflects what is requested and what is physically posible to perform. So, for each sound in list of prioritized enabled sounds, start/update sounds that are REALLY supposed to be either playing audibly or playing silently.

Returns:
number of active (audible and silent) sounds

render

void render(boolean startFlag,
            SoundSchedulerAtom soundAtom,
            AuralAttributesRetained attribs)
render (start or update) the oscillator associated with this sound


start

void start(SoundSchedulerAtom soundAtom)
Start the sample associated with this sound Do everything necessary to start the sound: set start time the oscillator associated with this sound


update

void update(SoundSchedulerAtom soundAtom)
Exlicitly update the sound parameters associated with a sample


stopSound

void stopSound(SoundSchedulerAtom soundAtom,
               boolean setPending)
stop playing one specific sound node If setPending flag true, sound is stopped but enable state is set to pending-on so that it is restarted.


deactivateAllSounds

void deactivateAllSounds()
Deactive all playing sounds If the sound is continuous thendSilence it but leave it playing otherwise stop sound


pauseAllSounds

void pauseAllSounds()
Pause all activity playing sounds


resumeAllSounds

void resumeAllSounds()
Resume playing all paused active sounds


stopAllSounds

void stopAllSounds()
Stop all activity playing sounds


stopAllSounds

void stopAllSounds(boolean setPlayingSoundsPending)

pause

void pause(SoundSchedulerAtom soundAtom)
pause the sample associated with this sound


unpause

void unpause(SoundSchedulerAtom soundAtom)

turnOff

void turnOff(SoundSchedulerAtom soundAtom)
stop the sample associated with this sound


updateXformedParams

void updateXformedParams(boolean updateAll,
                         SoundSchedulerAtom soundAtom)
Update VirtualWorld local transform, sound position and direction. This is done dynamically from PointSoundRetained as these fields are updated (when soundAtom.status is AUDIBLE or SILENT), or by this. render() method when sound is started (sound.enabled is true). This method should only be called if mirror sound is a Point or ConeSound. Important: pre-transformed position and direction sent to AudioDevice.


updateSoundParams

void updateSoundParams(boolean updateAll,
                       SoundSchedulerAtom soundAtom,
                       AuralAttributesRetained attribs)

checkAudioDevice3D

boolean checkAudioDevice3D()
Check (and set if necessary) AudioDevice3D field


clearSoundData

void clearSoundData(SoundSchedulerAtom soundAtom)
Clears the fields associated with sample data for this sound. Assumes soundAtom is non-null, and that non-null atom would have non-null sound field.


attachSoundData

void attachSoundData(SoundSchedulerAtom soundAtom,
                     MediaContainer soundData,
                     boolean forceReload)
Attempts to load sound data for a particular sound source onto the chosen/initialized audio device If this called, it is assumed that SoundRetained.audioDevice is NOT null. If an error in loading occurs (an exception is caught,...) an error is printed out to stderr - an exception is not thrown.

Parameters:
soundData - descrition of sound source data

findSoundAtom

SoundSchedulerAtom findSoundAtom(SoundRetained node,
                                 int nthInstance)

setListenerFlag

void setListenerFlag(int flag)
'Dirty' flag == listenerUpdated flag The ambiguous name 'dirtyFlag' is a legacy from when there was only a single dirty flag set by Core yet tested and cleared in this scheduler. These methods specifically set/test/clear the local listenerUpdated flag.


clearListenerFlag

void clearListenerFlag()

testListenerFlag

boolean testListenerFlag()

setAttribsDirtyFlag

void setAttribsDirtyFlag(SoundRetained node,
                         int dirtyFlag)
set dirty flags associated with SoundSchedulerAtom


setStateDirtyFlag

void setStateDirtyFlag(SoundRetained node,
                       int dirtyFlag)

printAtomState

void printAtomState(SoundSchedulerAtom atom)

debugPrint

void debugPrint(java.lang.String message)

processViewSpecificGroupChanged

void processViewSpecificGroupChanged(J3dMessage m)

processBoundingLeafChanged

void processBoundingLeafChanged(J3dMessage m)

cleanup

void cleanup()
Description copied from class: J3dStructure
Release resource associate with this structure before GC We need to clear all those IndexedUnorderSet/WakeupIndexedList so that the listIdx associate with IndexedObject reset to -1.

Specified by:
cleanup in class J3dStructure


Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.