Skip to content

Commit

Permalink
fix(OscillatorNodes): only ever pass a single argument to start metho…
Browse files Browse the repository at this point in the history
…d to keep stricly inline with the specification and to avoid bugs in non-browser Web Audio implementations like node-web-audio-api

Fixes #267
  • Loading branch information
benji6 committed Jan 7, 2023
1 parent 4a49899 commit f898b09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
17 changes: 6 additions & 11 deletions src/VirtualAudioNodes/StandardVirtualAudioNode.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
audioParamProperties,
constructorParamsKeys,
setters,
startAndStopNodes,
} from "../data";
import { audioParamProperties, constructorParamsKeys, setters } from "../data";
import {
IAudioNodeFactoryParam,
IAudioNodePropertyLookup,
Expand Down Expand Up @@ -121,11 +116,11 @@ export default class StandardVirtualAudioNode extends VirtualAudioNodeBase {
this.params = undefined;
this.update(params);

if (startAndStopNodes.indexOf(this.node) !== -1) {
audioNode.start(
startTime == null ? audioContext.currentTime : startTime,
offsetTime || 0
);
if (this.node === "bufferSource") {
audioNode.start(startTime ?? audioContext.currentTime, offsetTime || 0);
if (stopTime != null) audioNode.stop(stopTime);
} else if (this.node === "oscillator") {
audioNode.start(startTime ?? audioContext.currentTime);
if (stopTime != null) audioNode.stop(stopTime);
}

Expand Down
2 changes: 0 additions & 2 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@ export const constructorParamsKeys = [
];

export const setters = ["position", "orientation"];

export const startAndStopNodes = ["oscillator", "bufferSource"];

0 comments on commit f898b09

Please sign in to comment.