public class AudioBuffer
- Object
- 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.AudioBufferCallback | A 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
Inherited methods
Constructor details
AudioBuffer
public AudioBuffer(int maxSize)Creates a new AudioBuffer with the given maximum size.
Parameters
maxSizeint- 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
sourceAudioBuffer- 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
sampleRateint- Not documented.
numChannelsint- Not documented.
sourcefloat[]- The source array to copy data from.
offsetint- The offset in the source array to begin copying from.
lenint- 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
destAudioBuffer- The destination audio buffer.
copyTo
public void copyTo(float[] dest)Copies data from this buffer to the given float array.
Parameters
destfloat[]- 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
destfloat[]- The destination float array.
offsetint- 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
lAudioBuffer.AudioBufferCallback- The AudioBufferCallback
removeCallback
public void removeCallback(AudioBuffer.AudioBufferCallback l)Removes a callback from the audio buffer.
Parameters
lAudioBuffer.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
targetSampleRateint- The new target rate.