Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class AudioData
- Object
- AudioData
In-memory PCM audio: one float array per channel, samples nominally in the
range -1 to 1. This is the Web Audio AudioBuffer, named differently so it
does not clash with the microphone capture class
com.codename1.media.AudioBuffer.
Create one with BaseAudioContext.createBuffer(int, int, float) or
[#fromInterleaved(float[], int, int, int, float)], play it with an
AudioBufferSourceNode, and get one back from
OfflineAudioContext.startRendering().
Constructors
public AudioData(int numberOfChannels, int length, float sampleRate) | Creates silent audio. |
Methods
public static AudioData fromInterleaved(float[] interleaved, int offset, int frames, int numberOfChannels, float sampleRate) | Creates audio from interleaved samples, the layout WAVWriter, the microphone AudioBuffer and most decoders use. |
public float[] toInterleaved() | Copies the samples out interleaved, for WAVWriter or a port API. |
public float getSampleRate() | The sample rate. |
public int getLength() | The length. |
public double getDuration() | The duration. |
public int getNumberOfChannels() | The number of channels. |
public float[] getChannelData(int channel) | The live sample array of a channel. |
public void copyFromChannel(float[] destination, int channel, int startInChannel) | Copies samples of one channel into destination. |
public void copyToChannel(float[] source, int channel, int startInChannel) | Copies source into one channel. |
Inherited methods
Constructor details
AudioData
public AudioData(int numberOfChannels, int length, float sampleRate)Creates silent audio.
Parameters
numberOfChannelsint- 1 to 32
lengthint- the length in frames, at least 1
sampleRatefloat- frames per second, 3000 to 768000
Method details
fromInterleaved
public static AudioData fromInterleaved(float[] interleaved, int offset, int frames, int numberOfChannels, float sampleRate)Creates audio from interleaved samples, the layout
WAVWriter, the
microphone AudioBuffer and most decoders use.Parameters
interleavedfloat[]- the samples
offsetint- the index of the first sample
framesint- the number of frames to copy
numberOfChannelsint- the number of interleaved channels
sampleRatefloat- frames per second
Returns
a new
AudioData holding a copy of the samplestoInterleaved
public float[] toInterleaved()Copies the samples out interleaved, for
WAVWriter or a port API.Returns
a new array of
getLength() * getNumberOfChannels() samplesgetSampleRate
public float getSampleRate()The sample rate.
Returns
frames per second
getLength
public int getLength()The length.
Returns
the number of frames
getDuration
public double getDuration()The duration.
Returns
the length in seconds
getNumberOfChannels
public int getNumberOfChannels()The number of channels.
Returns
the channel count
getChannelData
public float[] getChannelData(int channel)The live sample array of a channel. Writes to it are heard by any
AudioBufferSourceNode that is playing this data.Parameters
channelint- the channel index
Returns
the channel’s samples, not a copy
copyFromChannel
public void copyFromChannel(float[] destination, int channel, int startInChannel)Copies samples of one channel into
destination.Parameters
destinationfloat[]- the array to fill
channelint- the channel index
startInChannelint- the first frame to copy
copyToChannel
public void copyToChannel(float[] source, int channel, int startInChannel)Copies
source into one channel.Parameters
sourcefloat[]- the samples
channelint- the channel index
startInChannelint- the first frame to write