public class AudioBuffer

  1. Object
  2. AudioBuffer
This class can be used to capture raw PCM data from the device’s microphone. AudioBuffers should be obtained via the boolean, int) method.

Nested types

interface AudioBuffer.AudioBufferCallbackA callback that can be registered to receive notifications when the contents of the AudioBuffer is changed.

Constructors

public AudioBuffer(int maxSize)Creates a new AudioBuffer with the given maximum size.

Methods

public void copyFrom(AudioBuffer source)Copies data into the buffer from the given source buffer.
public void copyFrom(int sampleRate, int numChannels, float[] source)Copies data from the source array into this buffer.
public void copyFrom(int sampleRate, int numChannels, float[] source, int offset, int len)Copies data from the source array (in the given range) into the buffer.
public void copyTo(AudioBuffer dest)Copies data to another audio buffer.
public void copyTo(float[] dest)Copies data from this buffer to the given float array.
public void copyTo(float[] dest, int offset)Copies data from this buffer to the given float array.
public int getSize()The current size of the buffer.
public int getMaxSize()Gets the maximum size of the buffer.
public void addCallback(AudioBuffer.AudioBufferCallback l)Adds a callback to be notified when the contents of this buffer are changed.
public void removeCallback(AudioBuffer.AudioBufferCallback l)Removes a callback from the audio buffer.
public int getSampleRate()
public int getNumChannels()
public void downSample(int targetSampleRate)Downsamples the buffer to the given rate.

Inherited methods

Constructor details

AudioBuffer

public AudioBuffer(int maxSize)
Creates a new AudioBuffer with the given maximum size.

Parameters

maxSize int
The maximum size of the buffer.

Method details

copyFrom

public void copyFrom(AudioBuffer source)
Copies data into the buffer from the given source buffer. This will trigger the callbacks’ AudioBufferCallback#frameReceived(com.codename1.media.AudioBuffer) method.

Parameters

source AudioBuffer
The source buffer to copy from.

copyFrom

public void copyFrom(int sampleRate, int numChannels, float[] source)
Copies data from the source array into this buffer. This will trigger the callbacks’ AudioBufferCallback#frameReceived(com.codename1.media.AudioBuffer) method.

copyFrom

public void copyFrom(int sampleRate, int numChannels, float[] source, int offset, int len)
Copies data from the source array (in the given range) into the buffer. This will trigger the callbacks’ AudioBufferCallback#frameReceived(com.codename1.media.AudioBuffer) method.

Parameters

sampleRate int
Not documented.
numChannels int
Not documented.
source float[]
The source array to copy data from.
offset int
The offset in the source array to begin copying from.
len int
The length of the range to copy.

copyTo

public void copyTo(AudioBuffer dest)
Copies data to another audio buffer. This will trigger callbacks in the destination.

Parameters

dest AudioBuffer
The destination audio buffer.

copyTo

public void copyTo(float[] dest)
Copies data from this buffer to the given float array.

Parameters

dest float[]
The destination float array to copy to.

copyTo

public void copyTo(float[] dest, int offset)
Copies data from this buffer to the given float array.

Parameters

dest float[]
The destination float array.
offset int
The offset in the destination array to start copying to.

getSize

public int getSize()
The current size of the buffer. This value will be changed each time data is copied into the buffer to reflect the current size of the data.

getMaxSize

public int getMaxSize()
Gets the maximum size of the buffer. Trying to copy more than this amount of data into the buffer will result in an IndexOutOfBoundsException.

addCallback

public void addCallback(AudioBuffer.AudioBufferCallback l)
Adds a callback to be notified when the contents of this buffer are changed.

Parameters

l AudioBuffer.AudioBufferCallback
The AudioBufferCallback

removeCallback

public void removeCallback(AudioBuffer.AudioBufferCallback l)
Removes a callback from the audio buffer.

Parameters

l AudioBuffer.AudioBufferCallback
The callback to remove.

getSampleRate

public int getSampleRate()

Returns

the sampleRate

getNumChannels

public int getNumChannels()

Returns

the numChannels

downSample

public void downSample(int targetSampleRate)

Downsamples the buffer to the given rate. This will change the result of #getSize() and #getSampleRate().

Note: This should only be called inside the AudioBuffer callback since it is modifying the contents of the buffer.

Parameters

targetSampleRate int
The new target rate.