Skip to content

Commit

Permalink
pass whole options object to processor constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed May 11, 2024
1 parent 0647f70 commit 583148f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/worklets/bitcrusher.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Bitcrusher extends AudioWorkletProcessor {

this._phase = 0;
this._lastSampleValue = 0;
this._msg = options.msg;
this._msg = options.processorOptions.msg;

this.port.on('message', event => {
console.log(`++ on message: ${JSON.stringify(event, null, 2)}\n`);
Expand Down
14 changes: 4 additions & 10 deletions js/AudioWorkletGlobalScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,25 +265,19 @@ parentPort.on('message', event => {
case 'node-web-audio-api:worklet:create-processor': {
const { name, id, options, port } = event;
const ctor = nameProcessorCtorMap.get(name);
// options to be passed to the processor parent for intialization
const {
numberOfInputs,
numberOfOutputs,
processorOptions,
outputChannelCount, // @todo - clarify usage
} = options;

// rewrap options of interest for the AudioWorkletNodeBaseClass
pendingProcessorConstructionData = {
port,
numberOfInputs,
numberOfOutputs,
numberOfInputs: options.numberOfInputs,
numberOfOutputs: options.numberOfOutputs,
parameterDescriptors: ctor.parameterDescriptors,
};

let instance;

try {
instance = new ctor(processorOptions);
instance = new ctor(options);
} catch (err) {
// @todo - send processor error
console.log(err.message);
Expand Down

0 comments on commit 583148f

Please sign in to comment.