auditory.sampled
Class BufferedSound

java.lang.Object
  extended by auditory.sampled.BufferedSound
All Implemented Interfaces:
Content

public class BufferedSound
extends java.lang.Object
implements Content

An in-memory representation of sampled auditory content. Because this is a complete in-memory representation it often uses a lot of memory. One could, alternatively, keep part of the content in-memory and store the remainder in a file (e.g., using a ring buffer). An individual BufferedSound can only be manipulated by one thread at a time. This should not be a problem in practice since, most often, a BufferedSound will be manipulated first and then rendered. Note: For simplicity, all BufferedSound objects use signed PCM with a 16bit sample size, and a big-endian byte order (i.e., network byte order)

See Also:
"The Design and Implementation of Multimedia Software © 2011"

Constructor Summary
BufferedSound(float sampleRate)
          Explicit Value Constructor
 
Method Summary
 void addChannel(double[] signal)
          Add a channel to this BufferedSound One channel corresponds to "mono", two channels corresponds to "stereo", etc...
 void append(BufferedSound other)
          Append a BufferedSound to this BufferedSound Note: If the BufferedSound to append does not match this BufferedSound then nothing is done
 javax.sound.sampled.AudioFormat getAudioFormat()
          Get the AudioFormat for this BufferedSound
 int getMicrosecondLength()
          Get the length of this BufferedSound in microseconds
 int getMillisecondLength()
          Get the length of this BufferedSound in milliseconds
 int getNumberOfChannels()
          Get the number of channels
 int getNumberOfSamples()
          Get the number of samples (per channel) in this BufferedSound
 float getSampleRate()
          Get the sampling rate for this BufferedSound
 java.util.Iterator<double[]> getSignals()
          Get the signals Note: It is dangerous to provide access to the signal data since it could be modified in inappropriate ways
 boolean matches(BufferedSound other)
          Compares this BufferedSound object to another
 void render(javax.sound.sampled.Clip clip)
          Render this BufferedSound on the given Clip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedSound

public BufferedSound(float sampleRate)
Explicit Value Constructor

Parameters:
sampleRate - The sampling rate (in Hz)
Method Detail

addChannel

public void addChannel(double[] signal)
Add a channel to this BufferedSound One channel corresponds to "mono", two channels corresponds to "stereo", etc...


append

public void append(BufferedSound other)
Append a BufferedSound to this BufferedSound Note: If the BufferedSound to append does not match this BufferedSound then nothing is done

Parameters:
other - The BufferedSound to append

getAudioFormat

public javax.sound.sampled.AudioFormat getAudioFormat()
Get the AudioFormat for this BufferedSound

Specified by:
getAudioFormat in interface Content
Returns:
The AudioFormat

getSignals

public java.util.Iterator<double[]> getSignals()
Get the signals Note: It is dangerous to provide access to the signal data since it could be modified in inappropriate ways

Returns:
The signal for the left output

getMicrosecondLength

public int getMicrosecondLength()
Get the length of this BufferedSound in microseconds

Returns:
The length in microseconds

getMillisecondLength

public int getMillisecondLength()
Get the length of this BufferedSound in milliseconds

Returns:
The length in milliseconds

getNumberOfChannels

public int getNumberOfChannels()
Get the number of channels

Returns:
The number of channels

getNumberOfSamples

public int getNumberOfSamples()
Get the number of samples (per channel) in this BufferedSound

Returns:
The number of samples

getSampleRate

public float getSampleRate()
Get the sampling rate for this BufferedSound

Returns:
The sampling rate (in Hz)

matches

public boolean matches(BufferedSound other)
Compares this BufferedSound object to another

Parameters:
other - The BufferedSound to compare to
Returns:
true if the two match; false otherwise

render

public void render(javax.sound.sampled.Clip clip)
            throws javax.sound.sampled.LineUnavailableException
Render this BufferedSound on the given Clip

Specified by:
render in interface Content
Parameters:
clip - The Clip to use
Throws:
javax.sound.sampled.LineUnavailableException


Design and Implementation of Multimedia Software, Jones and Bartlett Publishers