importing_audio_samples.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. .. _doc_importing_audio_samples:
  2. Importing audio samples
  3. =======================
  4. Supported audio formats
  5. -----------------------
  6. Godot provides 3 options to import your audio data: WAV, Ogg Vorbis and MP3.
  7. Each format has different advantages:
  8. - WAV files use raw data or light compression (IMA-ADPCM). They are lightweight
  9. on the CPU to play back (hundreds of simultaneous voices in this format are
  10. fine). The downside is that they take up a lot of disk space.
  11. - Ogg Vorbis files use a stronger compression that results in much
  12. smaller file size, but require significantly more processing power to
  13. play back.
  14. - MP3 files use better compression than WAV with IMA-ADPCM, but worse than
  15. Ogg Vorbis. This means that a MP3 file with roughly equal quality to
  16. Ogg Vorbis will be significantly larger. On the bright side, MP3 requires
  17. less CPU usage to play back compared to Ogg Vorbis.
  18. .. note::
  19. If you've compiled the Godot editor from source with specific modules disabled,
  20. some formats may not be available.
  21. Here is a comparative chart representing the file size of 1 second of audio with
  22. each format:
  23. +-----------------------------+-------------------+
  24. | Format | 1 second of audio |
  25. +=============================+===================+
  26. | WAV 24-bit, 96 kHz, stereo | 576 KB |
  27. +-----------------------------+-------------------+
  28. | WAV 16-bit, 44 kHz, mono | 88 KB |
  29. +-----------------------------+-------------------+
  30. | WAV 16-bit, IMA-ADPCM, mono | 22 KB |
  31. +-----------------------------+-------------------+
  32. | MP3 192 Kb/s, stereo | 24 KB |
  33. +-----------------------------+-------------------+
  34. | Ogg Vorbis 128 Kb/s, stereo | 16 KB |
  35. +-----------------------------+-------------------+
  36. | Ogg Vorbis 96 Kb/s, stereo | 12 KB |
  37. +-----------------------------+-------------------+
  38. Note that the MP3 and Ogg Vorbis figures can vary depending on the encoding
  39. type. The above figures use :abbr:`CBR (Constant Bit Rate)` encoding for
  40. simplicity, but most Ogg Vorbis and MP3 files you can find online are encoded
  41. with :abbr:`VBR (Variable Bit Rate)` encoding which is more efficient.
  42. VBR encoding makes the effective audio file size depend on how "complex" the
  43. source audio is.
  44. .. tip::
  45. Consider using WAV for short and repetitive sound effects, and Ogg Vorbis for
  46. music, speech, and long sound effects. MP3 is useful for mobile and web projects
  47. where CPU resources are limited, especially when playing multiple compressed
  48. sounds at the same time (such as long ambient sounds).
  49. Importing audio samples
  50. -----------------------
  51. Several options are available in the Import dock after selecting a WAV file in
  52. the FileSystem dock:
  53. .. figure:: img/importing_audio_samples_import_options_wav.webp
  54. :align: center
  55. :alt: Import options in the Import dock after selecting a WAV file in the FileSystem dock
  56. Import options in the Import dock after selecting a WAV file in the FileSystem dock
  57. The set of options available after selecting a Ogg Vorbis or MP3 file is different:
  58. .. figure:: img/importing_audio_samples_import_options_mp3.webp
  59. :align: center
  60. :alt: Import options in the Import dock after selecting a MP3 file in the FileSystem dock
  61. Import options in the Import dock after selecting a MP3 file in the
  62. FileSystem dock. Options are identical for Ogg Vorbis files.
  63. After importing a sound, you can play it back using the AudioStreamPlayer,
  64. AudioStreamPlayer2D or AudioStreamPlayer3D nodes. See :ref:`doc_audio_streams`
  65. for more information.
  66. Import options (WAV)
  67. --------------------
  68. Force > 8 Bit
  69. -------------
  70. If enabled, forces the imported audio to use 8-bit quantization if the source
  71. file is 16-bit or higher.
  72. Enabling this is generally not recommended, as 8-bit quantization decreases
  73. audio quality significantly. If you need smaller file sizes, consider using Ogg
  74. Vorbis or MP3 audio instead.
  75. Force > Mono
  76. ------------
  77. If enabled, forces the imported audio to be mono if the source file is stereo.
  78. This decreases the file size by 50% by merging the two channels into one.
  79. Force > Max Rate
  80. ----------------
  81. If set to a value greater than ``0``, forces the audio's sample rate to be
  82. reduced to a value lower than or equal to the value specified here.
  83. This can decrease file size noticeably on certain sounds, without impacting
  84. quality depending on the actual sound's contents. See
  85. :ref:`doc_importing_audio_samples_best_practices` for more information.
  86. Edit > Trim
  87. -----------
  88. The source audio file may contain long silences at the beginning and/or the end.
  89. These silences are inserted by :abbr:`DAWs (Digital Audio Workstations)` when
  90. saving to a waveform, which increases their size unnecessarily and add latency
  91. to the moment they are played back.
  92. Enabling **Trim** will automatically trim the beginning and end of the audio if
  93. it's lower than -50 dB *after* normalization (see **Edit > Normalize** below). A
  94. fade-in/fade-out period of 500 samples is also used during trimming to avoid
  95. audible pops.
  96. Edit > Normalize
  97. ----------------
  98. If enabled, audio volume will be *normalized* so that its peak volume is equal
  99. to 0 dB. When enabled, normalization will make audio sound louder depending on
  100. its original peak volume.
  101. Edit > Loop Mode
  102. ----------------
  103. Unlike Ogg Vorbis and MP3, WAV files can contain metadata to indicate whether
  104. they're looping (in addition to loop points). By default, Godot will follow this
  105. metadata, but you can choose to apply a specific loop mode:
  106. - **Disabled:** Don't loop audio, even if metadata indicates the file should be
  107. played back looping.
  108. - **Forward:** Standard audio looping.
  109. - **Ping-Pong:** Play audio forward until it's done playing, then play it
  110. backward and repeat. This is similar to mirrored texture repeat, but for
  111. audio.
  112. - **Backward:** Play audio in reverse and loop back to the end when done playing.
  113. When choosing one of the **Forward**, **Ping-Pong** or **Backward** loop modes,
  114. loop points can also be defined to make only a specific part of the sound loop.
  115. **Loop Begin** is set in seconds after the beginning of the audio file. **Loop
  116. End** is also set in seconds after the beginning of the audio file, but will use
  117. the end of the audio file if set to ``-1``.
  118. .. warning::
  119. In AudioStreamPlayer, the ``finished`` signal won't be emitted for looping
  120. audio when it reaches the end of the audio file, as the audio will keep
  121. playing indefinitely.
  122. Compress > Mode
  123. ---------------
  124. Two compression modes can be chosen for WAV files: **Disabled** (default) or
  125. **RAM (Ima-ADPCM)**. **RAM (Ima-ADPCM)** reduces file size and memory usage a
  126. little, at the cost of decreasing quality in an audible manner.
  127. Ogg Vorbis and MP3 don't decrease quality as much and can provide greater file
  128. size reductions, at the cost of higher CPU usage during playback. This higher
  129. CPU usage is usually not a problem (especially with MP3), unless playing dozens
  130. of compressed sounds at the same time on mobile/web platforms.
  131. Import options (Ogg Vorbis and MP3)
  132. -----------------------------------
  133. Loop
  134. ^^^^
  135. If enabled, the audio will begin playing at the beginning after playback ends by
  136. reaching the end of the audio.
  137. .. warning::
  138. In AudioStreamPlayer, the ``finished`` signal won't be emitted for looping
  139. audio when it reaches the end of the audio file, as the audio will keep
  140. playing indefinitely.
  141. Loop Offset
  142. ^^^^^^^^^^^
  143. The loop offset determines where audio will start to loop after playback reaches
  144. the end of the audio. This can be used to only loop a part of the audio file,
  145. which is useful for some ambient sounds or music. The value is determined in
  146. seconds relative to the beginning of the audio, so ``0`` will loop the entire
  147. audio file.
  148. Only has an effect if **Loop** is enabled.
  149. A more convenient editor for **Loop Offset** is provided in the
  150. :ref:`Advanced import settings <doc_importing_audio_samples_advanced_import_settings>`
  151. dialog, as it lets you preview your changes without having to reimport the audio.
  152. BPM
  153. ^^^
  154. The Beats Per Minute of the audio track. This should match the BPM measure that
  155. was used to compose the track. This is only relevant for music that wishes to
  156. make use of interactive music functionality (not implemented yet), not sound
  157. effects.
  158. A more convenient editor for **BPM** is provided in the
  159. :ref:`Advanced import settings <doc_importing_audio_samples_advanced_import_settings>`
  160. dialog, as it lets you preview your changes without having to reimport the audio.
  161. Beat Count
  162. ^^^^^^^^^^
  163. The beat count of the audio track. This is only relevant for music that wishes
  164. to make use of interactive music functionality (not implemented yet), not sound
  165. effects.
  166. A more convenient editor for **Beat Count** is provided in the
  167. :ref:`Advanced import settings <doc_importing_audio_samples_advanced_import_settings>`
  168. dialog, as it lets you preview your changes without having to reimport the audio.
  169. Bar Beats
  170. ^^^^^^^^^
  171. The number of bars within a single beat in the audio track. This is only
  172. relevant for music that wishes to make use of interactive music functionality
  173. (not implemented yet), not sound effects.
  174. A more convenient editor for **Bar Beats** is provided in the
  175. :ref:`Advanced import settings <doc_importing_audio_samples_advanced_import_settings>`
  176. dialog, as it lets you preview your changes without having to reimport the audio.
  177. .. _doc_importing_audio_samples_advanced_import_settings:
  178. Advanced import settings (Ogg Vorbis and MP3)
  179. ---------------------------------------------
  180. If you double-click an Ogg Vorbis or MP3 file in the FileSystem dock (or choose
  181. **Advanced…** in the Import dock), you will see a dialog appear:
  182. .. figure:: img/importing_audio_samples_advanced_import_settings.webp
  183. :align: center
  184. :alt: Advanced dialog when double-clicking a Ogg Vorbis or MP3 file in the FileSystem dock
  185. Advanced dialog when double-clicking a Ogg Vorbis or MP3 file in the FileSystem dock
  186. This dialog allows you to edit the audio's loop point with a real-time preview,
  187. in addition to the :abbr:`BPM (Beats Per Minute)`, beat count and bar beats.
  188. These 3 settings are currently unused, but they will be used in the future for
  189. interactive music support (which allows smoothly transitioning between different
  190. music tracks).
  191. .. note::
  192. Unlike WAV files, Ogg Vorbis and MP3 only support a "loop begin" loop point,
  193. not a "loop end" point. Looping can also be only be standard forward
  194. looping, not ping-pong or backward.
  195. .. _doc_importing_audio_samples_best_practices:
  196. Best practices
  197. --------------
  198. Use appropriate quality settings
  199. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  200. While keeping pristine-quality audio sources is important if you're performing
  201. editing, using the same quality in the exported project is not necessary. For
  202. WAV files, Godot offers several import options to reduce the final file size
  203. without modifying the source file on disk.
  204. To reduce memory usage and file size, choose an appropriate quantization,
  205. sample rate and number of channels for your audio:
  206. - There's no *audible* benefit to using 24-bit audio, especially in a game
  207. where several sounds are often playing at the same time (which makes it
  208. harder to appreciate individual sounds).
  209. - Unless you are slowing down the audio at run-time, there's no *audible*
  210. benefit to using a sample rate greater than 48 kHz. If you wish to keep a
  211. source with a higher sample rate for editing, use the **Force > Max Rate**
  212. import option to limit the sample rate of the imported sound (only available
  213. for WAV files).
  214. - Many sound effects can generally be converted to mono as opposed to stereo.
  215. If you wish to keep a source with stereo for editing, use the **Force > Mono**
  216. import option to convert the imported sound to mono (only available for WAV files).
  217. - Voices can generally be converted to mono, but can also have their sample rate
  218. reduced to 22 kHz without a noticeable loss in quality (unless the voice is
  219. very high-pitched). This is because most human voices never go past 11 kHz.
  220. Use real-time audio effects to reduce file size
  221. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  222. Godot has an :ref:`extensive bus system <doc_audio_buses>` with built-in effects.
  223. This saves SFX artists the need to add reverb to the sound effects,
  224. reducing their size greatly and ensuring correct trimming.
  225. .. image:: img/reverb.png
  226. As you can see above, sound effects become much larger in file size with reverb
  227. added.