Skip to content

Commit

Permalink
Add .opus and .m4a sounds
Browse files Browse the repository at this point in the history
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 .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
  • Loading branch information
erikdubbelboer committed Jul 20, 2021
1 parent ed36f0b commit 15c3295
Show file tree
Hide file tree
Showing 37 changed files with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions js/core/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ Game.loadAssets = function(completeCallback, progressCallback, PRELOADER){

// Is MP3. Leave it to Howler.
if(src.slice(-4)==".mp3"){
var sound = new Howl({ src:[src] });
var sound = new Howl({ src:[
src.slice(0, src.length-4)+".opus",
src.slice(0, src.length-4)+".m4a",
src
] });
_soundsToLoad++;
sound.once('load', _onSoundLoad);
Game.sounds[key] = sound;
Expand All @@ -174,4 +178,4 @@ Game.addToManifest = function(keyValues, PRELOADER){
}
};

})(window);
})(window);
Binary file added sounds/bg_creepy.m4a
Binary file not shown.
Binary file added sounds/bg_creepy.opus
Binary file not shown.
Binary file added sounds/bg_nighttime.m4a
Binary file not shown.
Binary file added sounds/bg_nighttime.opus
Binary file not shown.
Binary file added sounds/bg_panic.m4a
Binary file not shown.
Binary file added sounds/bg_panic.opus
Binary file not shown.
Binary file added sounds/bg_park.m4a
Binary file not shown.
Binary file added sounds/bg_park.opus
Binary file not shown.
Binary file added sounds/breaking_news.m4a
Binary file not shown.
Binary file added sounds/breaking_news.opus
Binary file not shown.
Binary file added sounds/cam_snap.m4a
Binary file not shown.
Binary file added sounds/cam_snap.opus
Binary file not shown.
Binary file added sounds/crickets.m4a
Binary file not shown.
Binary file added sounds/crickets.opus
Binary file not shown.
Binary file added sounds/gun_cock.m4a
Binary file not shown.
Binary file added sounds/gun_cock.opus
Binary file not shown.
Binary file added sounds/gunshot.m4a
Binary file not shown.
Binary file added sounds/gunshot.opus
Binary file not shown.
Binary file added sounds/impact.m4a
Binary file not shown.
Binary file added sounds/impact.opus
Binary file not shown.
Binary file added sounds/peep_gasp.m4a
Binary file not shown.
Binary file added sounds/peep_gasp.opus
Binary file not shown.
Binary file added sounds/peep_hmph.m4a
Binary file not shown.
Binary file added sounds/peep_hmph.opus
Binary file not shown.
Binary file added sounds/peep_hngh.m4a
Binary file not shown.
Binary file added sounds/peep_hngh.opus
Binary file not shown.
Binary file added sounds/peep_huh.m4a
Binary file not shown.
Binary file added sounds/peep_huh.opus
Binary file not shown.
Binary file added sounds/scream.m4a
Binary file not shown.
Binary file added sounds/scream.opus
Binary file not shown.
Binary file added sounds/shotgun.m4a
Binary file not shown.
Binary file added sounds/shotgun.opus
Binary file not shown.
Binary file added sounds/shout.m4a
Binary file not shown.
Binary file added sounds/shout.opus
Binary file not shown.
Binary file added sounds/squeak.m4a
Binary file not shown.
Binary file added sounds/squeak.opus
Binary file not shown.

0 comments on commit 15c3295

Please sign in to comment.