@like2d/like
    Preparing search index...

    Interface Audio

    For a list of all possible play and update parameters, check ChannelState.

    To play a sound, load it and then play it.

    const wave = like.audio.loadWave("beanBlast.ogg")

    like.actionpressed = (action) => {
    if (action == "blast") {
    like.audio.play(wave, {
    index: 0, // channel index, omit to use polyphony
    speed: blastPower, // affects speed and pitch
    volume: 0.5,
    seek: 0.0, // start position
    loop: false,
    })
    }
    }

    When a sound is playing, it can be manipulated just the same with Audio.update

    // keep track of channels to manipulate playing sounds
    const channel = like.audio.play(wobbleWave);

    like.update = (dt) => {
    // make the sound's playback rate (pitch and speed) change with a variable
    // don't forget to pass in the channel index.
    like.audio.update({ index: channel, speed: wobbleRate })
    }

    like.actionpressed = (action) => {
    if (action == "scrub_left") {
    const status = like.audio.status(channel);
    // if status is undefined, the sound ended.
    if (status) {
    like.audio.update({ index: channel, seek: status.seek - 0.5 });
    }
    }
    }
    interface Audio {
        active(): ChannelState[];
        getContext(): AudioContext;
        loadWave(path: string): Wave;
        play(wave: Wave, options?: Partial<ChannelState>): number | null;
        status(channel: number): ChannelState | undefined;
        stop(channel: number): void;
        stopAll(): void;
        stopWave(wave: Wave): void;
        tell(channel: number): number | undefined;
        update(params: Partial<ChannelState> & { index: number }): void;
        get globalVolume(): number;
        set globalVolume(volume: number): void;
    }
    Index

    Accessors

    • get globalVolume(): number

      Get the master volume, aka gain of the root gain node.

      Returns number

    • set globalVolume(volume: number): void

      Set the master volume, aka gain of the root gain node.

      Parameters

      • volume: number

      Returns void

    Methods

    • Get audio context (escape hatch). Not guaranteed to work the same way in future versions.

      Returns AudioContext

    • Load a sound file into a Wave.

      Save this wave and reuse it! Construction is slow and expensive. Avoid loading large files (>5 minutes) to avoid using excess memory.

      To unload a wave file, simply drop all references to it so the garbage collector can clear it out.

      Use promise Wave.ready or check Wave.isReady to know that it has finished loading.

      Parameters

      • path: string

      Returns Wave

    • Play a wave.

      If options.channel is set, this will overwrite the playback state of the previous channel. Otherwise, it allocates a new one.

      If the wave is not loaded, LÏKE will begin playing when it is loaded. This does not cause delay, but it may cause cut-in.

      Parameters

      Returns number | null

      The index of the active channel (starting at 1), unless the wave file failed to load.

    • Query the state of a current playing sound.

      Parameters

      • channel: number

      Returns ChannelState | undefined

      said state, unless the sound stopped/ended

    • Stop a playing channel and deallocate it.

      Parameters

      • channel: number

      Returns void

    • Stop all channels playing a specific wave.

      Parameters

      Returns void

    • Query just the current play position of a sound.

      Parameters

      • channel: number

      Returns number | undefined