Class BaseAudioContext
- Direct Known Subclasses:
AudioContext, 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.
-
Method Summary
Modifier and TypeMethodDescriptionCreates a spectrum and waveform analyser.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.createAudioProcessor(AudioProcessor processor, int numberOfInputs, int numberOfOutputs, int[] outputChannelCount, AudioParamDescriptor[] parameters) Creates a node running custom Java DSP, the counterpart ofnew AudioWorkletNode(...).Creates a second order filter, a 350 Hz low pass until changed.createBuffer(int numberOfChannels, int length, float sampleRate) Creates silentAudioDatato fill in and play.Creates a node that playsAudioData.Creates a node that merges 6 mono inputs into one 6 channel output.createChannelMerger(int numberOfInputs) Creates a node that merges mono inputs into one output.Creates a node that splits 6 channels into 6 mono outputs.createChannelSplitter(int numberOfOutputs) Creates a node that splits channels into mono outputs.Creates a node whose output is a constant, or automated, value.Creates a convolver with no impulse response.Creates a delay line of up to one second.createDelay(double maxDelayTime) Creates a delay line.Creates a compressor with the specification's default settings.Creates a node that multiplies its input by a gain.createIIRFilter(double[] feedforward, double[] feedback) Creates a general IIR filter.createMicrophoneSource(AudioBuffer capture) Creates a source that plays live capture, the counterpart ofcreateMediaStreamSourcefor a microphone.Creates a band-limited oscillator, a 440 Hz sine until changed.Creates a 3D panner, equal-power with the inverse distance model until changed.createPeriodicWave(float[] real, float[] imag) Creates a normalized custom waveform for anOscillatorNode.createPeriodicWave(float[] real, float[] imag, boolean disableNormalization) Creates a custom waveform for anOscillatorNode.Creates an equal-power stereo panner.Creates a curve distortion node with no curve.decodeAudioData(byte[] encoded) Decodes an encoded audio file into anAudioDatafor anAudioBufferSourceNode, the counterpart ofdecodeAudioData.doubleThe time of the next frame to be rendered: the clock every scheduling method is measured against.The node whose input is heard (or recorded, offline).The listener everyPannerNodeof this context is heard from.floatThe sample rate every node of this context renders at.abstract AudioContextStategetState()The life cycle state.booleanWhethercreateAudioProcessor(AudioProcessor, int, int, int[], AudioParamDescriptor[])runs custom DSP here.booleanWhetherPanningModel.HRTFrenders binaurally on this platform.booleanWhether the platform can capture to anAudioBuffer, whichcreateMicrophoneSource(AudioBuffer)plays.
-
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
The node whose input is heard (or recorded, offline).
Returns
the destination
-
getListener
-
createWaveShaper
Creates a curve distortion node with no curve.
Returns
the node
-
createAnalyser
Creates a spectrum and waveform analyser.
Returns
the node
-
createDynamicsCompressor
Creates a compressor with the specification's default settings.
Returns
the node
-
createConvolver
Creates a convolver with no impulse response.
Returns
the node
-
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: the DSP -
numberOfInputs: inputs the node has -
numberOfOutputs: outputs the node has -
outputChannelCount: channels of each output; null gives every output one -
parameters: the parameters to create, or null for none
Returns
the node
-
-
createAudioProcessor
Creates a one input, one output processor node with one output channel per input channel up to two, and no parameters.
Parameters
-
processor: the DSP -
outputChannels: the output's channel count
Returns
the node
-
-
isAudioProcessorSupported
public boolean isAudioProcessorSupported()Whether
createAudioProcessor(AudioProcessor, int, int, int[], AudioParamDescriptor[])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
Creates a source that plays live capture, the counterpart of
createMediaStreamSourcefor a microphone. Record withMediaRecorderBuilder.redirectToAudioBuffer(true)and pass the buffer fromMediaManager.getAudioBuffer(path, true, size).Parameters
capture: the buffer the recorder fills
Returns
the node
-
isMicrophoneSourceSupported
public boolean isMicrophoneSourceSupported()Whether the platform can capture to an
AudioBuffer, whichcreateMicrophoneSource(AudioBuffer)plays. Recording still needs the user's permission, which the recorder asks for.Returns
true where capture to a buffer is implemented
-
decodeAudioData
Decodes an encoded audio file into an
AudioDatafor anAudioBufferSourceNode, the counterpart ofdecodeAudioData.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: the file's bytes
Returns
the audio, or null when the format is not one this decoder reads
-
isHrtfSupported
public boolean isHrtfSupported()Whether
PanningModel.HRTFrenders 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
The life cycle state.
Returns
the state
-
createBuffer
-
createGain
Creates a node that multiplies its input by a gain.
Returns
the node
-
createDelay
Creates a delay line of up to one second.
Returns
the node
-
createDelay
Creates a delay line.
Parameters
maxDelayTime: the longest delay in seconds, more than 0 and less than 180
Returns
the node
-
createBufferSource
-
createConstantSource
Creates a node whose output is a constant, or automated, value.
Returns
the node
-
createOscillator
Creates a band-limited oscillator, a 440 Hz sine until changed.
Returns
the node
-
createBiquadFilter
Creates a second order filter, a 350 Hz low pass until changed.
Returns
the node
-
createIIRFilter
Creates a general IIR filter.
Parameters
-
feedforward: the numerator coefficients, 1 to 20 of them, not all 0 -
feedback: the denominator coefficients, 1 to 20 of them, the first not 0
Returns
the node
-
-
createStereoPanner
Creates an equal-power stereo panner.
Returns
the node
-
createChannelSplitter
Creates a node that splits 6 channels into 6 mono outputs.
Returns
the node
-
createChannelSplitter
Creates a node that splits channels into mono outputs.
Parameters
numberOfOutputs: 1 to 32
Returns
the node
-
createChannelMerger
Creates a node that merges 6 mono inputs into one 6 channel output.
Returns
the node
-
createChannelMerger
Creates a node that merges mono inputs into one output.
Parameters
numberOfInputs: 1 to 32
Returns
the node
-
createPeriodicWave
Creates a normalized custom waveform for an
OscillatorNode.Parameters
-
real: cosine coefficients; index 0, the DC term, is ignored -
imag: sine coefficients, the same length asreal
Returns
the waveform
-
-
createPeriodicWave
Creates a custom waveform for an
OscillatorNode.Parameters
-
real: cosine coefficients; index 0, the DC term, is ignored -
imag: sine coefficients, the same length asreal -
disableNormalization: true to keep the coefficients' own amplitude rather than scaling the peak to 1
Returns
the waveform
-
-