outputChannelCount not working when I inherit from AudioWorkletProcessor
KnappSas opened this issue · 4 comments
Hi, I am facing this issue, trying out the example in the WamExample folder. The example passes the outputChannelCount: [2]
with the options
to the processor which is then passed to the actual AudioWorkletProcessor
via the super
call to the parent class.
This doesn't work on my system in any browser, I always have a channel count of 1 ... I also just tried a minimal example:
The following code doesn't work.
// processor.js
class Processor extends AudioWorkletProcessor {
constructor() {
super({outputChannelCount: [2]});
}
process(inputs, outputs, parameters) {
console.log("output channels: ", outputs[0].length);
return true;
}
}
registerProcessor('processor', Processor);
But when I leave the options in the Processor class out like:
// processor.js
class Processor extends AudioWorkletProcessor {
constructor() {
super();
}
process(inputs, outputs, parameters) {
console.log("output channels: ", outputs[0].length);
return true;
}
}
registerProcessor('processor', Processor);
and pass the options
to the AudioWorkletNode
instead
// app.js
let audioContext = new AudioContext();
(async () => {
await audioContext.audioWorklet.addModule('processor.js');
audioWorkletNode = new AudioWorkletNode(audioContext, 'processor', {outputChannelCount: [2]});
audioWorkletNode.connect(audioContext.destination);
})();
it works and I get my 2 channels now.
So passing options
in the class that inherits from AudioWorkletProcessor
doesn't seem to work anymore? Is this a bug in the Web Audio API or is there something that I am missing from the specification?
Anyway,... whatever is wrong with my code above, the real cause seems to be either in WamExampleNode.js or WamExampleProcessor.js..
To fix it on my side it is enough to rewrite the following in WamExampleNode.js
options.processorOptions = {
numberOfInputs: 1,
numberOfOutputs: 1,
outputChannelCount: [2],
useSab: true,
};
super(module, options);
to
options.outputChannelCount = [2];
options.processorOptions = {
numberOfInputs: 1,
numberOfOutputs: 1,
outputChannelCount: [2],
useSab: true,
};
super(module, options);
I see you removed the options from the ctor-call in WamProcessor in the sdk. This was also discussed here: WebAudio/web-audio-api#2491
So this thread can be closed then.