web-audio-mock-api
v1.0.0
Published
mock API which implements the Web Audio API's interfaces only
Downloads
1,844
Readme
web-audio-mock-api
This module is a mock API which implements the Web Audio API's interfaces only. This mock API simulates Web Audio API's methods, return value and properties. It is useful to test your web audio application.
Installation
$ npm install -D web-audio-mock-api
API
The API is based on the latest specification of Web Audio API.
Example
const assert = require("assert");
const wamock = require("web-audio-mock-api");
function beep(audioContext) {
const oscillator = audioContext.createOscillator();
const gain = audioContext.createGain();
const t0 = audioContext.currentTime;
const t1 = t0 + 0.25;
oscillator.type = "sine";
oscillator.frequency.value = 880;
oscillator.start(t0);
oscillator.stop(t1);
oscillator.onended = () => {
oscillator.disconnect();
gain.disconnect();
};
gain
.setValueAtTime(1, t0)
.linearRampToValueAtTime(0, t1);
oscillator.connect(gain).connect(audioContext.destination);
}
const audioContext = new wamock.AudioContext();
assert.doesNotThrow(() => beep(audioContext));
Licsense
MIT