Ogg Vorbis and your browser

Audio capabilities in a browser come from their Engines: Blink is the engine for Brave, Opera, and Chrome. WebKit is the engine for Safari and all iOS browsers (e.g. Chrome on an iPhone uses Webkit, not Blink). Gecko is the engine for Firefox.


Oggmented has detected that it’s running in a browser with buggy ogg vorbis support. This is expected for Browsers using the Blink engine: Brave, Opera, Chrome, etc. Blink uses ffmpeg to decode vorbis, which has a bug specific to vorbis where it adds a few extra samples at the end, resulting in a popping sound if you were to loop some audio that’s meant to sound smooth when looped. For example with the file produced by sox -nr 44100 triangle.ogg synth .75 triangle 440 gain -20:

15%

Looped using native AudioContext

15%

Looped using OggmentedAudioContext


If you look in your browser’s JavaScript console, you’ll see the Float32Arrays for both buffers. The Oggmented AudioContext’s buffer has 33075 samples, which is a reasonable number of samples to see for 0.75s of 44100 Hz audio. The native AudioContext however, has 33472 samples.


Note: If you’re seeing the above console demo and you’re using Firefox, consider it a bug (in my page). It won’t demonstrate anything interesting in Firefox, and is just showing up because your computer’s audio output is currently set to run at something other than 44,100 Hz, and Firefox is resampling the audio to that rate (the code just looks at your native AudioContext capabilities, not your user-agent). I’ll need to come up with a slight redesign to account for this, but in the short term I wanted to provide this info.




Oggmented AudioContext is a library that decodes vorbis using its own JavaScript and Wasm, transpiled from Xiph’s libvorbis C libraries, rather than using the browser’s built in audio decoding support. I initially wrote it to compensate for Safari’s lack of support, but along the way I realized it’s also useful in Blink browsers, where vorbis decoding is buggy.

If you don’t happen to have any vorbis files lying around but you’d like to try this demonstration, here’s one you can download: Só Sol – Valsa Do Corpo. (More Só Sol can be found at their Bandcamp page)


Source for this page