Class AbstractAudioBuffer
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.implementation.AbstractAudio
-
- jmri.jmrit.audio.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
LOOP_POINT_BOTH
Identifier of both loop pointsprotected static int
LOOP_POINT_END
Identifier of end loop pointprotected static int
LOOP_POINT_START
Identifier of start loop point-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.Audio
AT, BUFFER, CMD_BIND_BUFFER, CMD_FADE_IN, CMD_FADE_OUT, CMD_INIT_FACTORY, CMD_LOAD_SOUND, CMD_PAUSE, CMD_PAUSE_TOGGLE, CMD_PLAY, CMD_PLAY_TOGGLE, CMD_QUEUE_BUFFERS, CMD_RESET_POSITION, CMD_RESUME, CMD_REWIND, CMD_STOP, CMD_UNQUEUE_BUFFERS, DECIMAL_PLACES, FADE_IN, FADE_NONE, FADE_OUT, LISTENER, MAX_DISTANCE, SOURCE, STATE_EMPTY, STATE_INITIAL, STATE_LOADED, STATE_MOVING, STATE_PLAYING, STATE_POSITIONED, STATE_STOPPED, UP
-
Fields inherited from interface jmri.jmrit.audio.AudioBuffer
FORMAT_16BIT_5DOT1, FORMAT_16BIT_6DOT1, FORMAT_16BIT_7DOT1, FORMAT_16BIT_MONO, FORMAT_16BIT_QUAD, FORMAT_16BIT_STEREO, FORMAT_8BIT_5DOT1, FORMAT_8BIT_6DOT1, FORMAT_8BIT_7DOT1, FORMAT_8BIT_MONO, FORMAT_8BIT_QUAD, FORMAT_8BIT_STEREO, FORMAT_UNKNOWN
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_STATE, QUOTED_NAME_FORMAT, UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description AbstractAudioBuffer(java.lang.String systemName)
Abstract constructor for new AudioBuffer with system nameAbstractAudioBuffer(java.lang.String systemName, java.lang.String userName)
Abstract constructor for new AudioBuffer with system name and user name
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
generateLoopBuffers(int which)
Method used to generate any necessary loop buffers.protected abstract boolean
generateStreamingBuffers()
Internal method used to generate buffers for streaminglong
getEndLoopPoint()
Retrieves the end loop point of the sound sample stored in this bufferint
getFrameSize()
Retrieves the length of a sound sample frame stored in this bufferlong
getStartLoopPoint()
Retrieves the start loop point of the sound sample stored in this bufferchar
getSubType()
An Audio object can represent one of a number of subtypes of object.java.lang.String
getURL()
Return the url of the sound sampleboolean
isStreamed()
Retrieves the current streaming setting of this bufferboolean
isStreamedForced()
Determines if this buffer can be loaded in full or if it must be streamed from the file.protected abstract boolean
loadBuffer()
Method used to load the actual sound data into the bufferprotected abstract boolean
loadBuffer(java.io.InputStream s)
Method used to load the actual sound data from an InputStream into the bufferboolean
loadBuffer(java.nio.ByteBuffer b, int format, int frequency)
protected abstract void
removeStreamingBuffers()
Internal method used to remove streaming buffersvoid
setEndLoopPoint(long endLoopPoint)
Sets the end loop point of the sound sample stored in this bufferprotected void
setEndLoopPoint(long endLoopPoint, boolean generateLoopBuffers)
Internal method used to set the end loop point of this buffer with optional generation of loop buffersvoid
setInputStream(java.io.InputStream stream)
Sets the input stream of the sound samplevoid
setStartLoopPoint(long startLoopPoint)
Sets the start loop point of the sound sample stored in this bufferprotected void
setStartLoopPoint(long startLoopPoint, boolean generateLoopBuffers)
Internal method used to set the start loop point of this buffer with optional generation of loop buffersvoid
setStreamed(boolean streamed)
Sets that this buffer is to be streamed as opposed to loaded in full.protected void
setStreamedForced(boolean streamedForced)
Protected method used internally to modify the forced streaming flagvoid
setURL(java.lang.String url)
Sets the url of the sound samplevoid
stateChanged(int oldState)
Method used to update the current state of the Audio object-
Methods inherited from class jmri.implementation.AbstractAudio
cleanup, dispose, getBeanType, getState, getUsageReport, roundDecimal, roundDecimal, setState
-
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, describeState, equals, firePropertyChange, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeListenersByReference, getPropertyKeys, getSystemName, getUserName, hashCode, removeProperty, removePropertyChangeListener, removePropertyChangeListener, setComment, setProperty, setUserName, toString, toStringSuffix, updateListenerRef, vetoableChange
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jmri.jmrit.audio.AudioBuffer
getFormat, getFrequency, getLength
-
Methods inherited from interface jmri.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, describeState, dispose, getBeanType, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getRecommendedToolTip, getState, getSystemName, getUsageReport, getUserName, removeProperty, setComment, setProperty, setState, setUserName, toString, updateListenerRef, vetoableChange
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Field Detail
-
LOOP_POINT_START
protected static final int LOOP_POINT_START
Identifier of start loop point- See Also:
- Constant Field Values
-
LOOP_POINT_END
protected static final int LOOP_POINT_END
Identifier of end loop point- See Also:
- Constant Field Values
-
LOOP_POINT_BOTH
protected static final int LOOP_POINT_BOTH
Identifier of both loop points- See Also:
- Constant Field Values
-
-
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 interfaceAudio
- Returns:
- subType char
-
getURL
public java.lang.String getURL()
Description copied from interface:AudioBuffer
Return the url of the sound sampleApplies only to sub-types:
- Buffer
- Specified by:
getURL
in interfaceAudioBuffer
- Returns:
- url
-
setURL
public void setURL(java.lang.String url)
Description copied from interface:AudioBuffer
Sets the url of the sound sampleApplies only to sub-types:
- Buffer
- Specified by:
setURL
in interfaceAudioBuffer
- 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 sampleApplies only to sub-types:
- Buffer
- Specified by:
setInputStream
in interfaceAudioBuffer
- 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 bufferApplies only to sub-types:
- Buffer
- Specified by:
getFrameSize
in interfaceAudioBuffer
- 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 bufferApplies only to sub-types:
- Buffer
- Specified by:
setStartLoopPoint
in interfaceAudioBuffer
- Parameters:
startLoopPoint
- position of start loop point in samples
-
loadBuffer
public boolean loadBuffer(java.nio.ByteBuffer b, int format, int frequency)
- Specified by:
loadBuffer
in interfaceAudioBuffer
-
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 samplesgenerateLoopBuffers
- 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 bufferApplies only to sub-types:
- Buffer
- Specified by:
getStartLoopPoint
in interfaceAudioBuffer
- 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 bufferApplies only to sub-types:
- Buffer
- Specified by:
setEndLoopPoint
in interfaceAudioBuffer
- 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 samplesgenerateLoopBuffers
- 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 bufferApplies only to sub-types:
- Buffer
- Specified by:
getEndLoopPoint
in interfaceAudioBuffer
- Returns:
- position of end loop point in samples
-
setStreamed
public void setStreamed(boolean streamed)
Description copied from interface:AudioBuffer
Sets that this buffer is to be streamed as opposed to loaded in full. Can only be turned off whenisStreamedForced
is not set.Applies only to sub-types:
- Buffer
- Specified by:
setStreamed
in interfaceAudioBuffer
- Parameters:
streamed
- buffer is streamed from file or loaded in full- See Also:
AudioBuffer.isStreamedForced()
-
isStreamed
public boolean isStreamed()
Description copied from interface:AudioBuffer
Retrieves the current streaming setting of this bufferApplies only to sub-types:
- Buffer
- Specified by:
isStreamed
in interfaceAudioBuffer
- 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 interfaceAudioBuffer
- Returns:
- True if buffer must be streamed; False it can be loaded in full
-
generateLoopBuffers
protected abstract void generateLoopBuffers(int which)
Method used to generate any necessary loop buffers.- Parameters:
which
- the loop buffer to generate:LOOP_POINT_START
for the start loop bufferLOOP_POINT_END
for the end loop bufferLOOP_POINT_BOTH
for both loop buffers
-
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 interfaceAudio
- Parameters:
oldState
- the former state
-
-