Class 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().
-
Constructor Summary
ConstructorsConstructorDescriptionAudioData(int numberOfChannels, int length, float sampleRate) Creates silent audio. -
Method Summary
Modifier and TypeMethodDescriptionvoidcopyFromChannel(float[] destination, int channel, int startInChannel) Copies samples of one channel intodestination.voidcopyToChannel(float[] source, int channel, int startInChannel) Copiessourceinto one channel.static AudioDatafromInterleaved(float[] interleaved, int offset, int frames, int numberOfChannels, float sampleRate) Creates audio from interleaved samples, the layoutWAVWriter, the microphoneAudioBufferand most decoders use.float[]getChannelData(int channel) The live sample array of a channel.doubleThe duration.intThe length.intThe number of channels.floatThe sample rate.float[]Copies the samples out interleaved, forWAVWriteror a port API.
-
Constructor Details
-
AudioData
public AudioData(int numberOfChannels, int length, float sampleRate) Creates silent audio.
Parameters
-
numberOfChannels: 1 to 32 -
length: the length in frames, at least 1 -
sampleRate: 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 microphoneAudioBufferand most decoders use.Parameters
-
interleaved: the samples -
offset: the index of the first sample -
frames: the number of frames to copy -
numberOfChannels: the number of interleaved channels -
sampleRate: frames per second
Returns
a new
AudioDataholding a copy of the samples -
-
toInterleaved
public float[] toInterleaved()Copies the samples out interleaved, for
WAVWriteror a port API.Returns
a new array of
getLength() * getNumberOfChannels()samples -
getSampleRate
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
AudioBufferSourceNodethat is playing this data.Parameters
channel: 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
-
destination: the array to fill -
channel: the channel index -
startInChannel: the first frame to copy
-
-
copyToChannel
public void copyToChannel(float[] source, int channel, int startInChannel) Copies
sourceinto one channel.Parameters
-
source: the samples -
channel: the channel index -
startInChannel: the first frame to write
-
-