Class JavaSoundAudioSource

All Implemented Interfaces:
Comparable<NamedBean>, Audio, PropertyChangeProvider, AudioSource, NamedBean

JavaSound implementation of the Audio Source sub-class.

For now, no system-specific implementations are foreseen - this will remain internal-only

For more information about the JavaSound API, visit http://java.sun.com/products/java-media/sound/


This file is part of JMRI.

JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.

JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

  • Constructor Details

    • JavaSoundAudioSource

      public JavaSoundAudioSource(String systemName)
      Constructor for new JavaSoundAudioSource with system name
      Parameters:
      systemName - AudioSource object system name (e.g. IAS1)
    • JavaSoundAudioSource

      public JavaSoundAudioSource(String systemName, String userName)
      Constructor for new JavaSoundAudioSource with system name and user name
      Parameters:
      systemName - AudioSource object system name (e.g. IAS1)
      userName - AudioSource object user name
  • Method Details

    • bindAudioBuffer

      boolean bindAudioBuffer(AudioBuffer audioBuffer)
      Description copied from class: AbstractAudioSource
      Binds this AudioSource with the specified AudioBuffer.

      Applies only to sub-types:

      • Source
      Specified by:
      bindAudioBuffer in class AbstractAudioSource
      Parameters:
      audioBuffer - The AudioBuffer to bind to this AudioSource
      Returns:
      true if successful
    • changePosition

      protected void changePosition(javax.vecmath.Vector3f pos)
      Description copied from class: AbstractAudioSource
      Change the current position of this source.
      Specified by:
      changePosition in class AbstractAudioSource
      Parameters:
      pos - new position
    • setGain

      public void setGain(float gain)
      Description copied from interface: AudioSource
      Set the gain of this AudioSource object

      Default value = 1.0f

      Applies only to sub-types:

      • Listener
      • Source
      Specified by:
      setGain in interface AudioSource
      Overrides:
      setGain in class AbstractAudioSource
      Parameters:
      gain - the gain of this AudioSource
    • setPitch

      public void setPitch(float pitch)
      Description copied from interface: AudioSource
      Set the pitch of this AudioSource object

      Values are restricted from 0.5f to 2.0f, i.e. half to double

      Default value = 1.0f

      Applies only to sub-types:

      • Source
      Specified by:
      setPitch in interface AudioSource
      Overrides:
      setPitch in class AbstractAudioSource
      Parameters:
      pitch - the pitch of this AudioSource
    • setReferenceDistance

      public void setReferenceDistance(float referenceDistance)
      Description copied from interface: AudioSource
      Set the reference distance of this AudioSource object.

      Default value = 1.0f

      The Reference Distance is one of the main parameters you have for controlling the way that sounds attenuate with distance. A Source with Reference Distance set to 5 (meters) will be at maximum volume while it is within 5 metere of the listener, and start to fade out as it moves further away. At 10 meters it will be at half volume, and at 20 meters at a quarter volume, etc ...

      Applies only to sub-types:

      • Source
      Specified by:
      setReferenceDistance in interface AudioSource
      Overrides:
      setReferenceDistance in class AbstractAudioSource
      Parameters:
      referenceDistance - the Reference Distance for this AudioSource
    • setOffset

      public void setOffset(long offset)
      Description copied from interface: AudioSource
      Set the offset in which to start playback of this AudioSource.

      Default value = 0

      Value is clamped between 0 and length of attached AudioBuffer

      Applies only to sub-types:

      • Source
      Specified by:
      setOffset in interface AudioSource
      Overrides:
      setOffset in class AbstractAudioSource
      Parameters:
      offset - the offset in samples marking the point to commence playback
    • getState

      public int getState()
      Description copied from interface: NamedBean
      Provide generic access to internal state.

      This generally shouldn't be used by Java code; use the class-specific form instead (e.g. getCommandedState in Turnout). This is provided to make scripts easier to read.

      Specified by:
      getState in interface NamedBean
      Overrides:
      getState in class AbstractAudio
      Returns:
      the state
    • stateChanged

      public void stateChanged(int oldState)
      Description copied from interface: Audio
      Method used to update the current state of the Audio object
      Specified by:
      stateChanged in interface Audio
      Overrides:
      stateChanged in class AbstractAudioSource
      Parameters:
      oldState - the former state
    • doPlay

      protected void doPlay()
      Description copied from class: AbstractAudioSource
      Play the clip from the beginning. If looped, start looping.
      Specified by:
      doPlay in class AbstractAudioSource
    • doStop

      protected void doStop()
      Description copied from class: AbstractAudioSource
      Stop playing the clip and rewind to the beginning.
      Specified by:
      doStop in class AbstractAudioSource
    • doPause

      protected void doPause()
      Description copied from class: AbstractAudioSource
      Stop playing the clip but retain the current position.
      Specified by:
      doPause in class AbstractAudioSource
    • doResume

      protected void doResume()
      Description copied from class: AbstractAudioSource
      Play the clip from the current position.
      Specified by:
      doResume in class AbstractAudioSource
    • doRewind

      protected void doRewind()
      Description copied from class: AbstractAudioSource
      Rewind clip to the beginning.
      Specified by:
      doRewind in class AbstractAudioSource
    • doFadeIn

      protected void doFadeIn()
      Description copied from class: AbstractAudioSource
      Fade in then play this AudioSource.
      Specified by:
      doFadeIn in class AbstractAudioSource
    • doFadeOut

      protected void doFadeOut()
      Description copied from class: AbstractAudioSource
      Fade out then stop this AudioSource.
      Specified by:
      doFadeOut in class AbstractAudioSource
    • cleanup

      protected void cleanup()
      Description copied from class: AbstractAudio
      Abstract method that concrete classes will implement to perform necessary cleanup routines.

      This method is now included in dispose(). The caller can call dispose() to cleanup and deregister an audio object.

      Specified by:
      cleanup in class AbstractAudio
    • calculatePan

      protected void calculatePan()
      Calculate the panning of this Source between fully left (-1.0f) and fully right (1.0f)

      Calculated internally from the relative positions of this source and the listener.

    • calculateGain

      protected void calculateGain()
      Description copied from class: AbstractAudioSource
      Calculate the gain of this AudioSource based on distance from listener and fade levels.
      Specified by:
      calculateGain in class AbstractAudioSource
    • calculatePitch

      protected void calculatePitch()
      Internal method used to calculate the pitch.