web-audio-mock-api

1.0.0 • Public • Published

web-audio-mock-api

Build Status NPM Version License

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

/web-audio-mock-api/

    Package Sidebar

    Install

    npm i web-audio-mock-api

    Weekly Downloads

    234

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • mohayonao