mwg API
    Preparing search index...

    Class FakeAudioContext

    A WebAudio double whose clock only moves when a test moves it. It records every buffer source that was started and ends them as advance() passes their end time, which is exactly the part of an AudioContext a streaming voice depends on (the clock, scheduled starts, the onended of a source) and nothing else.

    import { StreamChannel } from '@datamoc/mwg/audio';
    import { FakeAudioContext, FakeBlockSource } from '@datamoc/mwg/testing';

    const context = new FakeAudioContext();
    const channel = new StreamChannel(context.asContext(), undefined, { pumpMs: 0 });
    channel.play(new FakeBlockSource({ seconds: 1 }));
    context.advance(2);
    Index
    currentTime: number = 0
    destination: { connect(): void } = ...
    processors: FakeScriptProcessor[] = []

    every script processor made, in order

    resumes: number = 0
    sampleRate: number
    sources: FakeBufferSource[] = []

    every buffer source made, in order, with when it was asked to start

    state: "running" | "suspended" = 'running'
    • moves the clock and ends every started source whose scheduled end has passed

      Parameters

      • seconds: number

      Returns void

    • the double typed as the context the code under test expects

      Returns AudioContext

    • Parameters

      • bufferSize: number

      Returns FakeScriptProcessor

    • Returns { pan: { value: number }; connect(): void }