ncase / wbwwb

We Become What We Behold – a minigame about the news!
1.15k stars 235 forks source link

Add .opus and .m4a sounds #39

Closed erikdubbelboer closed 3 years ago

erikdubbelboer commented 3 years ago

When passing multiple sounds to Howl it will automatically pick the first supported one [1]. Most browsers support .opus (Howl also does [2]) which is by far the smallest audio format. This reduces the audio from 1.8MB to 0.66MB. Safari doesn't support .opus so we can use .m4a (AAC) for this. This still reduces the audio to 1.33MB.

Commands to generate files: Convert .mp3 to .wav:

sox bg_creepy.mp3 bg_creepy.wav

Convert .wav to .opus:

opusenc --discard-pictures --discard-comments --padding 0 --framesize 60 --bitrate 32 --music bg_creepy.wav bg_creepy.opus

Convert .wav to .m4a:

fdkaac -o bg_creepy.m4a bg_creepy.wav  -b 64
  1. https://github.com/goldfire/howler.js/#src-arraystring--required
  2. https://github.com/goldfire/howler.js/blob/17c3d3d7aedc58f1d0ba1aa0fe94ddda6039e53a/src/howler.core.js#L277
ncase commented 3 years ago

Hi @erikdubbelboer ! Sorry I took so long to get around to pulling this (hiatus + i'm bad at emails + been stressed this past month). I didn't even know about the .opus file format, thanks for the tip for this & future projects!