question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to find native AudioParam on connection

See original GitHub issue

I’m trying to integrate standardized-audio-context into Tone.js, but i’m getting an issue when i try to use it in a simple Oscillator: Uncaught Error: A value with the given key could not be found.

Here’s how i reproduced it: https://codesandbox.io/s/sharp-currying-k9v9y

For context, the oscillator uses two ConstantSourceNodes connected to the frequency and detune of the OscillatorNode. it seems to cause an issue when the constant source is connected to the AudioParam. It is unable to resolve the native AudioParam in the WeakMap. Either the AudioParam has been already garbage collected, which seems unlikely, or possibly it was not added.

Thanks for your help!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisguttandincommented, Aug 27, 2019

After writing the message above yesterday I realized that it is unfortunately not that easy. Up to now we have the following behavior which I think is super confusing.

import { AudioBuffer as StdAudioBuffer } from 'standardized-audio-context';

const nativeAudioBuffer = new AudioBuffer({ length: 1, sampleRate: 44100 });

// This seems reasonable to me:
console.log(nativeAudioBuffer instanceof AudioBuffer); // true
console.log(nativeAudioBuffer instanceof StdAudioBuffer); // false

const stdAudioBuffer = new StdAudioBuffer({ length: 1, sampleRate: 44100 });

// But I think this is confusing:
console.log(stdAudioBuffer instanceof AudioBuffer); // true
console.log(stdAudioBuffer instanceof StdAudioBuffer); // false

I changed that now that an AudioBuffer created with standardized-audio-context also returns true when doing an instanceof check with the constructor exported by standardized-audio-context.

Only the result of the last console.log() from the example above will change when using v21.2.1 (yet to be released) onwards.

// ...
console.log(stdAudioBuffer instanceof AudioBuffer); // true
console.log(stdAudioBuffer instanceof StdAudioBuffer); // true

I hope this makes sense to you as well.

1reaction
chrisguttandincommented, Aug 26, 2019

Yes an instanceof check will work.

The AudioBuffer implementation is very dirty because by definition an AudioBuffer is the only thing which can be shared across different (Offline)AudioContexts. The constructor in particular is doing something which should normally never be done: https://github.com/chrisguttandin/standardized-audio-context/blob/master/src/factories/audio-buffer-constructor.ts#L89 😃

I did all this to make the following work:

import { AudioBuffer } from 'standardized-audio-context';

const nativeAudioContext = new AudioContext();
const nativeAudioBufferSourceNode = new AudioBufferSourceNode(
    nativeAudioContext,
    { buffer: new AudioBuffer({ length: 1, sampleRate: 44100 }) }
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Constructible and connect()able AudioParams #367 - GitHub
Binding AudioParam of another AudioNode to an AudioWorker As far as i understand, it is impossible to change a native AudioNodes' parameter ...
Read more >
How does the audioParam.exponentialRampToValueAtTime ...
It seems that this function does not like 0 value. FF throws "SyntaxError: An invalid or illegal string was specified".
Read more >
AudioParam - Web APIs | MDN
Chrome Edge AudioParam Full support. Chrome14. Toggle history Full support. Edge12. Toggl... automationRate Full support. Chrome68. Toggle history Full support. Edge79. Toggl... cancelAndHoldAtTime Full support. Chrome57....
Read more >
Web Audio API - W3C
An AudioParam interface, for controlling an individual aspect of an AudioNode 's functioning, such as volume. An AudioListener interface, which ...
Read more >
Web Audio API - GitHub Pages
Abstract. This specification describes a high-level Web API for processing and synthesizing audio in web applications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found