Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public abstract class BaseAudioContext

  1. Object
  2. BaseAudioContext

Known subtypesAudioContext, OfflineAudioContext

What AudioContext (real time, to the speaker) and OfflineAudioContext (as fast as possible, to memory) share: the clock, the destination and the factory methods for every node, the Web Audio BaseAudioContext.

The graph is rendered in quanta of 128 frames. Building and changing it is allowed from any thread; every change is queued and applied by the renderer at the start of its next quantum, so the renderer never waits on a lock.

Methods

public float getSampleRate()The sample rate every node of this context renders at.
public double getCurrentTime()The time of the next frame to be rendered: the clock every scheduling method is measured against.
public AudioDestinationNode getDestination()The node whose input is heard (or recorded, offline).
public AudioListener getListener()The listener every PannerNode of this context is heard from.
public WaveShaperNode createWaveShaper()Creates a curve distortion node with no curve.
public AnalyserNode createAnalyser()Creates a spectrum and waveform analyser.
public DynamicsCompressorNode createDynamicsCompressor()Creates a compressor with the specification’s default settings.
public ConvolverNode createConvolver()Creates a convolver with no impulse response.
public PannerNode createPanner()Creates a 3D panner, equal-power with the inverse distance model until changed.
public AudioProcessorNode createAudioProcessor(AudioProcessor processor, int numberOfInputs, int numberOfOutputs, int[] outputChannelCount, AudioParamDescriptor[] parameters)Creates a node running custom Java DSP, the counterpart of new AudioWorkletNode(...).
public AudioProcessorNode createAudioProcessor(AudioProcessor processor, int outputChannels)Creates a one input, one output processor node with one output channel per input channel up to two, and no parameters.
public boolean isAudioProcessorSupported()Whether createAudioProcessor runs custom DSP here.
public MicrophoneSourceNode createMicrophoneSource(AudioBuffer capture)Creates a source that plays live capture, the counterpart of createMediaStreamSource for a microphone.
public boolean isMicrophoneSourceSupported()Whether the platform can capture to an AudioBuffer, which createMicrophoneSource plays.
public AudioData decodeAudioData(byte[] encoded)Decodes an encoded audio file into an AudioData for an AudioBufferSourceNode, the counterpart of decodeAudioData.
public boolean isHrtfSupported()Whether PanningModel.HRTF renders binaurally on this platform.
public abstract AudioContextState getState()The life cycle state.
public AudioData createBuffer(int numberOfChannels, int length, float sampleRate)Creates silent AudioData to fill in and play.
public GainNode createGain()Creates a node that multiplies its input by a gain.
public DelayNode createDelay()Creates a delay line of up to one second.
public DelayNode createDelay(double maxDelayTime)Creates a delay line.
public AudioBufferSourceNode createBufferSource()Creates a node that plays AudioData.
public ConstantSourceNode createConstantSource()Creates a node whose output is a constant, or automated, value.
public OscillatorNode createOscillator()Creates a band-limited oscillator, a 440 Hz sine until changed.
public BiquadFilterNode createBiquadFilter()Creates a second order filter, a 350 Hz low pass until changed.
public IIRFilterNode createIIRFilter(double[] feedforward, double[] feedback)Creates a general IIR filter.
public StereoPannerNode createStereoPanner()Creates an equal-power stereo panner.
public ChannelSplitterNode createChannelSplitter()Creates a node that splits 6 channels into 6 mono outputs.
public ChannelSplitterNode createChannelSplitter(int numberOfOutputs)Creates a node that splits channels into mono outputs.
public ChannelMergerNode createChannelMerger()Creates a node that merges 6 mono inputs into one 6 channel output.
public ChannelMergerNode createChannelMerger(int numberOfInputs)Creates a node that merges mono inputs into one output.
public PeriodicWave createPeriodicWave(float[] real, float[] imag)Creates a normalized custom waveform for an OscillatorNode.
public PeriodicWave createPeriodicWave(float[] real, float[] imag, boolean disableNormalization)Creates a custom waveform for an OscillatorNode.

Inherited methods

Method details

getSampleRate

public float getSampleRate()
The sample rate every node of this context renders at.

Returns

frames per second

getCurrentTime

public double getCurrentTime()
The time of the next frame to be rendered: the clock every scheduling method is measured against. It starts at 0 and advances one render quantum at a time.

Returns

seconds

getDestination

public AudioDestinationNode getDestination()
The node whose input is heard (or recorded, offline).

Returns

the destination

getListener

public AudioListener getListener()
The listener every PannerNode of this context is heard from.

Returns

the listener

createWaveShaper

public WaveShaperNode createWaveShaper()
Creates a curve distortion node with no curve.

Returns

the node

createAnalyser

public AnalyserNode createAnalyser()
Creates a spectrum and waveform analyser.

Returns

the node

createDynamicsCompressor

public DynamicsCompressorNode createDynamicsCompressor()
Creates a compressor with the specification’s default settings.

Returns

the node

createConvolver

public ConvolverNode createConvolver()
Creates a convolver with no impulse response.

Returns

the node

createPanner

public PannerNode createPanner()
Creates a 3D panner, equal-power with the inverse distance model until changed.

Returns

the node

createAudioProcessor

public AudioProcessorNode createAudioProcessor(AudioProcessor processor, int numberOfInputs, int numberOfOutputs, int[] outputChannelCount, AudioParamDescriptor[] parameters)
Creates a node running custom Java DSP, the counterpart of new AudioWorkletNode(...). There is no module to load: the processor is an ordinary object, called on the render thread.

Parameters

processor AudioProcessor
the DSP
numberOfInputs int
inputs the node has
numberOfOutputs int
outputs the node has
outputChannelCount int[]
channels of each output; null gives every output one
parameters AudioParamDescriptor[]
the parameters to create, or null for none

Returns

the node

createAudioProcessor

public AudioProcessorNode createAudioProcessor(AudioProcessor processor, int outputChannels)
Creates a one input, one output processor node with one output channel per input channel up to two, and no parameters.

Parameters

processor AudioProcessor
the DSP
outputChannels int
the output’s channel count

Returns

the node

isAudioProcessorSupported

public boolean isAudioProcessorSupported()
Whether createAudioProcessor runs custom DSP here. It is always true, since the whole graph is rendered by portable code; the method exists so code written for the Web Audio worklet’s spotty support can ask.

Returns

true

createMicrophoneSource

public MicrophoneSourceNode createMicrophoneSource(AudioBuffer capture)
Creates a source that plays live capture, the counterpart of createMediaStreamSource for a microphone. Record with MediaRecorderBuilder.redirectToAudioBuffer(true) and pass the buffer from MediaManager.getAudioBuffer(path, true, size).

Parameters

capture AudioBuffer
the buffer the recorder fills

Returns

the node

isMicrophoneSourceSupported

public boolean isMicrophoneSourceSupported()
Whether the platform can capture to an AudioBuffer, which createMicrophoneSource plays. Recording still needs the user’s permission, which the recorder asks for.

Returns

true where capture to a buffer is implemented

decodeAudioData

public AudioData decodeAudioData(byte[] encoded)

Decodes an encoded audio file into an AudioData for an AudioBufferSourceNode, the counterpart of decodeAudioData.

The decoder is portable code and reads RIFF WAVE (integer PCM of 8 to 32 bits, float of 32 or 64 bits). It answers null for anything else; convert compressed audio to WAVE ahead of time. The result keeps the file’s sample rate, and a buffer source resamples it as it plays.

Parameters

encoded byte[]
the file’s bytes

Returns

the audio, or null when the format is not one this decoder reads

isHrtfSupported

public boolean isHrtfSupported()
Whether PanningModel.HRTF renders binaurally on this platform. It is always true: the head model is portable code. The method exists so code written for platforms where HRTF might fall back to equal-power can ask.

Returns

true

getState

public abstract AudioContextState getState()
The life cycle state.

Returns

the state

createBuffer

public AudioData createBuffer(int numberOfChannels, int length, float sampleRate)
Creates silent AudioData to fill in and play.

Parameters

numberOfChannels int
1 to 32
length int
frames
sampleRate float
frames per second; need not match the context

Returns

the new data

createGain

public GainNode createGain()
Creates a node that multiplies its input by a gain.

Returns

the node

createDelay

public DelayNode createDelay()
Creates a delay line of up to one second.

Returns

the node

createDelay

public DelayNode createDelay(double maxDelayTime)
Creates a delay line.

Parameters

maxDelayTime double
the longest delay in seconds, more than 0 and less than 180

Returns

the node

createBufferSource

public AudioBufferSourceNode createBufferSource()
Creates a node that plays AudioData.

Returns

the node

createConstantSource

public ConstantSourceNode createConstantSource()
Creates a node whose output is a constant, or automated, value.

Returns

the node

createOscillator

public OscillatorNode createOscillator()
Creates a band-limited oscillator, a 440 Hz sine until changed.

Returns

the node

createBiquadFilter

public BiquadFilterNode createBiquadFilter()
Creates a second order filter, a 350 Hz low pass until changed.

Returns

the node

createIIRFilter

public IIRFilterNode createIIRFilter(double[] feedforward, double[] feedback)
Creates a general IIR filter.

Parameters

feedforward double[]
the numerator coefficients, 1 to 20 of them, not all 0
feedback double[]
the denominator coefficients, 1 to 20 of them, the first not 0

Returns

the node

createStereoPanner

public StereoPannerNode createStereoPanner()
Creates an equal-power stereo panner.

Returns

the node

createChannelSplitter

public ChannelSplitterNode createChannelSplitter()
Creates a node that splits 6 channels into 6 mono outputs.

Returns

the node

createChannelSplitter

public ChannelSplitterNode createChannelSplitter(int numberOfOutputs)
Creates a node that splits channels into mono outputs.

Parameters

numberOfOutputs int
1 to 32

Returns

the node

createChannelMerger

public ChannelMergerNode createChannelMerger()
Creates a node that merges 6 mono inputs into one 6 channel output.

Returns

the node

createChannelMerger

public ChannelMergerNode createChannelMerger(int numberOfInputs)
Creates a node that merges mono inputs into one output.

Parameters

numberOfInputs int
1 to 32

Returns

the node

createPeriodicWave

public PeriodicWave createPeriodicWave(float[] real, float[] imag)
Creates a normalized custom waveform for an OscillatorNode.

Parameters

real float[]
cosine coefficients; index 0, the DC term, is ignored
imag float[]
sine coefficients, the same length as real

Returns

the waveform

createPeriodicWave

public PeriodicWave createPeriodicWave(float[] real, float[] imag, boolean disableNormalization)
Creates a custom waveform for an OscillatorNode.

Parameters

real float[]
cosine coefficients; index 0, the DC term, is ignored
imag float[]
sine coefficients, the same length as real
disableNormalization boolean
true to keep the coefficients’ own amplitude rather than scaling the peak to 1

Returns

the waveform