Class AbstractAudioBuffer

  • All Implemented Interfaces:
    java.lang.Comparable<NamedBean>, Audio, PropertyChangeProvider, AudioBuffer, NamedBean
    Direct Known Subclasses:
    JavaSoundAudioBuffer, JoalAudioBuffer, NullAudioBuffer

    public abstract class AbstractAudioBuffer
    extends AbstractAudio
    implements AudioBuffer
    Base implementation of the AudioBuffer class.

    Specific implementations will extend this base class.


    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

      • AbstractAudioBuffer

        public AbstractAudioBuffer​(java.lang.String systemName)
        Abstract constructor for new AudioBuffer with system name
        Parameters:
        systemName - AudioBuffer object system name (e.g. IAB4)
      • AbstractAudioBuffer

        public AbstractAudioBuffer​(java.lang.String systemName,
                                   java.lang.String userName)
        Abstract constructor for new AudioBuffer with system name and user name
        Parameters:
        systemName - AudioBuffer object system name (e.g. IAB4)
        userName - AudioBuffer object user name
    • Method Detail

      • getSubType

        public char getSubType()
        Description copied from interface: Audio
        An Audio object can represent one of a number of subtypes of object.

        This method enables us to determine which of those subtypes this particular instance is and be able to process accordingly.

        Current supported subtypes are:

        • B = Buffer
        • L = Listener
        • S = Source
        Specified by:
        getSubType in interface Audio
        Returns:
        subType char
      • getURL

        public java.lang.String getURL()
        Description copied from interface: AudioBuffer
        Return the url of the sound sample

        Applies only to sub-types:

        • Buffer
        Specified by:
        getURL in interface AudioBuffer
        Returns:
        url
      • setURL

        public void setURL​(java.lang.String url)
        Description copied from interface: AudioBuffer
        Sets the url of the sound sample

        Applies only to sub-types:

        • Buffer
        Specified by:
        setURL in interface AudioBuffer
        Parameters:
        url - URL for location containing sound sample data
      • setInputStream

        public void setInputStream​(java.io.InputStream stream)
        Description copied from interface: AudioBuffer
        Sets the input stream of the sound sample

        Applies only to sub-types:

        • Buffer
        Specified by:
        setInputStream in interface AudioBuffer
        Parameters:
        stream - InputStream containing sound sample data
      • getFrameSize

        public int getFrameSize()
        Description copied from interface: AudioBuffer
        Retrieves the length of a sound sample frame stored in this buffer

        Applies only to sub-types:

        • Buffer
        Specified by:
        getFrameSize in interface AudioBuffer
        Returns:
        length of sound sample frame in bytes
      • loadBuffer

        protected abstract boolean loadBuffer()
        Method used to load the actual sound data into the buffer
        Returns:
        True if successful; False if not
      • loadBuffer

        protected abstract boolean loadBuffer​(java.io.InputStream s)
        Method used to load the actual sound data from an InputStream into the buffer
        Parameters:
        s - InputStream containing sound data
        Returns:
        True if successful; False if not
      • setStartLoopPoint

        public void setStartLoopPoint​(long startLoopPoint)
        Description copied from interface: AudioBuffer
        Sets the start loop point of the sound sample stored in this buffer

        Applies only to sub-types:

        • Buffer
        Specified by:
        setStartLoopPoint in interface AudioBuffer
        Parameters:
        startLoopPoint - position of start loop point in samples
      • setStartLoopPoint

        protected void setStartLoopPoint​(long startLoopPoint,
                                         boolean generateLoopBuffers)
        Internal method used to set the start loop point of this buffer with optional generation of loop buffers
        Parameters:
        startLoopPoint - position of start loop point in samples
        generateLoopBuffers - True if loop buffers to be generated
      • getStartLoopPoint

        public long getStartLoopPoint()
        Description copied from interface: AudioBuffer
        Retrieves the start loop point of the sound sample stored in this buffer

        Applies only to sub-types:

        • Buffer
        Specified by:
        getStartLoopPoint in interface AudioBuffer
        Returns:
        position of start loop point in samples
      • setEndLoopPoint

        public void setEndLoopPoint​(long endLoopPoint)
        Description copied from interface: AudioBuffer
        Sets the end loop point of the sound sample stored in this buffer

        Applies only to sub-types:

        • Buffer
        Specified by:
        setEndLoopPoint in interface AudioBuffer
        Parameters:
        endLoopPoint - position of end loop point in samples
      • setEndLoopPoint

        protected void setEndLoopPoint​(long endLoopPoint,
                                       boolean generateLoopBuffers)
        Internal method used to set the end loop point of this buffer with optional generation of loop buffers
        Parameters:
        endLoopPoint - position of end loop point in samples
        generateLoopBuffers - True if loop buffers to be generated
      • getEndLoopPoint

        public long getEndLoopPoint()
        Description copied from interface: AudioBuffer
        Retrieves the end loop point of the sound sample stored in this buffer

        Applies only to sub-types:

        • Buffer
        Specified by:
        getEndLoopPoint in interface AudioBuffer
        Returns:
        position of end loop point in samples
      • isStreamed

        public boolean isStreamed()
        Description copied from interface: AudioBuffer
        Retrieves the current streaming setting of this buffer

        Applies only to sub-types:

        • Buffer
        Specified by:
        isStreamed in interface AudioBuffer
        Returns:
        current streaming setting
      • setStreamedForced

        protected void setStreamedForced​(boolean streamedForced)
        Protected method used internally to modify the forced streaming flag
        Parameters:
        streamedForced - True if required; False if not
      • isStreamedForced

        public boolean isStreamedForced()
        Description copied from interface: AudioBuffer
        Determines if this buffer can be loaded in full or if it must be streamed from the file. Forced streaming is usually restricted to larger sound samples that are otherwise too large to fit directly into memory.

        Applies only to sub-types:

        • Buffer
        Specified by:
        isStreamedForced in interface AudioBuffer
        Returns:
        True if buffer must be streamed; False it can be loaded in full
      • generateStreamingBuffers

        protected abstract boolean generateStreamingBuffers()
        Internal method used to generate buffers for streaming
        Returns:
        True if successful; False if not
      • removeStreamingBuffers

        protected abstract void removeStreamingBuffers()
        Internal method used to remove streaming buffers
      • 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
        Parameters:
        oldState - the former state