From d0181c16e5b5e1421c4845635597406dd65bddfe Mon Sep 17 00:00:00 2001
From: Hongchan Choi
+ The AudioWorklet object allows importing user-supplied Javascript code
+ that runs on the audio rendering thread. This processing mechanism
+ ensures the aligned execution of the script code with other built-in
+ AudioNodes in the audio graph. The AudioWorklet object imports
+ and stores the definition of custom audio processor and then an
+ AudioWorkletNode object can be constructed based on the
+ processor definition. Note that the registered definition in an
+ AudioWorklet is valid for the entire global scope, therefore any
+ AudioContext in the same global scope can be used to create the
+ custom node.
+
+ An AudioWorklet object provides the capability to import module
+ scripts into its associated AudioWorkletGlobalScope. The user
+ agent can then create AudioWorkletProcessor classes registered
+ on the AudioWorkletGlobalScopes and construct their instances.
+ A processor object represents an audio processing module that runs on
+ the audio rendering thread. After the processor definition is
+ successfully stored, an instance of AudioWorkletNode can be
+ created in the main global scope. This is the counterpart of the
+ processor but lives on the main control thread. These two
+ components can communicate via message passing.
+
+ Imports a module script returns a promise once it is fully loaded.
+
+ The construction procedure of AudioWokletNode and the
+ corresponding AudioWorkletProcessor object consists of several
+ coordinated interactions and the following algorithm specifies such
+ procedure. Note that these steps must be performed in an atomic
+ fashion.
+
+ This interface represens an AudioNode which lives on the main
+ control thread. The user can create this node from an instance of
+ AudioContext and such node can be connected with other built-in
+ AudioNodes to form an audio graph.
+
+ The onmessage handler is called whenever the associated
+ AudioWorkletProcessor posts a message back to the main
+ thread.
+
+ postMessage May be called to send a message to the corresponding
+ AudioWorkletProcessor via the algorithm defined by the
+ Worker specification.
+
+ The AudioNodeOptions dictionary can be used for the custom
+ initialization of AudioNode attributes in the
+ AudioWorkletNode constructor. Entries in this dictionary whose
+ names that correspond to AudioParams in the class definition of
+ an AudioWorkletProcessor are used to initialize the parameter
+ values upon the creation of a node.
+
+ This interface is derived from WorkletGlobalScope
+ representing a special execution context in which an audio
+ processing script is run. It it is designed to enable the
+ generation, processing, and analysis of audio data directly using
+ JavaScript in the audio rendering thread. The user-supplied
+ script code is evaluated in this scope to define
+ AudioWorkletProcessor.
+
+ Registers a definition of a class that is derived from
+ AudioWorkletProcessor.
+
+ This interface represents an audio processing module that runs on
+ the audio rendering thread. It is defined in an
+ AudioWorkletGlobalScope and the definition of such class
+ manifests the actual audio processing mechanism of an
+ AudioWorkletNode. AudioWorkletProcessor can only be
+ instantiated by the construction of an AudioWorkletNode
+ instance.
+
+ This array contains AudioParamDescriptors, which are
+ descriptors for each controllable parameter on an
+ AudioNode. This static property is referred in the
+ construction of an AudioWorkletNode to create instances
+ of AudioParam in the node.
+
+ This getter provides an object contains the information of the
+ associated AudioContext such as the sample rate and the
+ current playback time when queried.
+
+ The onmessage handler is called whenever the
+ AudioWorkletNode posts a node message back to the
+ corresponding processor object on the audio rendering
+ thread.
+
+ This method gets executed isochronously by the audio rendering
+ thread along with the rest of an audio graph while the
+ associated AudioWorkletNode is connected.
+
+ It may be called to send a message to the
+ AudioWorkletNode, via the algorithm defined by the
+ Worker specification.
+
+ The AudioParamDescriptor dictionary is used to specify properties
+ for an AudioParam object that is used in an
+ AudioWorkletNode.
+
+ The AudioContextInfo dictionary is used to query the current
+ status of the associated AudioContext within the scope of
+ an AudioWorkletProcessor.
+
+ Bitcrushing is a mechanism by which the audio quality of an audio
+ stream is reduced - both by quantizing the value (simulating lower
+ bit-depth in integer-based audio), and by quantizing in time
+ (simulating a lower digital sample rate). This example shows how
+ to use AudioParams (in this case, treated as
+ a-rate) inside an AudioWorkletProcessor.
+
+ This example demonstrates a simple sound level meter. It shows how
+ to exchange states (that do not require sample-accurate
+ scheduling) between AudioWorkletNode and
+ AudioWorkletProcessor. This node does not use any output.
+
- The AudioWorklet object allows importing user-supplied Javascript code
- that runs on the audio rendering thread. This processing mechanism
- ensures the aligned execution of the script code with other built-in
- AudioNodes in the audio graph. The AudioWorklet object imports
- and stores the definition of custom audio processor and then an
- AudioWorkletNode object can be constructed based on the
- processor definition. Note that the registered definition in an
- AudioWorklet is valid for the entire global scope, therefore any
- AudioContext in the same global scope can be used to create the
- custom node.
-
- An AudioWorklet object provides the capability to import module
- scripts into its associated AudioWorkletGlobalScope. The user
- agent can then create AudioWorkletProcessor classes registered
- on the AudioWorkletGlobalScopes and construct their instances.
- A processor object represents an audio processing module that runs on
- the audio rendering thread. After the processor definition is
- successfully stored, an instance of AudioWorkletNode can be
- created in the main global scope. This is the counterpart of the
- processor but lives on the main control thread. These two
- components can communicate via message passing.
+ The
+ The
+ After importing a module script into the
+
- Imports a module script returns a promise once it is fully loaded.
+ Imports a module script and returns a promise when fully loaded.
- The construction procedure of AudioWokletNode and the
- corresponding AudioWorkletProcessor object consists of several
- coordinated interactions and the following algorithm specifies such
- procedure. Note that these steps must be performed in an atomic
- fashion.
+ The construction procedure of
- This interface represens an AudioNode which lives on the main
- control thread. The user can create this node from an instance of
- AudioContext and such node can be connected with other built-in
- AudioNodes to form an audio graph.
+ This interface represents a user-defined
+
- The onmessage handler is called whenever the associated
- AudioWorkletProcessor posts a message back to the main
- thread.
+ The
- postMessage May be called to send a message to the corresponding
- AudioWorkletProcessor via the algorithm defined by the
- Worker specification.
+
- The AudioNodeOptions dictionary can be used for the custom
- initialization of AudioNode attributes in the
- AudioWorkletNode constructor. Entries in this dictionary whose
- names that correspond to AudioParams in the class definition of
- an AudioWorkletProcessor are used to initialize the parameter
- values upon the creation of a node.
+ The
- This interface is derived from WorkletGlobalScope
- representing a special execution context in which an audio
- processing script is run. It it is designed to enable the
- generation, processing, and analysis of audio data directly using
- JavaScript in the audio rendering thread. The user-supplied
- script code is evaluated in this scope to define
- AudioWorkletProcessor.
+ This interface is derived from
@@ -5174,10 +5183,7 @@
This interface represents an audio processing module that runs on
the audio rendering thread. It is defined in an
- AudioWorkletGlobalScope and the definition of such class
- manifests the actual audio processing mechanism of an
- AudioWorkletNode. AudioWorkletProcessor can only be
- instantiated by the construction of an AudioWorkletNode
- instance.
+
- This array contains AudioParamDescriptors, which are
+ This array contains AudioParamDescriptors, which are
descriptors for each controllable parameter on an
- AudioNode. This static property is referred in the
+ AudioNode. This static property is referenced in the
construction of an AudioWorkletNode to create instances
- of AudioParam in the node.
+ of an AudioParam in the node.
- This getter provides an object contains the information of the
- associated AudioContext such as the sample rate and the
- current playback time when queried.
+ This getter returns an
- The onmessage handler is called whenever the
- AudioWorkletNode posts a node message back to the
- corresponding processor object on the audio rendering
- thread.
+ The
- This method gets executed isochronously by the audio rendering
- thread along with the rest of an audio graph while the
- associated AudioWorkletNode is connected.
+ This method gets executed isochronously by the audio
+ rendering thread.
It may be called to send a message to the
- AudioWorkletNode, via the algorithm defined by the
- Worker specification.
+
- The AudioParamDescriptor dictionary is used to specify properties
- for an AudioParam object that is used in an
- AudioWorkletNode.
+ The
- The AudioContextInfo dictionary is used to query the current
- status of the associated AudioContext within the scope of
- an AudioWorkletProcessor.
+ The
+
+ The AudioWorklet interface
+
+
+
+
+
+ Construction Procedure of AudioWorkletNode and AudioWorkletProcessor
+
+
+
+
+
+
+ The AudioWorkletNode interface
+
+
+
+
+
+ AudioWorkletNodeOptions
+
+
+
+
+ The AudioWorkletGlobalScope interface
+
+
+
+
+
+
+ The AudioWorkletProcessor interface
+
+
+
+
+
+
+
+
+ AudioParamDescriptor
+
+
+
+
+ AudioContextInfo
+
+
+
+
+ AudioWorklet Examples
+
+
+
+ The BitCrusher Node
+
+
+ Global Scope
+
+
+window.audioWorklet.import('bitcrusher.js').then(function () {
+ var context = new AudioContext();
+ var osc = new OscillatorNode(context);
+ var amp = new GainNode(context);
+
+ // Create a worklet node. 'BitCrusher' identifies the
+ // AudioWorkletProcessor previously registered when
+ // bitcrusher.js was imported. The options automatically
+ // initialize the correspondingly named AudioParams.
+ var bitcrusher = new AudioWorkletNode(context, 'BitCrusher', {
+ bitDepth: 8,
+ frequencyReduction: 0.5
+ });
+
+ osc.connect(bitcrusher).connect(amp).connect(context.destination);
+ osc.start();
+});
+
+
+ AudioWorkletGlobalScope: bitcrusher.js
+
+
+registerAudioWorkletProcessor('BitCrusher', class extends AudioWorkletProcessor {
+
+ static get parameterDescriptors () {
+ return [{
+ name: 'bitDepth',
+ defaultValue: 12,
+ minValue: 1
+ maxValue: 16
+ }, {
+ name: 'frequencyReduction',
+ defaultValue: 0.5,
+ minValue: 0,
+ maxValue: 1
+ }]
+ }
+
+ constructor (options) {
+ // We don't need to look at options: only AudioParams are initialized,
+ // which were taken care of by the node.
+ super(options);
+ this.phase = 0;
+ this.lastSampleValue = 0;
+ }
+
+ process (inputs, outputs, parameters) {
+ var input = inputs[0];
+ var output = outputs[0];
+ var bitDepth = parameters.bitDepth;
+ var frequencyReduction = parameters.frequencyReduction;
+
+ for (var channel = 0; channel < output.length; ++channel) {
+ for (var i = 0; i < output[channel].length; ++i) {
+ let step = Math.pow(1 / 2, bitDepth[i]);
+ this.phase += frequencyReduction[i];
+ if (this.phase >= 1.0) {
+ this.phase -= 1.0;
+ this.lastSampleValue =
+ step * Math.floor(input[channel][i] / step + 0.5);
+ }
+ output[channel][i] = this.lastSampleValue;
+ }
+ }
+ }
+
+});
+
+
+ VU Meter Node
+
+
+ Global Scope: vumeternode.js
+
+
+class VUMeterNode extends AudioWorkletNode {
+
+ constructor (context, options) {
+
+ // Defaulting from AudioNodeOptions
+ options.numberOfInputs = 1;
+ options.numberOfOutputs = 0;
+ options.channelCount = 1;
+
+ options.updatingInterval = options.hasOwnProperty('updatingInterval')
+ ? options.updatingInterval
+ : 100;
+
+ super(context, 'VUMeter', options);
+
+ // Mirrored states of AudioWorkletProcessor.
+ this.updatingInterval = options.updatingInterval;
+ this.volume = 0;
+ }
+
+ get updatingInterval() {
+ return this.updatingInterval;
+ }
+
+ set updatingInterval (intervalValue) {
+ this.updatingInterval = intervalValue;
+ this.postMessage({ updatingInterval: intervalValue });
+ }
+
+ draw () {
+ /** Draw the meter based on the volume value. **/
+ }
+
+ // handle updated values from audio side
+ onmessage (event) {
+ if (event.data.hasOwnProperty('volume'))
+ this.volume = event.data.volume;
+ }
+}
+
+var importAudioWorkletNode = window.audioWorklet.import('vumeterprocessor.js');
+
+
+ AudioWorkletGlobalScope: vumeterprocessor.js
+
+
+var VU_METER_SMOOTHING = 0.9;
+
+registerAudioWorkletProcessor('VUMeter', class extends AudioWorkletProcessor {
+
+ // Note: AudioParam definition can be omitted.
+
+ constructor (options) {
+ super(options);
+
+ this.volume = 0;
+ this.updatingInterval = options.updatingInterval;
+ this.nextUpdateFrames = this.interval;
+ }
+
+ get interval () {
+ return this.updatingInterval / 1000 * this.contextInfo.sampleRate;
+ }
+
+ process (inputs, outputs, parameters) {
+ // Note that the input will be downmixed to mono.
+ var buffer = inputs[0][0];
+ var bufferLength = buffer.length;
+ var sum = 0, x = 0, rms = 0;
+
+ // Calculated the squared-sum.
+ for (var i = 0; i < bufferLength; ++i) {
+ x = buffer[i];
+ sum += x * x;
+ }
+
+ // Caluclate the RMS level and update the volume.
+ rms = Math.sqrt(sum / bufferLength);
+ this.volume = Math.max(rms, this.volume * VU_METER_SMOOTHING);
+
+ // Update and sync the volume property with the main thread.
+ this.nextUpdateFrame -= bufferLength;
+ if (this.nextUpdateFrame < 0) {
+ this.nextUpdateFrame += this.interval;
+ this.postMessage({ volume: this.volume });
+ }
+ }
+
+ onmessage (event) {
+ if (event.data.hasOwnProperty('updatingInterval'))
+ this.updatingInterval = event.data.updatingInterval;
+ }
+});
+
+
+ Main HTML file
+
+
+<script src="vumeternode.js"></script>
+<script>
+ importAudioWorkletNode.then(function () {
+ var context = new AudioContext();
+ var microphone = GET_MIRCOPHONE(); // e.g) a live input from getUserMedia().
+ var vuMeterNode = new VUMeterNode(context, { updatingInterval: 50 });
+
+ microphone.connnect(vuMeterNode);
+ requestAnimationFrame(function () {
+ vuMeterNode.draw();
+ });
+ });
+</script>
+
+
The ScriptProcessorNode Interface - DEPRECATED
From 77015588ff33dbedb1c6e448b53467725f5d157b Mon Sep 17 00:00:00 2001
From: Hongchan Choi
The AudioWorklet interface
AudioWorklet
object allows importing user-supplied
+ Javascript code that runs on the audio rendering thread. This
+ processing mechanism ensures the synchronous execution of the script code
+ with other built-in AudioNode
s in the audio graph.
+ AudioWorklet
object stores the definitions of a
+ custom audio processor and an AudioWorkletNode
object can
+ be constructed based on the processor definition. Note that the
+ registered definition in an AudioWorklet is valid for the entire
+ global scope (i.e. window
), therefore any
+ AudioContext
instance in the same global scope can
+ access the registered definition to create a custom node.
+ AudioWorkletGlobalScope
, an instance of
+ AudioWorkletNode
can be created in the main global
+ scope. At the same time, the user agent automatically creates an
+ instance of AudioWorkletProcessor
. This
+ counterpart represents an audio processing module that runs on the
+ audio rendering thread. These two components can communicate
+ via message passing.
-
-
+
+
Construction Procedure of AudioWorkletNode and AudioWorkletProcessor
-
AudioWokletNode
and
+ the corresponding AudioWorkletProcessor
object
+ consists of several coordinated interactions and the following
+ algorithm specifies the procedure. Note that these steps must be
+ performed in an atomic fashion.
window
scope: An
+ AudioWorkletNode
constructor starts with
+ arguments of AudioContext
and the
+ option
object.
AudioWorkletGlobalScope
: Locate a
+ registered AudioWorkletProcessor
subclass based
+ on the name argument. If none is found, or if subclass does not
+ extend AudioWorkletProcessor
, an
+ InvalidAccessError exception MUST be thrown by the corresponding
+ AudioWorkletNode
constructor.
-
AudioWorkletProcessor
subclass starts,
+ passing a structured clone of the options
object
+ that was provided to AudioWorkletNode
.
AudioWorkletProcessor
starts.
AudioWorkletProcessor
constructor
+ ends, return to the AudioWorkletNode
's
+ constructor and perform the rest of construction process.
window
scope: Construct
+ AudioParam
objects in the node based on the
+ information from the processor's
+ parameterDescriptors
getter. Initialize
+ parameter values from the options
object where the keys
+ match names declared in descriptors.
The AudioWorkletNode interface
AudioNode
which lives on the main control
+ thread. The user can create an AudioWorkletNode
+ from an AudioContext
and such a node can be
+ connected with other built-in AudioNode
s to form
+ an audio graph.
onmessage
handler is called whenever the
+ associated AudioWorkletProcessor
posts a
+ message back to the main thread.
postMessage
may be called to send a message to the
+ corresponding AudioWorkletProcessor via the algorithm
+ defined by the specification.
- AudioWorkletNodeOptions
+ AudioWorkletNodeOptions
AudioWorkletNodeOptions
dictionary can be used
+ for the custom initialization of AudioNode
+ attributes in the AudioWorkletNode
+ constructor. Entries in this dictionary whose names correspond to
+ AudioParam
s in the class definition of an
+ AudioWorkletProcessor
are used to initialize
+ the parameter values upon the creation of a node.
The AudioWorkletGlobalScope interface
WorkletGlobalScope
and
+ represents a special execution context in which an audio processing
+ script is run. It is designed to enable the generation, processing,
+ and analysis of audio data directly using JavaScript in the audio
+ rendering thread. The user-supplied script code is evaluated
+ in this scope to define an
+ AudioWorkletProcessor
.
AudioWorkletGlobalScope
and the definition of
+ the class manifests the actual audio processing mechanism of a
+ custom audio node. AudioWorkletProcessor
can
+ only be instantiated by the construction of an
+ AudioWorkletNode
instance.
AudioContextInfo
+ object from the associated AudioContext.
onmessage
handler is called whenever the
+ AudioWorkletNode
posts a message back to the
+ corresponding processor object.
Float32Array
s. The top-
+ level Array is organized by input; each input may contain
+ multiple channels; each channel contains a
+ Float32Array
of sample data. The initial size of
+ the channel array will be determined by the number of channels
+ by the channelCount
property in the
+ AudioWorkletNodeOptions
object supplied to
+ the AudioWorkletNode
constructor. However,
+ the number of channels may be altered dynamically by the
+ number of channels in the incoming audio stream.
Float32Array
s. The top-
+ level Array is organized by output; each output may contain
+ multiple channels; each channel contains a
+ Float32Array
of sample data.
Float32Array
for each parameter that has been
+ registered to an AudioWorkletNode. As this is dynamic, this
+ cannot be captured in IDL. The length of this Float32Array
+ will correspond to the length of the channel data in the
+ input. The contents of this Float32Array
will be
+ the values calculated by the AudioParam automation at the
+ corresponding points in time.
AudioWorkletNode
, via the algorithm defined
+ by the Worker specification.
- AudioParamDescriptor
+ AudioParamDescriptor
AudioParamDescriptor
dictionary is used to
+ specify properties for an AudioParam
object
+ that is used in an AudioWorkletNode
.
minValue
and maxValue
, an
+ NotSupportedError exception MUST be thrown.
maxValue
.
minValue
.
- AudioContextInfo
+ AudioContextInfo
AudioContextInfo
dictionary contains the status
+ of the associated AudioContext
.
BaseAudioContext
's
+ currentTime
attribute that was most recently
+ observable in the control thread.
AudioContext
.
AudioWorklet Examples
-
The BitCrusher Node
@@ -5380,8 +5398,9 @@
stream is reduced - both by quantizing the value (simulating lower
bit-depth in integer-based audio), and by quantizing in time
(simulating a lower digital sample rate). This example shows how
- to use AudioParams (in this case, treated as
- a-rate) inside an AudioWorkletProcessor.
+ to use
AudioParam
s (in this case, treated as
+ a-rate) inside an
+ AudioWorkletProcessor
.
This example demonstrates a simple sound level meter. It shows how
to exchange states (that do not require sample-accurate
- scheduling) between AudioWorkletNode and
- AudioWorkletProcessor. This node does not use any output.
+ scheduling) between AudioWorkletNode
and
+ AudioWorkletProcessor
. This node does not use
+ any output.
- Bitcrushing is a mechanism by which the audio quality of an audio
- stream is reduced - both by quantizing the value (simulating lower
- bit-depth in integer-based audio), and by quantizing in time
- (simulating a lower digital sample rate). This example shows how
- to use AudioParam
s (in this case, treated as
+ Bitcrushing is a mechanism by which the quality of an audio stream
+ is reduced both by quantizing the sample value (simulating lower
+ bit-depth), and by quantizing in time resolution (simulating a
+ lower sample rate). This example shows how to use
+ AudioParam
s (in this case, treated as
a-rate) inside an
AudioWorkletProcessor
.
The AudioWorklet
object allows importing user-supplied
Javascript code that runs on the audio rendering thread. This
- processing mechanism ensures the synchronous execution of the script code
- with other built-in AudioNode
s in the audio graph.
+ processing mechanism ensures the synchronous execution of the script
+ code with other built-in AudioNode
s in the audio graph.
The AudioWorklet
object stores the definitions of a
- custom audio processor and an AudioWorkletNode
object can
- be constructed based on the processor definition. Note that the
+ custom audio processor and an AudioWorkletNode
object
+ can be constructed based on the processor definition. Note that the
registered definition in an AudioWorklet is valid for the entire
global scope (i.e. window
), therefore any
- AudioContext
instance in the same global scope can
- access the registered definition to create a custom node.
+ AudioContext
instance in the same global scope
+ can access the registered definition to create a custom node.
After importing a module script into the
AudioWorkletGlobalScope
, an instance of
- AudioWorkletNode
can be created in the main global
- scope. At the same time, the user agent automatically creates an
- instance of AudioWorkletProcessor
. This
+ AudioWorkletNode
can be created in the main
+ global scope. At the same time, the user agent automatically creates
+ an instance of AudioWorkletProcessor
. This
counterpart represents an audio processing module that runs on the
audio rendering thread. These two components can communicate
via message passing.
@@ -5049,9 +5049,10 @@
AudioWorkletProcessor
constructor
- ends, return to the AudioWorkletNode
's
- constructor and perform the rest of construction process.
+ AudioWorkletProcessor
+ constructor ends, return to the
+ AudioWorkletNode
's constructor and perform
+ the rest of construction process.
AudioParam
objects in the node based on the
information from the processor's
parameterDescriptors
getter. Initialize
- parameter values from the options
object where the keys
- match names declared in descriptors.
+ parameter values from the options
object where the
+ keys match names declared in descriptors.
AudioNode
which lives on the main control
thread. The user can create an AudioWorkletNode
from an AudioContext
and such a node can be
- connected with other built-in AudioNode
s to form
- an audio graph.
+ connected with other built-in AudioNode
s to
+ form an audio graph.
AudioWorkletProcessor
.
-
The onmessage
handler is called whenever the
- AudioWorkletNode
posts a message back to the
- corresponding processor object.
+ AudioWorkletNode
posts a message back to
+ the corresponding processor object.
Float32Array
s. The top-
level Array is organized by input; each input may contain
multiple channels; each channel contains a
- Float32Array
of sample data. The initial size of
- the channel array will be determined by the number of channels
- by the channelCount
property in the
- AudioWorkletNodeOptions
object supplied to
- the AudioWorkletNode
constructor. However,
- the number of channels may be altered dynamically by the
- number of channels in the incoming audio stream.
+ Float32Array
of sample data. The initial size
+ of the channel array will be determined by the number of
+ channels by the channelCount
property in
+ the AudioWorkletNodeOptions
object
+ supplied to the AudioWorkletNode
+ constructor. However, the number of channels may be altered
+ dynamically by the number of channels in the incoming audio
+ stream.
Float32Array
for each parameter that has been
- registered to an AudioWorkletNode. As this is dynamic, this
- cannot be captured in IDL. The length of this Float32Array
- will correspond to the length of the channel data in the
- input. The contents of this Float32Array
will be
- the values calculated by the AudioParam automation at the
+ This object attribute exposes a correspondingly-named
+ readonly Float32Array
for each parameter that
+ has been registered to an AudioWorkletNode. As this is
+ dynamic, this cannot be captured in IDL. The length of this
+ Float32Array
will correspond to the length of
+ the channel data in the input. The contents of this
+ Float32Array
will be the values calculated by
+ the AudioParam
automation at the
corresponding points in time.
BaseAudioContext
's
- currentTime
attribute that was most recently
- observable in the control thread.
+ response to this event. By definition this will be equal to
+ the value of BaseAudioContext
's
+ currentTime
attribute that was most
+ recently observable in the control thread.
- Bitcrushing is a mechanism by which the quality of an audio stream
- is reduced both by quantizing the sample value (simulating lower
- bit-depth), and by quantizing in time resolution (simulating a
- lower sample rate). This example shows how to use
- AudioParam
s (in this case, treated as
- a-rate) inside an
+ Bitcrushing is a mechanism by which the quality of an audio
+ stream is reduced both by quantizing the sample value
+ (simulating a lower bit-depth), and by quantizing in time
+ resolution (simulating a lower sample rate). This example shows
+ how to use AudioParam
s (in this case,
+ treated as a-rate) inside an
AudioWorkletProcessor
.
- This example demonstrates a simple sound level meter. It shows how
- to exchange states (that do not require sample-accurate
+ This example demonstrates a simple sound level meter. It shows
+ how to exchange states (that do not require sample-accurate
scheduling) between AudioWorkletNode
and
- AudioWorkletProcessor
. This node does not use
- any output.
+ AudioWorkletProcessor
. This node does not
+ use any output.
AudioWorkletNode
constructor.
AudioWorkletProcessor
subclass starts,
- passing a structured clone of the options
object
- that was provided to AudioWorkletNode
.
+ AudioWorkletProcessor
subclass starts,
+ passing a structured clone of the options
object
+ that was provided to AudioWorkletNode
.
AudioWorkletProcessor
starts.
+ AudioWorkletProcessor
starts.
AudioWorkletProcessor
- constructor ends, return to the
- AudioWorkletNode
's constructor and perform
- the rest of construction process.
+ constructor ends, return to the
+ AudioWorkletNode
's constructor and perform
+ the rest of construction process.
Float32Array
s. The top-
level Array is organized by input; each input may contain
multiple channels; each channel contains a
- Float32Array
of sample data. The initial size
- of the channel array will be determined by the number of
+ Float32Array
of sample data. The initial size of
+ the channel array will be determined by the number of
channels by the channelCount
property in
the AudioWorkletNodeOptions
object
supplied to the AudioWorkletNode
@@ -5371,8 +5371,8 @@ BaseAudioContext
's
+ response to this event. By definition this will be equal to the
+ value of BaseAudioContext
's
currentTime
attribute that was most
recently observable in the control thread.
Bitcrushing is a mechanism by which the quality of an audio
- stream is reduced both by quantizing the sample value
- (simulating a lower bit-depth), and by quantizing in time
- resolution (simulating a lower sample rate). This example shows
- how to use AudioParam
s (in this case,
- treated as a-rate) inside an
+ stream is reduced both by quantizing the sample value (simulating
+ a lower bit-depth), and by quantizing in time resolution
+ (simulating a lower sample rate). This example shows how to use
+ AudioParam
s (in this case, treated as
+ a-rate) inside an
AudioWorkletProcessor
.
AudioWorkletNode
and
- AudioWorkletProcessor
. This node does not
- use any output.
+ AudioWorkletProcessor
. This node does not use
+ any output.
Float32Array
s. The top-
level Array is organized by input; each input may contain
multiple channels; each channel contains a
- Float32Array
of sample data. The initial size of
+ Float32Array
of sample data. The initial size of
the channel array will be determined by the number of
channels by the channelCount
property in
the AudioWorkletNodeOptions
object
From 721064f2eecffdd1ef883faa08f63561b26fb9e9 Mon Sep 17 00:00:00 2001
From: Hongchan Choi
- Imports a module script and returns a promise when fully loaded.
+ Imports a module script at moduleURL
. The returned
+ promise is resolved when the code is successfully imported and
+ parsed. It is rejected when the code contains an syntax error,
+ the file is not found at the specificied location or there is a
+ name conflict between registered
+ AudioWorkletProcessor
definitions.
- The construction procedure of AudioWokletNode
and
- the corresponding AudioWorkletProcessor
object
- consists of several coordinated interactions and the following
- algorithm specifies the procedure. Note that these steps must be
- performed in an atomic fashion.
-
window
scope: An
- AudioWorkletNode
constructor starts with
- arguments of AudioContext
and the
- option
object.
- AudioWorkletGlobalScope
: Locate a
- registered AudioWorkletProcessor
subclass based
- on the name argument. If none is found, or if subclass does not
- extend AudioWorkletProcessor
, an
- InvalidAccessError exception MUST be thrown by the corresponding
- AudioWorkletNode
constructor.
- AudioWorkletProcessor
subclass starts,
- passing a structured clone of the options
object
- that was provided to AudioWorkletNode
.
- AudioWorkletProcessor
starts.
- AudioWorkletProcessor
- constructor ends, return to the
- AudioWorkletNode
's constructor and perform
- the rest of construction process.
- window
scope: Construct
- AudioParam
objects in the node based on the
- information from the processor's
- parameterDescriptors
getter. Initialize
- parameter values from the options
object where the
- keys match names declared in descriptors.
- AudioNode
s to
form an audio graph.
-
+ The construction procedure of
+ AudioWokletNode
and the corresponding
+ AudioWorkletProcessor
object consists of
+ several coordinated interactions.
+
+ The following algorithm specifies the steps when the
+ AudioWorkletNode
constructor invoked with
+ the parameters. This sequence must be performed by the user
+ agent atomically.
+
AudioWorkletGlobalScope
: Locate
+ a definition of AudioWorkletProcessor
+ subclass that is registered under the name
+ argument. If none is found, an InvalidAccessError exception
+ MUST be thrown by the AudioWorkletNode
+ constructor.
+ AudioWorkletProcessor
+ constructor, passing a structured clone of the
+ options
argument that was provided to
+ AudioWorkletNode
.
+ AudioWorkletProcessor
subclass.
+ AudioWorkletProcessor
subclass.
+ window
scope: Construct
+ AudioParam
objects based on the
+ information from the processor's
+ parameterDescriptors
.
+ options
object where the keys match names
+ declared in descriptors.
+ AudioNode
.
AudioNode
.
AudioNode
.
channelCountMode
attribute of an
+ AudioWorkletNode
This interface is derived from WorkletGlobalScope
and
represents a special execution context in which an audio processing
- script is run. It is designed to enable the generation, processing,
+ script runs. It is designed to enable the generation, processing,
and analysis of audio data directly using JavaScript in the audio
rendering thread. The user-supplied script code is evaluated
in this scope to define an
@@ -5212,14 +5219,16 @@
- This array contains AudioParamDescriptors, which are - descriptors for each controllable parameter on an - AudioNode. This static property is referenced in the - construction of an AudioWorkletNode to create instances - of an AudioParam in the node. + This getter returns an array contains + AudioParamDescriptors, which are descriptors for each + controllable parameter on an AudioNode. This static + property is referenced in the construction of an + AudioWorkletNode to create instances of an + AudioParam in the node.
Float32Array
s. The top-
- level Array is organized by input; each input may contain
- multiple channels; each channel contains a
- Float32Array
of sample data. The initial size of
- the channel array will be determined by the number of
- channels by the channelCount
property in
- the AudioWorkletNodeOptions
object
- supplied to the AudioWorkletNode
- constructor. However, the number of channels may be altered
- dynamically by the number of channels in the incoming audio
- stream.
+ inputs[n][m]
is a Float32Array
of
+ audio samples for m
th channel of
+ n
th input. While the number of inputs is fixed
+ at the construction, the number of channels can be changed
+ dynamically.
Float32Array
s. The top-
- level Array is organized by output; each output may contain
- multiple channels; each channel contains a
- Float32Array
of sample data.
+ outputs[n][m]
is a Float32Array object for
+ m
th channel of n
th output.
Float32Array
for each parameter that
- has been registered to an AudioWorkletNode. As this is
- dynamic, this cannot be captured in IDL. The length of this
- Float32Array
will correspond to the length of
- the channel data in the input. The contents of this
- Float32Array
will be the values calculated by
- the AudioParam
automation at the
- corresponding points in time.
+ Provides an association between the names of an
+ AudioParam
s specified by the
+ AudioParamDescriptor
s during construction
+ and the automation values for the
+ AudioParam
. Thus,
+ parameters[name]
returns a
+ Float32Array
of the automation values
+ corresponding to the AudioParam
named
+ "name"
.
- The construction procedure of
- AudioWokletNode
and the corresponding
+ The construction procedure of an
+ AudioWorkletNode
and the corresponding
AudioWorkletProcessor
object consists of
- several coordinated interactions.
-
- The following algorithm specifies the steps when the
+ several coordinated interactions. The following algorithm
+ specifies the steps when the
AudioWorkletNode
constructor invoked with
the parameters. This sequence must be performed by the user
agent atomically.
@@ -5060,7 +5058,7 @@
AudioWorkletProcessor
constructor, passing a structured clone of the
- options
argument that was provided to
+ options
parameter that was provided to
AudioWorkletNode
.
parameterDescriptors
.
options
object where the keys match names
- declared in descriptors.
+ option
parameter. Find
+ the key matches the name of AudioParam object and assign
+ the value to it.
postMessage
may be called to send a message to the
corresponding AudioWorkletProcessor via the algorithm
- defined by the specification.
+ defined by the [!Worker] specification.
Imports a module script at moduleURL
. The returned
promise is resolved when the code is successfully imported and
- parsed. It is rejected when the code contains an syntax error,
- the file is not found at the specificied location or there is a
- name conflict between registered
+ parsed. It is rejected when the code contains a syntax error, the
+ file is not found at the specified location, or there is a name
+ conflict between registered
AudioWorkletProcessor
definitions.
AudioWorkletNode
and the corresponding
AudioWorkletProcessor
object consists of
several coordinated interactions. The following algorithm
- specifies the steps when the
- AudioWorkletNode
constructor invoked with
- the parameters. This sequence must be performed by the user
- agent atomically.
+ specifies the steps in constructing an
+ AudioWorkletNode
with the given parameters.
+ This sequence must be performed by the user agent atomically.
option
parameter. Find
- the key matches the name of AudioParam object and assign
- the value to it.
+ the key that matches the name of AudioParam object and
+ assign the value to it.
- This getter returns an array contains + This getter returns an array containing AudioParamDescriptors, which are descriptors for each controllable parameter on an AudioNode. This static - property is referenced in the construction of an + property is referenced in the construction on an AudioWorkletNode to create instances of an AudioParam in the node.
@@ -5260,7 +5260,7 @@inputs[n][m]
is a Float32Array
of
- audio samples for m
th channel of
+ audio samples for the m
th channel of
n
th input. While the number of inputs is fixed
at the construction, the number of channels can be changed
dynamically.
@@ -5269,14 +5269,15 @@ outputs[n][m]
is a Float32Array object for
- m
th channel of n
th output.
+ outputs[n][m]
is a Float32Array object
+ containing the audio samples for m
th channel of
+ n
th output.
AudioParam
s specified by the
AudioParamDescriptor
s during construction
and the automation values for the
From b90832134ec0ca31b591dc5af332a76912a799de Mon Sep 17 00:00:00 2001
From: Hongchan Choi
- The AudioWorklet
object allows importing user-supplied
- Javascript code that runs on the audio rendering thread. This
- processing mechanism ensures the synchronous execution of the script
- code with other built-in AudioNode
s in the audio graph.
+ The AudioWorklet
object allows developers to supply
+ Javascript to process audio on the rendering thread,
+ supporting custom AudioNodes. This processing mechanism ensures the
+ synchronous execution of the script code with other built-in
+ AudioNode
s in the audio graph.
- The AudioWorklet
object stores the definitions of a
- custom audio processor and an AudioWorkletNode
object
- can be constructed based on the processor definition. Note that the
- registered definition in an AudioWorklet is valid for the entire
- global scope (i.e. window
), therefore any
- AudioContext
instance in the same global scope
- can access the registered definition to create a custom node.
+ The AudioWorklet
object stores the definitions of custom
+ audio processors and AudioWorkletNode
s can be
+ constructed based on these definitions. The registered definition in
+ an AudioWorklet is valid for the entire global scope (i.e.
+ window
), therefore any AudioContext
+ instance in the same global scope can access the registered
+ definition to create a custom node.
After importing a module script into the
AudioWorkletGlobalScope
, an instance of
AudioWorkletNode
can be created in the main
- global scope. At the same time, the user agent automatically creates
- an instance of AudioWorkletProcessor
. This
- counterpart represents an audio processing module that runs on the
- audio rendering thread. These two components can communicate
- via message passing.
+ global scope, based on any of the definitions in the script. At the
+ same time, the user agent automatically creates an instance of
+ AudioWorkletProcessor
. This counterpart
+ represents an audio processing module that runs on the audio
+ rendering thread. These two components can communicate via
+ message passing.
Imports a module script at moduleURL
. The returned
promise is resolved when the code is successfully imported and
- parsed. It is rejected when the code contains a syntax error, the
- file is not found at the specified location, or there is a name
- conflict between registered
- AudioWorkletProcessor
definitions.
+ parsed. It is rejected if any uncaught exception occurs during
+ the execution of the imported script.
options
parameter that was provided to
AudioWorkletNode
.
AudioWorkletProcessor
subclass.
- AudioWorkletProcessor
subclass.
+ AudioWorkletProcessor
subclass. In this
+ constructor, The options
parameter can be used
+ to initialize the state of the processor.
option
parameter. Find
the key that matches the name of AudioParam object and
- assign the value to it.
+ assign the value to it. Any key does not match the name of
+ AudioParam
object and anything other
+ than Number
for the value are ignored.
AudioWorkletProcessor
during construction
+ of an AudioWorkletNode
. Throws an
+ exception if another
+ AudioWorkletProcessor
has already
+ registered this key.
AudioWorkletProcessor
.
This getter returns an AudioContextInfo
- object from the associated AudioContext.
+ object that describes the associated AudioContext.
AudioParamDescriptor
s during construction
and the automation values for the
AudioParam
. Thus,
- parameters[name]
returns a
+ parameters["name"]
returns a
Float32Array
of the automation values
corresponding to the AudioParam
named
"name"
.
@@ -5360,8 +5368,9 @@
- The AudioContextInfo
dictionary contains the status
- of the associated AudioContext
.
+ The AudioContextInfo
dictionary provides an
+ AudioWorkletGlobalScope
with a view of an
+ AudioContext
.
- This example demonstrates a simple sound level meter. It shows
- how to exchange states (that do not require sample-accurate
- scheduling) between AudioWorkletNode
and
- AudioWorkletProcessor
. This node does not use
- any output.
+ This example of a simple sound level meter further illustrates
+ how to create an AudioWorkletNode
subclass
+ that acts like a native AudioNode
, accepting
+ constructor options and encapsulating the inter-thread
+ communication (asynchronous) between
+ AudioWorkletNode
and
+ AudioWorkletProcessor
in clean method calls
+ and attribute accesses. This node does not use any output.
- Imports a module script at moduleURL
. The returned
- promise is resolved when the code is successfully imported and
- parsed. It is rejected if any uncaught exception occurs during
- the execution of the imported script.
+ Imports a module script at moduleURL
, similar to the
+ algorithm defined by [[!worklets-1]].
This interface represents a user-defined
- AudioNode
which lives on the main control
+ AudioNode
which lives on the control
thread. The user can create an AudioWorkletNode
from an AudioContext
and such a node can be
connected with other built-in AudioNode
s to
@@ -5042,7 +5040,7 @@
AudioWorkletNode
and the corresponding
AudioWorkletProcessor
object consists of
several coordinated interactions. The following algorithm
- specifies the steps in constructing an
+ specifies the steps for constructing an
AudioWorkletNode
with the given parameters.
This sequence must be performed by the user agent atomically.
@@ -5052,9 +5050,9 @@ AudioWorkletGlobalScope
: Locate
a definition of AudioWorkletProcessor
subclass that is registered under the name
- argument. If none is found, an InvalidAccessError exception
- MUST be thrown by the AudioWorkletNode
- constructor.
+ argument. If none is found, an
+ InvalidAccessError
exception MUST be thrown by
+ the AudioWorkletNode
constructor.
AudioWorkletProcessor
constructor, passing a structured clone of the
@@ -5062,24 +5060,26 @@ AudioWorkletNode
.
AudioWorkletProcessor
subclass. In this
- constructor, The options
parameter can be used
- to initialize the state of the processor.
+ AudioWorkletProcessor
subclass. The
+ constructor uses the options
parameter to
+ initialize this AudioWorkletProcessor
+ instance.
window
scope: Construct
+ In the global scope: Construct
AudioParam
objects based on the
information from the processor's
parameterDescriptors
.
option
parameter. Find
- the key that matches the name of AudioParam object and
- assign the value to it. Any key does not match the name of
- AudioParam
object and anything other
- than Number
for the value are ignored.
+ AudioParam
+ objects with key-value pairs in the option
+ parameter. Find the key that matches the name of AudioParam
+ object and assign the value to it. Any key does not match
+ the name of AudioParam
object and
+ anything other than Number
for the value are
+ ignored.
- This interface represents an audio processing module that runs on
- the audio rendering thread. It is defined in an
+ This interface represents an audio processing code that runs on the
+ audio rendering thread. It lives in an
AudioWorkletGlobalScope
and the definition of
the class manifests the actual audio processing mechanism of a
custom audio node. AudioWorkletProcessor
can
@@ -5229,8 +5229,8 @@
This getter returns an array containing
AudioParamDescriptors, which are descriptors for each
- controllable parameter on an AudioNode. This static
- property is referenced in the construction on an
+ AudioParam
on an AudioNode. This
+ static property is referenced in the construction on an
AudioWorkletNode to create instances of an
AudioParam in the node.
- This method gets executed isochronously by the audio - rendering thread. + This method is called synchronously by the audio rendering + thread that executes in an isochronous fashion.
It may be called to send a message to the
- AudioWorkletNode
, via the algorithm defined
- by the Worker specification.
+ AudioWorkletNode
.
NotSupportedError
exception MUST be thrown when a
+ duplicated name is found when registering the class definition.
minValue
and maxValue
, an
- NotSupportedError exception MUST be thrown.
+ NotSupportedError
exception MUST be thrown.
maxValue
.
+ Represents the minimum value. An NotSupportedError
+ exception MUST be thrown if this value is out of range of float
+ data type or it is greater than maxValue
.
minValue
.
+ Represents the maximum value. An NotSupportedError
+ exception MUST be thrown if this value is out of range of float
+ data type or it is smaller than minValue
.
BaseAudioContext
's
+ The context time of the block of audio being processed. By
+ definition this will be equal to the value of
+ BaseAudioContext
's
currentTime
attribute that was most
recently observable in the control thread.
AudioContext
.
+ BaseAudioContext
.
postMessage
may be called to send a message to the
- corresponding AudioWorkletProcessor via the algorithm
- defined by the [!Worker] specification.
+ corresponding AudioWorkletProcessor.
@@ -5333,12 +5332,14 @@
+ Processes the audio data from the input and produce the content + of output buffer by executing the user-supplied script code. This method is called synchronously by the audio rendering thread that executes in an isochronous fashion.
inputs[n][m]
is a Float32Array
of
@@ -5348,7 +5349,7 @@ outputs[n][m]
is a Float32Array object
@@ -5385,7 +5386,7 @@