Best practice for sound format / compression in Twine?

What compressed sound formats are usable in Twine works to reduce download size, while having wide enough support in browsers so as not to compromise compatibility?

The context is that, at the IF Archive, we sometimes get Quite Large submissions where most of the storage used is sounds in uncompressed .WAV format; and I’d like to be able to confidently advise on alternatives. (Not that the Archive doesn’t accept Quite Large submissions, but we’d prefer to minimise them where possible.)

MP3 seems like the obvious format choice; does that work OK?
A minimal bit of research suggests it shouldn’t cause trouble: the SugarCube docs (for example) say “The audio subsystem is based upon the HTML Media Elements APIs”; following links from that gets me to a web audio codec guide that suggests MP3 support is widespread in browsers. But I don’t have working knowledge (of Twine, or the underlying web primitives).

Does using a compressed format as opposed to WAV make a difference in practice to gapless looping of background music, or anything like that?
(Again, no practical experience, I can just see that in theory it could possibly be more of a problem for compressed than uncompressed audio. But I don’t know if gapless is possible at all with browsers.)

I guess that since any browser-based format is likely to use the underlying browser’s facilities to decode and play audio, what goes for Twine will probably go for other formats too.

4 Likes

This isn’t a Twine answer but;

I had to abandon my use of mp3 for things like ambient sounds, where they had to loop. Annoyingly mp3s won’t always loop. It’s because the format has to store data in whole frames, which isn’t the same as the original length. Normally, it pads with black. Which for shot sounds is fine. but not for loops, which get a gap.

Now i just use ogg.

3 Likes

It is also friendly to players (and their bandwidth) to use compressed media files.

3 Likes

Seconding ogg. The space at the start/end of mp3 files can get really annoying! Plus oggs are slightly smaller than mp3s when compressed, I think, depending on how much you compress the sound.

2 Likes

What’s cross-browser support for Ogg (and its contained Vorbis codec) like, though?
Looks like Safari supports MP3 but not Vorbis; and the codec doc has troubling statements like “Vorbis is almost always used in Ogg files, but Ogg containers are not universally supported. Even Microsoft Edge, which supports both Vorbis, does not yet support Ogg containers.”

Would this help?

EDIT:

This to compare with the other formats

2 Likes

Ah, I somehow missed looking on caniuse. Here’s MP3 (still looks well-supported, its deficiencies notwithstanding).

To focus this, I guess: has anyone who’s used MP3 in a Twine regretted it?

(Perhaps for the gap-when-looping reason.)

Just putting a note here on gapless playback since it was mentioned.

The audio APIs currently used by most story formats—either as built-ins (SugarCube & Chapbook) or via associated library (HAL for Harlowe)—are backed by the HTML Audio API, which does not support true gapless playback.

If you need true gapless support, then you’ll currently need to use either the Web Audio API directly or a library that supports it—e.g., Howler in the appropriate mode.

3 Likes