importing_audio_samples.rst 13 KB

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