MP3: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 1: Line 1:
'''MP3''' ('''MPEG Audio Layer III''') is a [[Wikipedia:Lossy compression|lossy]]-[[compression|compressed]] audio file format used by all of Valve's engines, and is available in all first-party titles. While engine limitations prevent it from being used for everything that [[WAV]] files can be used for, its smaller file sizes make it suitable for non-looping music or incidental ambient sounds in a [[Soundscape|soundscape]].
'''MP3''' ('''MPEG Audio Layer III''') is a [[Wikipedia:Lossy compression|lossy]]-[[compression|compressed]] audio file format used by all of Valve's engines, and is available in all first-party titles. While engine limitations prevent it from being used for everything that [[WAV]] files can be used for, its smaller file sizes make it suitable for non-looping music or incidental ambient sounds in a [[soundscape]].


{{warning|
{{warning|
* Using GoldSrc or Source 1's default implementation of MP3 in a commercial game requires paying for the [https://www.radgametools.com/miles.htm Miles Sound System license]. Consider implementing an alternative, such as Ogg {{wiki|Vorbis|icon=no}} or [https://github.com/misyltoad/VAudio-MiniMP3 minimp3].<br>{{strata|2}} and 64-bit version of the {{tf2branch|2}} use minimp3 by default.
* Using GoldSrc or Source 1's default implementation of MP3 in a commercial game requires paying for the [https://www.radgametools.com/miles.htm Miles Sound System license]. Consider implementing an alternative, such as Ogg {{wiki|Vorbis|icon=no}} or [https://github.com/misyltoad/VAudio-MiniMP3 minimp3].<br>{{strata|2}} and the 64-bit version of the {{tf2branch|2}} use minimp3 by default.
* MP3s '''''cannot''''' be [[looping a sound|properly looped]] in {{src|4}}! Looping can be simulated by scripting replaying the sound via [[entity I/O]] or code scripting, but there will be a gap.
* MP3s '''''cannot''''' be [[looping a sound|properly looped]] in {{src|4}}! Looping can be simulated by scripting replaying the sound via [[entity I/O]] or code scripting, but there will be a gap.
:* In {{src2|4}}, proper looping MP3s are possible ({{sboxwiki|Guide_to_Sounds#loopingsounds|only S&Box's tools can flag the VSND appropriately}}), but they can only loop in their entirety.
:* In {{src2|4}}, proper looping MP3s are possible ({{sboxwiki|Guide_to_Sounds#loopingsounds|only S&Box's tools can flag the VSND appropriately}}), but they can only loop in their entirety.

Revision as of 16:28, 15 June 2025

MP3 (MPEG Audio Layer III) is a lossy-compressed audio file format used by all of Valve's engines, and is available in all first-party titles. While engine limitations prevent it from being used for everything that WAV files can be used for, its smaller file sizes make it suitable for non-looping music or incidental ambient sounds in a soundscape.

Warning.pngWarning:
Note.pngNote:
  • MP3s with Wikipedia icon ID3 metadata will have that metadata in the soundcache (fixed in Garry's Mod). Avoid including metadata such as album art to prevent unnecessary bloat.
  • Many MP3 encoders will place ~100ms of silence before the sound to allow the sound to load. As such, MP3s are ill-suited to time-sensitive applications, where WAV should be used instead. If compression is necessary, see Compression (Source 1)#Audio Compression.

Recommended minimum bitrates

Unlike WAV, MP3 supports arbitrary bitrates, independent of sample rate and channel count. While this improves scalability, going below certain bitrates will result in noticeable quality degradation. Below are recommended minimum bitrates for the sample rates supported by all versions of Source Source (some third party games, as well as Source 2 Source 2, support Wikipedia icon additional sample rates).

Sample rate Mono (1 channel) Stereo (2 channels)
11025 Hz 32 kbps 64 kbps
22050 Hz
44100 Hz 64 kbps 128 kbps

These are just minimums. If you have the space to spare, you increase the bitrate for higher quality audio! Setting the bitrate to double the values listed above will result in a less aggressive low-pass filter (at least in Wikipedia icon LAME).

The maximums for each sample rate are different, as MP3 uses slightly different codecs for each sample rate:

Sample rate Max bitrate Codec
11025 Hz 64 kbps MPEG 2.5 Audio Layer III
22050 Hz 160 kbps MPEG 2 Audio Layer III
44100 Hz 320 kbps MPEG 1 Audio Layer III

See also

External links