importing_audio_samples.rst 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. .. _doc_importing_audio_samples:
  2. Importing audio samples
  3. =======================
  4. Why importing?
  5. --------------
  6. Importing Audio Samples into the game engine is a process that should be
  7. easier than it really is. Most readers are probably thinking "Why not
  8. just copy the wav files to a folder inside the project and be over
  9. with it?"
  10. It's not usually that simple. Most game engines use uncompressed audio
  11. (in memory, at least) for sound effects. The reason for this is because
  12. it's really cheap to play back and resample. Compressed streamed audio
  13. (such as ogg files) takes a large amount of processor to decode so no
  14. more than one or two are streamed simultaneously. However, with sound
  15. effects, one expects a dozen of them to be playing at the same time in
  16. several situations.
  17. Because of this, sound effects are loaded uncompressed into memory, and
  18. here is where the problems begin.
  19. As is usual with graphics, the situation where programmers don't really
  20. know about audio and audio engineers don't know about programming is
  21. also common in the industry. This leads to a scenario where a project
  22. ends up wasting resources unnecessarily.
  23. To be more precise, SFX artists tend to work with audio formats that
  24. give them a lot of room for tweaking the audio with a low noise floor and
  25. minimum aliasing, such as 96kHz, 24 bits. In many cases, they work in
  26. stereo too. Added to that, many times they add effects with an infinite
  27. or really long fadeout, such as reverb, which leads to apparent trailing
  28. silences. Finally, many DAWs also add silence at the beginning when
  29. normalizing to wav.
  30. These often result in extremely large files to integration into a game engine
  31. with sound effects taking dozens of megabytes.
  32. How much does quality matter?
  33. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. First of all, it is important to know that Godot has an internal reverb
  35. generator. Sound effects can go to four different setups (small, medium
  36. and large room, as well as hall), with different send amounts. This saves
  37. SFX artists the need to add reverb to the sound effects, reducing their
  38. size greatly and ensuring correct trimming. Say no to SFX with baked
  39. reverb!
  40. .. image:: /img/reverb.png
  41. Another common problem is that, while it's useful for working inside a
  42. DAW, high bit depths (24 bits) and high sampling rate (96kHz) are
  43. completely unnecessary for use in a game, as there is no `audible
  44. difference <http://www.youtube.com/watch?v=cIQ9IXSUzuM>`__. If
  45. positional sound is going to be used (for 2D and 3D), the panning and
  46. stereo reverb will be provided by the engine, so there is little need
  47. for stereo sound. How does this affect the resource usage? Look at the
  48. following comparison:
  49. +---------------------------+---------------------+--------------+
  50. | Format | 1 Second of Audio | Frame Size |
  51. +===========================+=====================+==============+
  52. | 24 bits, 96 kHz, Stereo | 576kb | 12 |
  53. +---------------------------+---------------------+--------------+
  54. | 16 bits, 44 kHz, Mono | 88kb | 2 |
  55. +---------------------------+---------------------+--------------+
  56. | 16 bits, IMA-ADPCM | 22kb | 1/2 |
  57. +---------------------------+---------------------+--------------+
  58. As seen, for being no audible difference, the 16 bits, 44kHz, mono conversion
  59. takes *6 times less memory* than the 24 bits, 96kHz, Stereo version. The
  60. IMA-ADPCM version (using computationally-light audio compression) takes *24
  61. times less memory* than what was exported from the DAW.
  62. Trimming
  63. ~~~~~~~~
  64. One last issue that happens often is that the waveform files received
  65. have silences at the beginning and at the end. These are inserted by
  66. DAWs when saving to a waveform, increase their size unnecessarily and
  67. add latency to the moment they are played back. Trimming them solves
  68. this, but it takes effort for the SFX artist, as they have to do it in a
  69. separate application. In the worst case, they may not even know the
  70. silences are being added.
  71. .. image:: /img/trim.png
  72. Importing audio samples
  73. -----------------------
  74. Godot has a simple screen for importing audio samples to the engine. SFX
  75. artists only have to save the wav files to a folder outside the
  76. project, and the import dialog will fix the files for inclusion, as well
  77. as doing it automatically every time they are modified and re-imported.
  78. .. image:: /img/importaudio.png
  79. In this screen, the quality of the audio can be limited to what is
  80. needed, and trimming is done automatically. In addition, several samples
  81. can be loaded and batch-converted, just as textures can.
  82. Looping
  83. ~~~~~~~
  84. Godot supports looping in the samples (Tools such as Sound Forge or
  85. Audition can add loop points to wav files). This is useful for sound
  86. effects such as engines, machine guns, etc. Ping-pong looping is also
  87. supported.
  88. As an alternative, the import screen has a "loop" option that enables
  89. looping for the entire sample when importing.