Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work as an argument to 'AudioNode.connect' #6

Closed
JohnWeisz opened this issue Aug 26, 2018 · 1 comment
Closed

Doesn't work as an argument to 'AudioNode.connect' #6

JohnWeisz opened this issue Aug 26, 2018 · 1 comment
Labels
bug Something isn't working

Comments

@JohnWeisz
Copy link
Contributor

JohnWeisz commented Aug 26, 2018

Every single browser (Firefox, Edge, Safari tested) throws a TypeError when attempting to connect to a polyfilled AudioWorkletNode, and I believe it's caused by these lines:

  window.AudioWorkletNode = function AudioWorkletNode (context, name) {
    const processor = getProcessorsForContext(context)[name];

    this.parameters = new Map();
    if (processor.properties) {
      for (let i = 0; i < processor.properties.length; i++) {
        const prop = processor.properties[i];
        const node = context.createGain().gain;
        node.value = prop.defaultValue;
        // @TODO there's no good way to construct the proxy AudioParam here
        this.parameters.set(prop.name, node);
      }
    }

    const inst = new processor.Processor({});

    this.port = processor.port;
    const scriptProcessor = context.createScriptProcessor();
    scriptProcessor.node = this;
    scriptProcessor.processor = processor;
    scriptProcessor.instance = inst;
    scriptProcessor.onaudioprocess = onAudioProcess;
    Object.defineProperty(this, '$$node', { value: scriptProcessor });
  };

Here, a custom class instance is constructed, but that's not accepted by any browser as the first argument to AudioNode.connect. A true, real, native AudioNode object is required for that to work, and this cannot be faked with setting the prototype manually.

The correct course of action would be returning an augmented ScriptProcessorNode.

@JohnWeisz JohnWeisz changed the title Doesn't work in any browser Doesn't work as an argument to 'AudioNode.connect' Aug 26, 2018
@developit
Copy link
Collaborator

Agreed, I'd like to switch to returning a ScriptProcessorNode.

@developit developit added the bug Something isn't working label Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants