phetsims / quadrilateral

"Quadrilateral" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
1 stars 3 forks source link

Reduce size of sound files #345

Closed jessegreenberg closed 1 year ago

jessegreenberg commented 1 year ago

In https://github.com/phetsims/quadrilateral/issues/335 @jbphet mentioned there is a process for reducing the size of sound files. There are ~15 sound files in this sim that play for ~16 seconds. The sounds directory is ~10 MB (12% of the entire sim), lets see if we can reduce the size.

For reference, the size of the sounds directory in greenhouse-effect is around 3.5 MB.

jessegreenberg commented 1 year ago

The documentation about this is in encoding-audio.md.

jessegreenberg commented 1 year ago

Here is the content

A fair amount of testing was done to determine the optimum tradeoff between audio file size and quality.  The
current recommendations are:

+ Always keep the full .wav file around in the `assets` direction so that we can re-encode if needed.
+ The .wav file should use a sample rate of 44.1 kHz, since it is the most commonly supported frequency for audio
  contexts, so re-sampling will not be required in most cases.
+ Audio files used in the sim code should be in .mp3 format in almost all cases, encoded at a variable bit rate of
  65-105 kbps unless a higher resolution is needed.  One exception to this is if a loop is needed with continuous sound
  playing.  Due to the short silence that generally exists at the beginning of an .mp3 file, a .wav file is sometimes
  required. 
+ Mono sounds should be used unless there is a specific sound-design need for stereo sounds.
+ Sounds should be encoded such that their peak output is at -1 dBFS.  For amplitude (but not power), this is a
  numerical value of about 0.891.

See https://github.com/phetsims/tambo/issues/28 and https://github.com/phetsims/tambo/issues/5 for more information
about the history of and thought processes behind these recommendations.

These recommendations are about the encoding. @Ashton-Morris can you review this list and recommend if there is anything we can do to reduce the size of files?

Ashton-Morris commented 1 year ago

I have copied all of these files

From https://github.com/phetsims/quadrilateral/tree/master/sounds this repository and Batch converted them to 64kbps - mono- normalized at -1db.

On my machine this entire folder of sounds is now 1.6MB.

I have added the files to this folder Small Sound Filesfor you to grab and switch out.

If there are any files I missed please let me know.

jessegreenberg commented 1 year ago

OK, I replaced the sounds - including the modulified .js, files the sounds directory is now 3.5 MB, down from ~10.

However, the quality reduction between this and the latest dev version is pretty noticeable (compared to https://phet-dev.colorado.edu/html/quadrilateral/1.0.0-dev.73/phet/quadrilateral_all_phet_debug.html). In particular, its harder for me to hear the percussion tracks and quadMelodyTracks004_mp3 doesn't come through as clearly.

@BLFiedler @Ashton-Morris can you please listen to master and comment on whether this is OK or if we should revert and consider accepting larger file sizes?

brettfiedler commented 1 year ago

Compared master to dev73.

I think the volumes of both of those tracks were lowered a bunch intentionally. Do we think the volume mapping is behaving differently with the modulified .js files? I think it actually might be working better than it previously did.

The base beat is may be a bit low, but quadMelodyTracks004_mp3 in Rhombus is in line with what I had adjusted for. Adding an adjustment to both beat tracks in a commit after this. Only raising them slightly. They still come across as too punchy and overbearing (to me) when raised as high as 0.75 of max (currently 0.5).

There's definitely a quality difference. It's not game-changing, but definitely noticeable if you're familiar with both or listen sequentially. Is this anything we can adjust without reverting to the larger filesize? Maybe a question for @Ashton-Morris, too.

Ashton-Morris commented 1 year ago

When we lower the Bitrate on these mp3s its going to leave the low parts pretty much intact but truncate the high parts.

So if its feeling like a little too muffled or there is a track where the high parts are more important than the others. I can give that one a slightly higher bitrate and leave the others as is. This is will increase the overall quality but raise the file size very little.

jessegreenberg commented 1 year ago

Great, thanks @Ashton-Morris! Ill assign to @BLFiedler to comment on next steps and review.

brettfiedler commented 1 year ago

@Ashton-Morris, can you take a quick review of this to note which tracks might benefit from higher bit rates?

Ashton-Morris commented 1 year ago

I listened to these very closely and I think the audio quality is comparable to that of higher bit rates. I think what was missing was the dynamics and magic that some of the tracks had while in Stereo (the smaller files were all bounced to Mono)

So I listened to all of the tracks and converted a few of them to Stereo and 96kbps which is a little higher bit rate. They are still around 188KB.

These files are in this folder https://drive.google.com/drive/folders/1dEa7U9d2vjiTu9UtTp92Z4e1Jq7Ov5wo?usp=share_link

brettfiedler commented 1 year ago

Thanks so much @Ashton-Morris. Go ahead and implement those variants @jessegreenberg , and then onto the file renaming!

jessegreenberg commented 1 year ago

That is awesome, nice @Ashton-Morris! They sound way better and hardly take up that much more space. @BLFiedler @Ashton-Morris anything else for this issue?

brettfiedler commented 1 year ago

All good! Thanks @jessegreenberg and @Ashton-Morris