Class BaseAudioContext

java.lang.Object
com.codename1.media.audio.BaseAudioContext
Direct Known Subclasses:
AudioContext, OfflineAudioContext

public abstract class BaseAudioContext extends Object

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 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: 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

      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: 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

      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: the buffer the recorder fills
      Returns

      the node

    • isMicrophoneSourceSupported

      public boolean isMicrophoneSourceSupported()

      Whether the platform can capture to an AudioBuffer, which createMicrophoneSource(AudioBuffer) 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: 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: 1 to 32

      • length: frames

      • sampleRate: 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: 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: 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

      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: 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: 1 to 32
      Returns

      the node

    • createPeriodicWave

      public PeriodicWave createPeriodicWave(float[] real, float[] imag)

      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 as real

      Returns

      the waveform

    • createPeriodicWave

      public PeriodicWave createPeriodicWave(float[] real, float[] imag, boolean disableNormalization)

      Creates a custom waveform for an OscillatorNode.

      Parameters
      • real: cosine coefficients; index 0, the DC term, is ignored

      • imag: sine coefficients, the same length as real

      • disableNormalization: true to keep the coefficients' own amplitude rather than scaling the peak to 1

      Returns

      the waveform