mwg API
    Preparing search index...

    Class StreamChannel

    The streaming twin of Channel: it queues short buffers on the audio clock ahead of the playhead from a BlockSource instead of owning one decoded buffer, so a long or endless track costs a couple of seconds of memory rather than the whole render. It loops on a region, seeks, retunes volume, pitch and pan, fades an endless source out after a limit, and reports onUnderrun when the clock got ahead of what was queued.

    Chunks are queued by a timer it runs itself (pumpMs), so a game that never calls update() still hears sound; a timer throttled in a background tab is the reason the lookahead is two seconds. A pitch change applies from the next chunk, up to the lookahead later.

    import { StreamChannel, type BlockSource } from '@datamoc/mwg/audio';

    declare const context: AudioContext;
    declare const tune: BlockSource;

    const channel = new StreamChannel(context);
    channel.onEnded.add(() => console.log('done'));
    channel.play(tune, { repeat: false, volume: 0.8 });
    console.log(channel.position());
    channel.stop(1);
    Index
    onEnded: Signal<void> = ...

    fires once when a source that does not repeat has played out, or an endless one reached its limit

    onError: Signal<Error> = ...

    fires when the source threw while being read: the voice stops instead of letting the error escape from a timer

    onUnderrun: Signal<number> = ...

    fires when the clock passed the end of the queue before the next chunk was ready, with how late it was in seconds

    • seconds into the source, wrapping inside the loop region while it repeats

      Returns number

    • the playhead as a source frame, the exact unit a save stores and a restore skips to

      Returns number

    • queues whatever chunks the lookahead allows; called by the timer and safe to call each frame

      Returns void

    • moves the playhead, restarting the queue from there

      Parameters

      • seconds: number

      Returns void

    • stops the voice, fading out over fadeSeconds first when positive; the playhead is remembered for a later play with the same pos

      Parameters

      • fadeSeconds: number = 0

      Returns void

    • retunes the playing voice in place: no restart, no seek

      Parameters

      • params: { pan?: number; pitch?: number; volume?: number } = {}

      Returns void