importing_audio_samples.rst 13 KB

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