importing_audio_samples.rst 13 KB

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