Class JavaSoundAudioSource

  • All Implemented Interfaces:
    java.lang.Comparable<NamedBean>, Audio, PropertyChangeProvider, AudioSource, NamedBean

    public class JavaSoundAudioSource
    extends AbstractAudioSource
    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 Detail

      • JavaSoundAudioSource

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

        public JavaSoundAudioSource​(java.lang.String systemName,
                                    java.lang.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 Detail

      • 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
      • 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.

      • calculatePitch

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