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.


Constructor Index

 o AudioBuffer(AudioBuffer)
Construct a copy of an AudioBuffer.
 o AudioBuffer(AudioFormat)
Construct an empty AudioBuffer which will hold data of the specified format.
 o AudioBuffer(AudioFormat, byte[])
Construct an AudioBuffer containing audio from the supplied byte array.
 o AudioBuffer(AudioInputStream)
Construct an AudioBuffer containing audio from the supplied AudioInputStream.

Method Index

 o getEncoding()
Get the AudioFormat.Encoding corresponding to the AudioBuffer's audio data.
 o getFormat()
Get the audio format of the buffer's data as an AudioFormat object.
 o getFrameSize()
Get the frame size (bytes per sample) of the AudioBuffer's data.
 o getSampleRate()
Get the sample rate (samples per second) of the AudioBuffer's data.
 o read(byte[], int, int)
Retrieve data from the buffer.
 o toAudioInputStream()
Obtain an AudioInputStream that contains the AudioBuffer's data.
 o toByteArray()
Obtain a byte array that contains the AudioBuffer's data.
 o transcode(AudioFormat$Encoding)
Convert the encoding of the audio in the buffer to the specified encoding.
 o write(byte[], int, int)
Add data to the buffer.

Constructors

 o AudioBuffer
 public AudioBuffer(javax.sound.sampled.AudioFormat format)
Construct an empty AudioBuffer which will hold data of the specified format.

 o AudioBuffer
 public AudioBuffer(javax.sound.sampled.AudioFormat format,
                    byte audioByteArray[])
Construct an AudioBuffer containing audio from the supplied byte array.

 o AudioBuffer
 public AudioBuffer(javax.sound.sampled.AudioInputStream ais)
Construct an AudioBuffer containing audio from the supplied AudioInputStream.

 o AudioBuffer
 public AudioBuffer(audio.AudioBuffer ab)
Construct a copy of an AudioBuffer.

Methods

 o getEncoding
 public javax.sound.sampled.AudioFormat$Encoding getEncoding()
Get the AudioFormat.Encoding corresponding to the AudioBuffer's audio data.

 o getSampleRate
 public float getSampleRate()
Get the sample rate (samples per second) of the AudioBuffer's data.

 o getFrameSize
 public int getFrameSize()
Get the frame size (bytes per sample) of the AudioBuffer's data.

 o getFormat
 public javax.sound.sampled.AudioFormat getFormat()
Get the audio format of the buffer's data as an AudioFormat object.

 o toByteArray
 public byte[] toByteArray()
Obtain a byte array that contains the AudioBuffer's data.

 o toAudioInputStream
 public javax.sound.sampled.AudioInputStream toAudioInputStream()
Obtain an AudioInputStream that contains the AudioBuffer's data.

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

 o read
 public int read(byte b[],
                 int off,
                 int len) throws java.io.IOException
Retrieve data from the buffer.

 o write
 public void write(byte b[],
                   int off,
                   int len)
Add data to the buffer.


All Packages  Class Hierarchy  This Package  Previous  Next  Index