Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(+1)
(I peeked at the source code for Sup.Audio.SoundPlayer, and it looks like this might be what it runs off of)

Yes, Sup.Audio uses WebAudio behind the scenes. As we tend to do with many things in Superpowers Game, we've wrapped it into an API that's more convenient and simpler for most games, but advanced features haven't been exposed yet.

You can access WebAudio from a Superpowers Game project. In JavaScript, "window" is the global object. So, any objects defined in the Web Audio docs can be access as window.NameOfThatObject, you just need to declare that window exists first, so TypeScript won't complain:

declare var window;
// window.AudioBuffer is now available

Alternatively, you can install Florent Poujol's DOM plugin which defines all Web APIs in a typed fashion to your Superpowers Game. Then you can access AudioBuffer directly.

If you want to plug into Superpowers's Sup.Audio's internal Web Audio context, you might go through the internal game instance:

// Start by accessing an inner Actor object
// It is not declared in our TypeScript APIs so you need to cast to any first:
let innerActor = (Sup.getActor("Some actor") as any).__inner;

// You can then gain access to the game instance (the Superpowers Game's engine main object)
let gameInstance = innerActor.gameInstance;

// Assuming you have installed the DOM plugin, you can use AudioContext as a type:
let audioCtx: AudioContext = gameInstance.audio.getContext();
let masterGain: GainNode = gameInstance.audio.masterGain;

Now you can do your own things with custom buffers etc.

Another approach, probably much simpler actually, would be to go through a Sup.Audio.SoundPlayer:

let soundPlayer = Sup.Audio.playSound("My Asset");
let innerSoundPlayer = (soundPlayer as any).__inner;

// innerSoundPlayer.audioCtx is the audio context
// innerSoundPlayer.audioMasterGain is the master gain node // innerSoundPlayer.buffer contains the AudioBuffer // etc. See https://github.com/superpowers/superpowers-game/blob/master/SupEngine/src/SoundPlayer.ts

Hope that helps!

Thanks for all the info! :D

(1 edit) (+1)

Using the SoundPlayer method, I was able to extend the class as SoundPlayerAdvanced, and add a Buffer interface to get auto-completion. I used Sup.log to test it, and I was able to get an array of data from the channels, along with the duration, length, and sampleRate of the buffer.

interface Buffer {
    sampleRate: number;
    length: number;
    duration: number;
    numberOfChannels: number;
    getChannelData(number);
    copyFromChannel(number);
    copyToChannel(number);
}

class SoundPlayerAdvanced extends Sup.Audio.SoundPlayer {
    buffer: Buffer;
    constructor(pathOrAsset: string|Sup.Sound, volume?: number, options?: {loop?: boolean, pitch?: number, pan?: number}) {
        super(pathOrAsset, volume, options);
        this.buffer = (this as any).__inner.buffer;
    }
}

Thanks again! :D