<audio />
HTML's <audio />
cannot play BRSTM!
<audio src="music.mp3" />
No, it's not able to loop
Is the complexity getting out of hand?
What's the user flow like?
Static | Server |
---|---|
SPA | Client-server |
User "uploads" BRSTM | User uploads BRSTM |
JS/WASM decode | Server converts to MP3 |
Web Audio API plays |
HTML <audio /> to play or live streaming
|
For real
So I started a simple page that accepts a BRSTM file and read its metadata
It works. What's next?
Buffer Source node → Audio Context destination node
const audioContext = new AudioContext();
const bufferSource = audioContext.createBufferSource();
bufferSource.connect(audioContext.destination);
Get PCM samples from BRSTM
const pcm = brstm.getAllSamples(); // TODO: Implement
Transform PCM into audio buffer
const audioBuffer = audioContext.createBuffer(
1, // number of channels
pcm.length,
metadata.sampleRate
);
audioBuffer.getChannelData(0).set(pcm);
Write into source node, and plays it
bufferSource.buffer = audioBuffer;
bufferSource.start(0); // start immediately
This is the coding format
How to turn ADPCM into PCM?and the input/output looks as expected!
That means I can't use that npm package
sighAttach debugger!
No
Web Audio API Gotchas
Easy
// audioBuffer contains raw audio data (PCM)
audioBuffer.loop = true
audioBuffer.loopStart = … // in seconds
audioBuffer.loopEnd = … // in seconds
Easy
audioContext.suspend(); // pause
audioContext.resume(); // resume
// in <audio />
audioElement.time = … // in seconds
bufferSource.start(0, soughtTimeInSeconds);
Impossible
audioContext.currentTime
Reimplement timer