All Packages Class Hierarchy This Package Previous Next Index
Class audio.AudioBuffer
audio.AudioBuffer
- public class AudioBuffer
- extends java.lang.Object
An AudioBuffer is a self-describing fragment of audio in memory.
It can be read and written in a manner similar to
java.io.ByteArrayInputStream and java.io.ByteArrayOutputStream.
It knows how to transcode itself from one audio format to another.
GRJ - 11/5/02 - This code can probably be simplifed somewhat, but
my initial goal was to break out this functionality. The goal
was to make an interface that works. The implementation can be
cleaned up in the next version.
-
AudioBuffer(AudioBuffer)
- Construct a copy of an AudioBuffer.
-
AudioBuffer(AudioFormat)
- Construct an empty AudioBuffer which will hold data of the
specified format.
-
AudioBuffer(AudioFormat, byte[])
- Construct an AudioBuffer containing audio from the supplied
byte array.
-
AudioBuffer(AudioInputStream)
- Construct an AudioBuffer containing audio from the supplied
AudioInputStream.
-
getEncoding()
- Get the AudioFormat.Encoding corresponding to the AudioBuffer's
audio data.
-
getFormat()
- Get the audio format of the buffer's data as an AudioFormat object.
-
getFrameSize()
- Get the frame size (bytes per sample) of the AudioBuffer's data.
-
getSampleRate()
- Get the sample rate (samples per second) of the AudioBuffer's data.
-
read(byte[], int, int)
- Retrieve data from the buffer.
-
toAudioInputStream()
- Obtain an AudioInputStream that contains the AudioBuffer's data.
-
toByteArray()
- Obtain a byte array that contains the AudioBuffer's data.
-
transcode(AudioFormat$Encoding)
- Convert the encoding of the audio in the buffer to the
specified encoding.
-
write(byte[], int, int)
- Add data to the buffer.
AudioBuffer
public AudioBuffer(javax.sound.sampled.AudioFormat format)
- Construct an empty AudioBuffer which will hold data of the
specified format.
AudioBuffer
public AudioBuffer(javax.sound.sampled.AudioFormat format,
byte audioByteArray[])
- Construct an AudioBuffer containing audio from the supplied
byte array.
AudioBuffer
public AudioBuffer(javax.sound.sampled.AudioInputStream ais)
- Construct an AudioBuffer containing audio from the supplied
AudioInputStream.
AudioBuffer
public AudioBuffer(audio.AudioBuffer ab)
- Construct a copy of an AudioBuffer.
getEncoding
public javax.sound.sampled.AudioFormat$Encoding getEncoding()
- Get the AudioFormat.Encoding corresponding to the AudioBuffer's
audio data.
getSampleRate
public float getSampleRate()
- Get the sample rate (samples per second) of the AudioBuffer's data.
getFrameSize
public int getFrameSize()
- Get the frame size (bytes per sample) of the AudioBuffer's data.
getFormat
public javax.sound.sampled.AudioFormat getFormat()
- Get the audio format of the buffer's data as an AudioFormat object.
toByteArray
public byte[] toByteArray()
- Obtain a byte array that contains the AudioBuffer's data.
toAudioInputStream
public javax.sound.sampled.AudioInputStream toAudioInputStream()
- Obtain an AudioInputStream that contains the AudioBuffer's data.
transcode
public void transcode(javax.sound.sampled.AudioFormat$Encoding destinationEncoding)
- Convert the encoding of the audio in the buffer to the
specified encoding.
GRJ - 11/5/02 - This is inefficient code. See disclaimer above.
Also, there seems to be a bug in the implementation here (or in
the transcoding version of AudioSystem.getAudioInputStream used by
the implementation?). The available() method of AudioInputStream does
not return a different length after the transcode if the number
of bytes per sample changes. I had to do a workaround.
read
public int read(byte b[],
int off,
int len) throws java.io.IOException
- Retrieve data from the buffer.
write
public void write(byte b[],
int off,
int len)
- Add data to the buffer.
All Packages Class Hierarchy This Package Previous Next Index