From d0181c16e5b5e1421c4845635597406dd65bddfe Mon Sep 17 00:00:00 2001 From: Hongchan Choi Date: Wed, 29 Jun 2016 08:51:21 -0700 Subject: [PATCH 01/13] initial commit --- index.html | 615 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 615 insertions(+) diff --git a/index.html b/index.html index 8e16493a2..3129f9ef6 100644 --- a/index.html +++ b/index.html @@ -4975,6 +4975,621 @@
+
+

+ The AudioWorklet interface +

+

+ 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. +

+
+
+ Promise<void> import(DOMString moduleUrl) +
+
+

+ Imports a module script returns a promise once it is fully loaded. +

+
+
+ +

+ Construction Procedure of AudioWorkletNode and AudioWorkletProcessor +

+

+ 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. +

+
    +
  1. + In the window scope: Start AudioWorkletNode constructor. +
  2. +
  3. + In the AudioWorkletGlobalScope: Locate a registered + AudioWorkletProcessor subclass based on name argument. If none is + found, or if subclass does not extend AudioWorkletProcessor, throw + an exception from the node constructor. +
      +
    1. + Start registered constructor for custom processor subclass, + passing structured clone of the options object that was provided + to AudioWorkletNode. +
    2. +
    3. + Start super constructor for AudioWorkletProcessor. +
    4. +
    5. + Initialize the processor’s states. +
    6. +
    7. + End the construction of an AudioWorkletProcessor and return to + AudioWorkletNode constructor. +
    8. +
    +
  4. +
  5. + In the window scope: Construct AudioParam objects in the node + based on the information from the processor’s + parameterDescriptors getter and initialize parameter values from + options where the keys match names declared in + AudioParamDescriptors. +
  6. +
  7. + In the window scope: Return from the AudioWorkletNode + constructor. +
  8. +
+
+

+ The AudioWorkletNode interface +

+

+ 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. +

+
+
+ attribute EventHandler onmessage +
+
+

+ The onmessage handler is called whenever the associated + AudioWorkletProcessor posts a message back to the main + thread. +

+
+
+ void postMessage(any message, optional sequence<Transferable> + transfer) +
+
+

+ postMessage May be called to send a message to the corresponding + AudioWorkletProcessor via the algorithm defined by the + Worker specification. +

+
+
+ +
+

+ AudioWorkletNodeOptions +

+

+ 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. +

+
+
+ unsigned long numberOfInputs +
+
+ Similar to numberOfInputs in AudioNode. +
+
+ unsigned long numberOfOutputs +
+
+ Similar to numberOfOutputs in AudioNode. +
+
+ unsigned long channelCount +
+
+ Similar to channelCount in AudioNode. +
+
+ ChannelCountMode channelCountMode +
+
+ Similar to channelCountMode in AudioNode. +
+
+ ChannelInterpretation channelInterpretation +
+
+ Similar to channelInterpretation in AudioNode. +
+
+
+
+
+

+ The AudioWorkletGlobalScope interface +

+

+ 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. +

+
+
+ void registerAudioWorkletProcessor (DOMString name, Function classConstructor) +
+
+

+ Registers a definition of a class that is derived from + AudioWorkletProcessor. +

+
+
+ DOMString name +
+
+ A string key that represents a class definition to be + registered. ISSUE: The conflict between + multiple class definitions under the same name needs to be + addressed. For the time being, WG’s resolution is to apply the + first-come-first- served policy. +
+
+ Function classConstructor +
+
+ A class definition extended from AudioWorkletProcessor. +
+
+
+
+
+
+

+ The AudioWorkletProcessor interface +

+

+ 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. +

+
+
+ readonly attribute static sequence<AudioParamDescriptor> +
+
+

+ 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. +

+
+
+ readonly attribute AudioContextInfo contextInfo +
+
+

+ This getter provides an object contains the information of the + associated AudioContext such as the sample rate and the + current playback time when queried. +

+
+
+ attribute EventHandler onmessage +
+
+

+ The onmessage handler is called whenever the + AudioWorkletNode posts a node message back to the + corresponding processor object on the audio rendering + thread. +

+
+
+ void process() +
+
+

+ This method gets executed isochronously by the audio rendering + thread along with the rest of an audio graph while the + associated AudioWorkletNode is connected. +

+
+
+ Float32Array[][] inputs +
+
+ Represents incoming data from inputs of the node. Each input + can contain multiple channels. +
+
+ Float32Array[][] outputs +
+
+ Represents outgoing data from outputs of the node. Each output + can contain multiple channels. +
+
+ Object parameters +
+
+ Represents an object contains multiple arrays of + AudioParam data with the associated name as a key. +
+
+
+
+ void postMessage() +
+
+

+ It may be called to send a message to the + AudioWorkletNode, via the algorithm defined by the + Worker specification. +

+
+
+ any message +
+
+
+
+ optional sequence<Transferable> transfer +
+
+
+
+
+
+
+

+ AudioParamDescriptor +

+

+ The AudioParamDescriptor dictionary is used to specify properties + for an AudioParam object that is used in an + AudioWorkletNode. +

+
+
+ DOMString name +
+
+ Represents the name of a parameter. An exception will be thrown + when the duplicated name is found when registering the class + definition. +
+
+ float defaultValue = 0 +
+
+ Represents the default value of the parameter. If this value is + out of the range of float data type or the range defined by + minValue and maxValue, an exception will be thrown. +
+
+ float minValue +
+
+ Represents the minimum value. An exception will be thrown, if + this value is out of range of float data type or it is greater + than maxValue. +
+
+ float maxValue +
+
+ Represents the maximum value. An exception will be thrown, if + this value is out of range of float data type or it is smaller + than minValue. +
+
+
+ +
+

+ AudioContextInfo +

+

+ The AudioContextInfo dictionary is used to query the current + status of the associated AudioContext within the scope of + an AudioWorkletProcessor. +

+
+
+ float playbackTime +
+
+ The starting time of the block of audio being processed in + 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. +
+
+ unsigned long sampleRate +
+
+ Represents the sample rate of the associated + AudioContext. +
+
+
+
+
+

+ AudioWorklet Examples +

+ +
+

+ The BitCrusher Node +

+

+ 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. +

+

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

+

+ 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. +

+

+ 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 Date: Wed, 29 Jun 2016 22:24:04 -0700 Subject: [PATCH 02/13] addressing feedback from rtoy --- index.html | 315 ++++++++++++++++++++++++++++------------------------- 1 file changed, 165 insertions(+), 150 deletions(-) diff --git a/index.html b/index.html index 3129f9ef6..a3491ddb4 100644 --- a/index.html +++ b/index.html @@ -4980,28 +4980,29 @@

The AudioWorklet interface

- 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 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 AudioNodes 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. +

+

+ 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.

@@ -5009,54 +5010,58 @@

- Imports a module script returns a promise once it is fully loaded. + Imports a module script and returns a promise when fully loaded.

- -

+

Construction Procedure of AudioWorkletNode and AudioWorkletProcessor -

+

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

  1. - In the window scope: Start AudioWorkletNode constructor. + In the window scope: An + AudioWorkletNode constructor starts with + arguments of AudioContext and the + option object.
  2. - In the AudioWorkletGlobalScope: Locate a registered - AudioWorkletProcessor subclass based on name argument. If none is - found, or if subclass does not extend AudioWorkletProcessor, throw - an exception from the node constructor. + In the 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.
      -
    1. - Start registered constructor for custom processor subclass, - passing structured clone of the options object that was provided - to AudioWorkletNode. +
    2. The constructor for the custom + AudioWorkletProcessor subclass starts, + passing a structured clone of the options object + that was provided to AudioWorkletNode.
    3. -
    4. - Start super constructor for AudioWorkletProcessor. +
    5. The super constructor for + AudioWorkletProcessor starts.
    6. -
    7. - Initialize the processor’s states. +
    8. The processor’s internal states are initialized.
    9. -
    10. - End the construction of an AudioWorkletProcessor and return to - AudioWorkletNode constructor. +
    11. When the AudioWorkletProcessor constructor + ends, return to the AudioWorkletNode's + constructor and perform the rest of construction process.
  3. - In the window scope: Construct AudioParam objects in the node - based on the information from the processor’s - parameterDescriptors getter and initialize parameter values from - options where the keys match names declared in - AudioParamDescriptors. + In the 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.
  4. In the window scope: Return from the AudioWorkletNode @@ -5068,79 +5073,82 @@

    The AudioWorkletNode interface

    - 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 + 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 AudioNodes to form + an audio graph.

    attribute EventHandler onmessage

    - The onmessage handler is called whenever the associated - AudioWorkletProcessor posts a message back to the main - thread. + The onmessage handler is called whenever the + associated AudioWorkletProcessor posts a + message back to the main thread.

    - void postMessage(any message, optional sequence<Transferable> - transfer) + void postMessage(any message, optional + sequence<Transferable> transfer)

    - postMessage May be called to send a message to the corresponding - AudioWorkletProcessor via the algorithm defined by the - Worker specification. + postMessage may be called to send a message to the + corresponding AudioWorkletProcessor via the algorithm + defined by the specification.

    - AudioWorkletNodeOptions + AudioWorkletNodeOptions

    - 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 AudioWorkletNodeOptions dictionary can be used + for the custom initialization of AudioNode + attributes in the AudioWorkletNode + constructor. Entries in this dictionary whose names correspond to + AudioParams in the class definition of an + AudioWorkletProcessor are used to initialize + the parameter values upon the creation of a node.

    unsigned long numberOfInputs
    - Similar to numberOfInputs in AudioNode. + Same to numberOfInputs in AudioNode.
    unsigned long numberOfOutputs
    - Similar to numberOfOutputs in AudioNode. + Same to numberOfOutputs in AudioNode.
    unsigned long channelCount
    - Similar to channelCount in AudioNode. + Same to channelCount in AudioNode.
    ChannelCountMode channelCountMode
    - Similar to channelCountMode in AudioNode. + Same to channelCountMode in AudioNode.
    ChannelInterpretation channelInterpretation
    - Similar to channelInterpretation in AudioNode. + Same to channelInterpretation in AudioNode.
    @@ -5150,18 +5158,19 @@

    The AudioWorkletGlobalScope interface

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

    - void registerAudioWorkletProcessor (DOMString name, Function classConstructor) + void registerAudioWorkletProcessor (DOMString name, Function + classConstructor)

    @@ -5174,10 +5183,7 @@

    A string key that represents a class definition to be - registered. ISSUE: The conflict between - multiple class definitions under the same name needs to be - addressed. For the time being, WG’s resolution is to apply the - first-come-first- served policy. + registered.
    Function classConstructor @@ -5196,11 +5202,11 @@

    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. + 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.

    @@ -5208,11 +5214,11 @@

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

    @@ -5220,9 +5226,8 @@

    - 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 AudioContextInfo + object from the associated AudioContext.

    @@ -5230,10 +5235,9 @@

    - The onmessage handler is called whenever the - AudioWorkletNode posts a node message back to the - corresponding processor object on the audio rendering - thread. + The onmessage handler is called whenever the + AudioWorkletNode posts a message back to the + corresponding processor object.

    @@ -5241,31 +5245,46 @@

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

    Float32Array[][] inputs
    - Represents incoming data from inputs of the node. Each input - can contain multiple channels. + An Array of Arrays of Float32Arrays. 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[][] outputs
    - Represents outgoing data from outputs of the node. Each output - can contain multiple channels. + An Array of Arrays of Float32Arrays. The top- + level Array is organized by output; each output may contain + multiple channels; each channel contains a + Float32Array of sample data.
    Object parameters
    - Represents an object contains multiple arrays of - AudioParam data with the associated name as a key. + 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.
    @@ -5275,8 +5294,8 @@

    It may be called to send a message to the - AudioWorkletNode, via the algorithm defined by the - Worker specification. + AudioWorkletNode, via the algorithm defined + by the Worker specification.

    @@ -5294,21 +5313,21 @@

    - AudioParamDescriptor + AudioParamDescriptor

    - The AudioParamDescriptor dictionary is used to specify properties - for an AudioParam object that is used in an - AudioWorkletNode. + The AudioParamDescriptor dictionary is used to + specify properties for an AudioParam object + that is used in an AudioWorkletNode.

    DOMString name
    - Represents the name of a parameter. An exception will be thrown - when the duplicated name is found when registering the class - definition. + Represents the name of a parameter. An NotSupportedError + exception MUST be thrown when a duplicated name is found when + registering the class definition.
    float defaultValue = 0 @@ -5316,52 +5335,52 @@

    Represents the default value of the parameter. If this value is out of the range of float data type or the range defined by - minValue and maxValue, an exception will be thrown. + minValue and maxValue, an + NotSupportedError exception MUST be thrown.
    float minValue
    - Represents the minimum value. An exception will be thrown, if - this value is out of range of float data type or it is greater - than 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.
    float maxValue
    - Represents the maximum value. An exception will be thrown, if - this value is out of range of float data type or it is smaller - than 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.

    -

    - AudioContextInfo + AudioContextInfo

    - The AudioContextInfo dictionary is used to query the current - status of the associated AudioContext within the scope of - an AudioWorkletProcessor. + The AudioContextInfo dictionary contains the status + of the associated AudioContext.

    - float playbackTime + double playbackTime
    The starting time of the block of audio being processed in 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. + value of BaseAudioContext's + currentTime attribute that was most recently + observable in the control thread.
    - unsigned long sampleRate + float sampleRate
    Represents the sample rate of the associated - AudioContext. + AudioContext.
    @@ -5370,7 +5389,6 @@

    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 AudioParams (in this case, treated as + a-rate) inside an + AudioWorkletProcessor.

    Global Scope @@ -5463,8 +5482,9 @@

    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.

    Global Scope: vumeternode.js @@ -5584,12 +5604,7 @@

- - - - - - +

The ScriptProcessorNode Interface - DEPRECATED From fdd47784b129f134ff9fd11db521f8ee0dcc2554 Mon Sep 17 00:00:00 2001 From: Hongchan Choi Date: Wed, 29 Jun 2016 22:26:32 -0700 Subject: [PATCH 03/13] addressing feedback from rtoy --- index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index a3491ddb4..0ae94daa3 100644 --- a/index.html +++ b/index.html @@ -5394,11 +5394,11 @@

The BitCrusher Node

- 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 + 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 + AudioParams (in this case, treated as a-rate) inside an AudioWorkletProcessor.

From fff16a99640b1803d84f0bd6310f183d5e02ddbe Mon Sep 17 00:00:00 2001 From: Hongchan Choi Date: Wed, 29 Jun 2016 22:35:59 -0700 Subject: [PATCH 04/13] tidy fix --- index.html | 119 +++++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/index.html b/index.html index 0ae94daa3..07bff47b6 100644 --- a/index.html +++ b/index.html @@ -4982,24 +4982,24 @@

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 AudioNodes in the audio graph. + processing mechanism ensures the synchronous execution of the script + code with other built-in AudioNodes 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 @@

  • The processor’s internal states are initialized.
  • -
  • When the AudioWorkletProcessor constructor - ends, return to the AudioWorkletNode's - constructor and perform the rest of construction process. +
  • When the AudioWorkletProcessor + constructor ends, return to the + AudioWorkletNode's constructor and perform + the rest of construction process.
  • @@ -5060,8 +5061,8 @@

    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.
  • In the window scope: Return from the AudioWorkletNode @@ -5077,8 +5078,8 @@

    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 AudioNodes to form - an audio graph. + connected with other built-in AudioNodes to + form an audio graph.

    -

    AudioWorkletNodeOptions @@ -5166,7 +5166,7 @@

    in this scope to define an AudioWorkletProcessor.

    -
    void registerAudioWorkletProcessor (DOMString name, Function @@ -5189,7 +5189,8 @@

    Function classConstructor

    - A class definition extended from AudioWorkletProcessor. + A class definition extended from + AudioWorkletProcessor.
    @@ -5236,8 +5237,8 @@

    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.

    @@ -5256,13 +5257,14 @@

    An Array of Arrays of Float32Arrays. 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[][] outputs @@ -5277,13 +5279,14 @@

    Object parameters

    - 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 + 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.
    @@ -5301,13 +5304,11 @@

    any message
    -
    -
    +
    optional sequence<Transferable> transfer
    -
    -
    +
    @@ -5370,10 +5371,10 @@

    The starting time of the block of audio being processed in - 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. + 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.
    float sampleRate @@ -5394,12 +5395,12 @@

    The BitCrusher Node

    - 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 - AudioParams (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 AudioParams (in this case, + treated as a-rate) inside an AudioWorkletProcessor.

    @@ -5458,11 +5459,11 @@

    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) { + 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) { + if (this.phase >= 1.0) { this.phase -= 1.0; this.lastSampleValue = step * Math.floor(input[channel][i] / step + 0.5); @@ -5480,11 +5481,11 @@

    VU Meter Node

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

    Global Scope: vumeternode.js @@ -5561,7 +5562,7 @@

    var sum = 0, x = 0, rms = 0; // Calculated the squared-sum. - for (var i = 0; i < bufferLength; ++i) { + for (var i = 0; i < bufferLength; ++i) { x = buffer[i]; sum += x * x; } @@ -5572,7 +5573,7 @@

    // Update and sync the volume property with the main thread. this.nextUpdateFrame -= bufferLength; - if (this.nextUpdateFrame < 0) { + if (this.nextUpdateFrame < 0) { this.nextUpdateFrame += this.interval; this.postMessage({ volume: this.volume }); } @@ -5604,7 +5605,7 @@

  • - +

    The ScriptProcessorNode Interface - DEPRECATED From cc6beeb9e6dd45f739f46f673e90e5c47912266c Mon Sep 17 00:00:00 2001 From: Hongchan Choi Date: Wed, 29 Jun 2016 22:44:24 -0700 Subject: [PATCH 05/13] tidy fix again --- index.html | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/index.html b/index.html index 07bff47b6..c18e93c7d 100644 --- a/index.html +++ b/index.html @@ -5040,19 +5040,19 @@

    AudioWorkletNode constructor.
    1. The constructor for the custom - 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.
    2. The super constructor for - AudioWorkletProcessor starts. + AudioWorkletProcessor starts.
    3. The processor’s internal states are initialized.
    4. When the 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.
    @@ -5082,7 +5082,7 @@

    form an audio graph.

    attribute EventHandler onmessage @@ -5257,8 +5257,8 @@

    An Array of Arrays of Float32Arrays. 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 @@

    The starting time of the block of audio being processed in - response to this event. By definition this will be equal to - the value of 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.
    @@ -5396,11 +5396,11 @@

    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 AudioParams (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 + AudioParams (in this case, treated as + a-rate) inside an AudioWorkletProcessor.

    @@ -5484,8 +5484,8 @@

    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.

    Global Scope: vumeternode.js From afd34a4f84f50235e7813dab9307e87873c16c08 Mon Sep 17 00:00:00 2001 From: Hongchan Choi Date: Wed, 29 Jun 2016 22:49:39 -0700 Subject: [PATCH 06/13] tidy fix again... --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index c18e93c7d..68429d60c 100644 --- a/index.html +++ b/index.html @@ -5257,7 +5257,7 @@

    An Array of Arrays of Float32Arrays. 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 Date: Thu, 7 Jul 2016 11:02:44 -0700 Subject: [PATCH 07/13] addressing feedback from the first pass review --- index.html | 190 ++++++++++++++++++++++++++--------------------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/index.html b/index.html index 68429d60c..67d14a1b4 100644 --- a/index.html +++ b/index.html @@ -5010,65 +5010,18 @@

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

    Construction Procedure of AudioWorkletNode and AudioWorkletProcessor

    -

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

    -
      -
    1. - In the window scope: An - AudioWorkletNode constructor starts with - arguments of AudioContext and the - option object. -
    2. -
    3. - In the 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. -
        -
      1. The constructor for the custom - AudioWorkletProcessor subclass starts, - passing a structured clone of the options object - that was provided to AudioWorkletNode. -
      2. -
      3. The super constructor for - AudioWorkletProcessor starts. -
      4. -
      5. The processor’s internal states are initialized. -
      6. -
      7. When the AudioWorkletProcessor - constructor ends, return to the - AudioWorkletNode's constructor and perform - the rest of construction process. -
      8. -
      -
    4. -
    5. - In the 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. -
    6. -
    7. - In the window scope: Return from the AudioWorkletNode - constructor. -
    8. -

    The AudioWorkletNode interface @@ -5081,9 +5034,60 @@

    connected with other built-in AudioNodes to form an audio graph.

    -
    +
    +
    + Constructor(BaseAudioContext context, DOMString name, optional + AudioWorkletNodeOptions options) +
    +
    +

    + 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. +

    +
      +
    1. + In the 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. +
    2. +
    3. Run the AudioWorkletProcessor + constructor, passing a structured clone of the + options argument that was provided to + AudioWorkletNode. +
        +
      1. Run the super constructor of + AudioWorkletProcessor subclass. +
      2. +
      3. Run the constructor of the + AudioWorkletProcessor subclass. +
      4. +
      +
    4. +
    5. + In the window scope: Construct + AudioParam objects based on the + information from the processor's + parameterDescriptors. +
        +
      1. Initialize parameter values from the + options object where the keys match names + declared in descriptors. +
      2. +
      +
    6. +
    +
    attribute EventHandler onmessage
    @@ -5124,25 +5128,28 @@

    unsigned long numberOfInputs
    - Same to numberOfInputs in AudioNode. + Same to numberOfInputs in AudioNode.
    unsigned long numberOfOutputs
    - Same to numberOfOutputs in AudioNode. + Same to numberOfOutputs in + AudioNode.
    unsigned long channelCount
    - Same to channelCount in AudioNode. + Same to channelCount in AudioNode.
    ChannelCountMode channelCountMode
    - Same to channelCountMode in AudioNode. + Value used to initialize the + channelCountMode attribute of an + AudioWorkletNode
    ChannelInterpretation channelInterpretation @@ -5160,7 +5167,7 @@

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

    readonly attribute static sequence<AudioParamDescriptor> + parameterDescriptors

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

    @@ -5254,40 +5263,32 @@

    Float32Array[][] inputs

    - An Array of Arrays of Float32Arrays. 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 mth channel of + nth input. While the number of inputs is fixed + at the construction, the number of channels can be changed + dynamically.
    Float32Array[][] outputs
    - An Array of Arrays of Float32Arrays. 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 + mth channel of nth output.
    Object parameters
    - 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. + Provides an association between the names of an + AudioParams specified by the + AudioParamDescriptors 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".
    @@ -5461,7 +5462,7 @@

    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]); + var step = Math.pow(0.5, bitDepth[i]); this.phase += frequencyReduction[i]; if (this.phase >= 1.0) { this.phase -= 1.0; @@ -5494,8 +5495,7 @@

    class VUMeterNode extends AudioWorkletNode { constructor (context, options) { - - // Defaulting from AudioNodeOptions + // Setting default values for the input, the output and the channel count. options.numberOfInputs = 1; options.numberOfOutputs = 0; options.channelCount = 1; @@ -5521,7 +5521,7 @@

    } draw () { - /** Draw the meter based on the volume value. **/ + // Draw the meter based on the volume value. } // handle updated values from audio side @@ -5593,7 +5593,7 @@

    <script> importAudioWorkletNode.then(function () { var context = new AudioContext(); - var microphone = GET_MIRCOPHONE(); // e.g) a live input from getUserMedia(). + var microphone = GET_MICROPHONE(); // e.g) a live input from getUserMedia(). var vuMeterNode = new VUMeterNode(context, { updatingInterval: 50 }); microphone.connnect(vuMeterNode); From aa51a966e5247ba20e4cb24a6366fd82f291771b Mon Sep 17 00:00:00 2001 From: Hongchan Choi Date: Thu, 7 Jul 2016 11:06:21 -0700 Subject: [PATCH 08/13] remove redundant header --- index.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.html b/index.html index 67d14a1b4..15ef23ee8 100644 --- a/index.html +++ b/index.html @@ -5019,9 +5019,6 @@

    -

    - Construction Procedure of AudioWorkletNode and AudioWorkletProcessor -

    The AudioWorkletNode interface From 4f479a239e8bef0063db488ebc94066d48f25722 Mon Sep 17 00:00:00 2001 From: Hongchan Choi Date: Thu, 7 Jul 2016 14:02:32 -0700 Subject: [PATCH 09/13] fixing typos --- index.html | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 15ef23ee8..681458bc6 100644 --- a/index.html +++ b/index.html @@ -5038,13 +5038,11 @@

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

  • Run the AudioWorkletProcessor constructor, passing a structured clone of the - options argument that was provided to + options parameter that was provided to AudioWorkletNode.
    1. Run the super constructor of @@ -5077,9 +5075,10 @@

      information from the processor's parameterDescriptors.
        -
      1. Initialize parameter values from the - options object where the keys match names - declared in descriptors. +
      2. Initialize the value of AudioParam objects with + key-value pairs in the option parameter. Find + the key matches the name of AudioParam object and assign + the value to it.

    2. @@ -5103,7 +5102,7 @@

      postMessage may be called to send a message to the corresponding AudioWorkletProcessor via the algorithm - defined by the specification. + defined by the [!Worker] specification.

  • From 5cea8613978b993ab1a08260c961309d4f75c81c Mon Sep 17 00:00:00 2001 From: Hongchan Choi Date: Tue, 12 Jul 2016 09:09:30 -0700 Subject: [PATCH 10/13] addressed feedback from rtoy --- index.html | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index 681458bc6..b5422fc7f 100644 --- a/index.html +++ b/index.html @@ -5012,9 +5012,9 @@

    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.

    @@ -5042,10 +5042,10 @@

    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.

    1. @@ -5077,8 +5077,8 @@

      1. Initialize the value of AudioParam objects with key-value pairs in the 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.

    2. @@ -5219,10 +5219,10 @@

      - 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 mth channel of + audio samples for the mth channel of nth input. While the number of inputs is fixed at the construction, the number of channels can be changed dynamically. @@ -5269,14 +5269,15 @@

      Float32Array[][] outputs
      - outputs[n][m] is a Float32Array object for - mth channel of nth output. + outputs[n][m] is a Float32Array object + containing the audio samples for mth channel of + nth output.
      Object parameters
      - Provides an association between the names of an + Provides an association between the names of the AudioParams specified by the AudioParamDescriptors during construction and the automation values for the From b90832134ec0ca31b591dc5af332a76912a799de Mon Sep 17 00:00:00 2001 From: Hongchan Choi Date: Mon, 18 Jul 2016 13:26:42 -0700 Subject: [PATCH 11/13] wating for feedback from joe --- index.html | 84 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/index.html b/index.html index b5422fc7f..a5a4c5cc9 100644 --- a/index.html +++ b/index.html @@ -4980,29 +4980,31 @@

      The AudioWorklet interface

      - 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 AudioNodes 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 + AudioNodes 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 AudioWorkletNodes 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.

      @@ -5012,10 +5014,8 @@

      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.

      @@ -5061,11 +5061,10 @@

      options parameter that was provided to AudioWorkletNode.
        -
      1. Run the super constructor of - AudioWorkletProcessor subclass. -
      2. Run the constructor of the - AudioWorkletProcessor subclass. + AudioWorkletProcessor subclass. In this + constructor, The options parameter can be used + to initialize the state of the processor.
      @@ -5078,7 +5077,9 @@

    3. Initialize the value of 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. + 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.
    @@ -5186,14 +5187,21 @@

    A string key that represents a class definition to be - registered. + registered. This key is used to resolve an + AudioWorkletProcessor during construction + of an AudioWorkletNode. Throws an + exception if another + AudioWorkletProcessor has already + registered this key.
    Function classConstructor
    A class definition extended from - AudioWorkletProcessor. + AudioWorkletProcessor. Throws if this is not a class + definition or it does not extend + AudioWorkletProcessor.
    @@ -5233,7 +5241,7 @@

    This getter returns an AudioContextInfo - object from the associated AudioContext. + object that describes the associated AudioContext.

    @@ -5282,7 +5290,7 @@

    AudioParamDescriptors 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 @@

    AudioContextInfo

    - The AudioContextInfo dictionary contains the status - of the associated AudioContext. + The AudioContextInfo dictionary provides an + AudioWorkletGlobalScope with a view of an + AudioContext.

    @@ -5479,11 +5488,14 @@

    VU Meter Node

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

    Global Scope: vumeternode.js From 4f193791e77d6c13794129825519a044f6738226 Mon Sep 17 00:00:00 2001 From: Hongchan Choi Date: Thu, 4 Aug 2016 16:16:20 -0700 Subject: [PATCH 12/13] addressing feedback from Paul (part 1) --- index.html | 91 +++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/index.html b/index.html index a5a4c5cc9..03eff337d 100644 --- a/index.html +++ b/index.html @@ -5012,10 +5012,8 @@

    - 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]].

    @@ -5025,7 +5023,7 @@

    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 AudioNodes 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 @@

    In the 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.
  • Run the AudioWorkletProcessor constructor, passing a structured clone of the @@ -5062,24 +5060,26 @@

    AudioWorkletNode.
    1. Run the constructor of the - 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.

  • - In the window scope: Construct + In the global scope: Construct AudioParam objects based on the information from the processor's parameterDescriptors.
      -
    1. Initialize the value of 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. +
    2. Initialize the value of 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.
  • @@ -5212,8 +5212,8 @@

    The AudioWorkletProcessor interface

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

    @@ -5259,8 +5259,8 @@

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

    @@ -5303,8 +5303,7 @@

    It may be called to send a message to the - AudioWorkletNode, via the algorithm defined - by the Worker specification. + AudioWorkletNode.

    @@ -5332,9 +5331,9 @@

    DOMString name

    - Represents the name of a parameter. An NotSupportedError - exception MUST be thrown when a duplicated name is found when - registering the class definition. + Represents the name of a parameter. An + NotSupportedError exception MUST be thrown when a + duplicated name is found when registering the class definition.
    float defaultValue = 0 @@ -5343,23 +5342,23 @@

    Represents the default value of the parameter. If this value is out of the range of float data type or the range defined by minValue and maxValue, an - NotSupportedError exception MUST be thrown. + NotSupportedError exception MUST be thrown.

    float minValue
    - 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. + 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.
    float maxValue
    - 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. + 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.

    @@ -5377,9 +5376,9 @@

    double playbackTime
    - The starting time of the block of audio being processed in - response to this event. By definition this will be equal to the - value of 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.
    @@ -5388,7 +5387,7 @@

    Represents the sample rate of the associated - AudioContext. + BaseAudioContext.

    @@ -5516,16 +5515,16 @@

    super(context, 'VUMeter', options); // Mirrored states of AudioWorkletProcessor. - this.updatingInterval = options.updatingInterval; - this.volume = 0; + this._updatingInterval = options.updatingInterval; + this._volume = 0; } get updatingInterval() { - return this.updatingInterval; + return this._updatingInterval; } set updatingInterval (intervalValue) { - this.updatingInterval = intervalValue; + this._updatingInterval = intervalValue; this.postMessage({ updatingInterval: intervalValue }); } @@ -5536,7 +5535,7 @@

    // handle updated values from audio side onmessage (event) { if (event.data.hasOwnProperty('volume')) - this.volume = event.data.volume; + this._volume = event.data.volume; } } From 75ca59fc82e3fca5530e0a17eb81c98fc5ab2afa Mon Sep 17 00:00:00 2001 From: Hongchan Choi Date: Fri, 5 Aug 2016 14:56:57 -0700 Subject: [PATCH 13/13] addressing feedback from domenic - part 1 --- index.html | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index 0d3399cc7..7264c3b82 100644 --- a/index.html +++ b/index.html @@ -5170,14 +5170,13 @@

    - void postMessage(any message, optional - sequence<Transferable> transfer) + void postMessage(any message, optional sequence<Object> + transfer)

    postMessage may be called to send a message to the - corresponding AudioWorkletProcessor via the algorithm - defined by the [!Worker] specification. + corresponding AudioWorkletProcessor.

    @@ -5247,7 +5246,7 @@

    - void registerAudioWorkletProcessor (DOMString name, Function + void registerProcessor (DOMString name, Function classConstructor)
    @@ -5296,8 +5295,8 @@

    - readonly attribute static sequence<AudioParamDescriptor> - parameterDescriptors + [SameObject] readonly attribute + FrozenArray<AudioParamDescriptor> parameterDescriptors

    @@ -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.

    - Float32Array[][] inputs + sequence<sequence<Float32Array>> inputs
    inputs[n][m] is a Float32Array of @@ -5348,7 +5349,7 @@

    dynamically.

    - Float32Array[][] outputs + sequence<sequence<Float32Array>> outputs
    outputs[n][m] is a Float32Array object @@ -5385,7 +5386,7 @@

    - optional sequence<Transferable> transfer + optional sequence<Object> transfer