audio_buses.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. .. _doc_audio_buses:
  2. Audio buses
  3. ===========
  4. Introduction
  5. ------------
  6. Godot's audio processing code has been written with games in mind, with the aim
  7. of achieving an optimal balance between performance and sound quality.
  8. Godot's audio engine allows any number of audio buses to be created and any
  9. number of effect processors can be added to each bus. Only the hardware of the
  10. device running your game will limit the number of buses and effects that can be
  11. used before performance starts to suffer.
  12. Decibel scale
  13. -------------
  14. Godot's sound interface is designed to meet the expectations of sound design
  15. professionals. To this end, it primarily uses the decibel scale.
  16. For those unfamiliar with it, it can be explained with a few facts:
  17. - The decibel (dB) scale is a relative scale. It represents the ratio of
  18. sound power by using 20 times the base 10 logarithm of the ratio
  19. (20 × log\ :sub:`10`\ (P/P\ :sub:`0`\ )).
  20. - For every 6 dB, sound amplitude doubles or halves. 12 dB represents a factor
  21. of 4, 18 dB a factor of 8, 20 dB a factor of 10, 40 dB a factor of 100, etc.
  22. - Since the scale is logarithmic, true zero (no audio) can't be represented.
  23. - 0 dB is the maximum amplitude possible in a digital audio system.
  24. This limit is not the human limit, but a limit from the sound hardware.
  25. Audio with amplitudes that are too high to be represented properly below 0 dB
  26. create a kind of distortion called *clipping*.
  27. - To avoid clipping, your sound mix should be arranged so that the output of the
  28. *master bus* (more on that later) never exceeds 0 dB.
  29. - Every 6 dB below the 0 dB limit, sound energy is *halved*.
  30. It means the sound volume at -6 dB is half as loud as 0dB.
  31. -12 dB is half as loud as -6 dB and so on.
  32. - When working with decibels, sound is considered no longer audible
  33. between -60 dB and -80 dB. This makes your working range generally
  34. between -60 dB and 0 dB.
  35. This can take a bit getting used to, but it's friendlier in the end
  36. and will allow you to communicate better with audio professionals.
  37. Audio buses
  38. -----------
  39. Audio buses can be found in the bottom panel of the Godot editor:
  40. .. image:: img/audio_buses1.png
  41. An *audio bus* (also called an *audio channel*) can be considered a place that
  42. audio is channeled through on the way to playback through a device's speakers.
  43. Audio data can be *modified* and *re-routed* by an audio bus. An audio bus
  44. has a VU meter (the bars that light up when sound is played) which indicates the
  45. amplitude of the signal passing through.
  46. The leftmost bus is the *master bus*. This bus outputs the mix to your speakers
  47. so, as mentioned in the *Decibel scale* section above, make sure that your mix
  48. level doesn't reach 0 dB in this bus. The rest of the audio buses can be
  49. flexibly routed. After modifying the sound, they send it to another bus to
  50. the left. The destination bus can be specified for each of the non-master audio
  51. buses. Routing always passes audio from buses on the right to buses further
  52. to the left. This avoids infinite routing loops.
  53. .. image:: img/audio_buses2.png
  54. In the above image, the output of *Bus 2* has been routed to the *Master* bus.
  55. Playback of audio through a bus
  56. -------------------------------
  57. To test passing audio to a bus, create an AudioStreamPlayer node, load an
  58. AudioStream and select a target bus for playback:
  59. .. image:: img/audio_buses3.png
  60. Finally, toggle the **Playing** property to **On** and sound will flow.
  61. .. seealso::
  62. You may also be interested in reading about :ref:`doc_audio_streams` now.
  63. Adding effects
  64. --------------
  65. Audio buses can contain all sorts of effects. These effects modify the sound in
  66. one way or another and are applied in order.
  67. .. image:: img/audio_buses4.png
  68. Try them all out to get a sense of how they alter sound. Here follows a short
  69. description of the available effects:
  70. Amplify
  71. ~~~~~~~
  72. Amplify changes the amplitude of the signal. Some care needs to be taken.
  73. Setting the level too high can make the sound clip, which is usually
  74. undesirable.
  75. BandLimit and BandPass
  76. ~~~~~~~~~~~~~~~~~~~~~~
  77. These are resonant filters which block frequencies around the *Cutoff* point.
  78. BandPass can be used to simulate sound passing through an old telephone line or
  79. megaphone. Modulating the BandPass frequency can simulate the sound of a wah-wah
  80. guitar pedal, think of the guitar in Jimi Hendrix's *Voodoo Child (Slight
  81. Return)*.
  82. Capture
  83. ~~~~~~~
  84. The Capture effect copies the audio frames of the audio bus that it is on into
  85. an internal buffer. This can be used to capture data from the microphone
  86. or to transmit audio over the network in real-time.
  87. Chorus
  88. ~~~~~~
  89. The Chorus effect duplicates the incoming audio, delays the duplicate slightly
  90. and uses an LFO to continuously modulate the pitch of the duplicated signal
  91. before mixing the duplicated signal(s) and the original together again. This
  92. creates a shimmering effect and adds stereo width to the sound.
  93. Compressor
  94. ~~~~~~~~~~
  95. A dynamic range compressor automatically attenuates the level of the incoming
  96. signal when its amplitude exceeds a certain threshold. The level of attenuation
  97. applied is proportional to how far the incoming audio exceeds the threshold.
  98. The compressor's Ratio parameter controls the degree of attenuation.
  99. One of the main uses of a compressor is to reduce the dynamic range of signals
  100. with very loud and quiet parts. Reducing the dynamic range of a signal
  101. can make it easier to mix.
  102. The compressor has many uses. For example:
  103. - It can be used in the Master bus to compress the whole output.
  104. - It can be used in voice channels to ensure they sound as even as possible.
  105. - It can be *sidechained*. This means it can reduce the sound level
  106. of one signal using the level of another audio bus for threshold detection.
  107. This technique is very common in video game mixing to "duck" the level of
  108. music or sound effects when voices need to be heard.
  109. - It can accentuate transients by using a slower attack.
  110. This can make sound effects more punchy.
  111. .. note::
  112. If your goal is to prevent a signal from exceeding a given amplitude
  113. altogether, rather than to reduce the dynamic range of the signal,
  114. a :ref:`limiter <doc_audio_buses_limiter>` is likely a better choice
  115. than a compressor.
  116. Delay
  117. ~~~~~
  118. Adds an "echo" effect with a feedback loop. It can be used together
  119. with *Reverb* to simulate wide rooms, canyons, etc. where sound bounces
  120. are far apart.
  121. Distortion
  122. ~~~~~~~~~~
  123. Makes the sound distorted. Godot offers several types of distortion: *overdrive*,
  124. *tan* and *bit crushing*. Distortion can be used to simulate sound coming through
  125. a low-quality speaker or device.
  126. EQ
  127. ~~
  128. EQ is what all other equalizers inherit from. It can be extended with with Custom
  129. scripts to create an equalizer with a custom number of bands.
  130. EQ6, EQ10, EQ21
  131. ~~~~~~~~~~~~~~~
  132. Godot provides three equalizers with different numbers of bands. An equalizer on
  133. the Master bus can be useful to cut frequencies that the device's speakers can't
  134. reproduce well (e.g. a mobile phone's speakers won't reproduce bass content
  135. well). The equalizer effect can be disabled when headphones are plugged in.
  136. Filter
  137. ~~~~~~
  138. Filter is what all other filters inherit from and should not be used directly.
  139. HighPassFilter
  140. ~~~~~~~~~~~~~~
  141. Cuts frequencies below a specific *Cutoff* frequency.
  142. HighPassFilter is used to reduce the bass content of a
  143. signal.
  144. HighShelfFilter
  145. ~~~~~~~~~~~~~~~
  146. Reduces all frequencies above a specific *Cutoff* frequency.
  147. .. _doc_audio_buses_limiter:
  148. Limiter
  149. ~~~~~~~
  150. A limiter is similar to a compressor, but it's less flexible and designed to
  151. prevent a signal's amplitude exceeding a given dB threshold. Adding a limiter to
  152. the Master bus is a safeguard against clipping.
  153. LowPassFilter
  154. ~~~~~~~~~~~~~
  155. Cuts frequencies above a specific *Cutoff* frequency and can also resonate
  156. (boost frequencies close to the *Cutoff* frequency). Low pass filters can be
  157. used to simulate "muffled" sound. For instance, underwater sounds, sounds
  158. blocked by walls, or distant sounds.
  159. LowShelfFilter
  160. ~~~~~~~~~~~~~~
  161. Reduces all frequencies below a specific *Cutoff* frequency.
  162. NotchFilter
  163. ~~~~~~~~~~~
  164. The opposite of the BandPassFilter, it removes a band of sound from the
  165. frequency spectrum at a given *Cutoff* frequency.
  166. Panner
  167. ~~~~~~
  168. The Panner allows the stereo balance of a signal to be adjusted between
  169. the left and right channels (wear headphones to audition this effect).
  170. Phaser
  171. ~~~~~~
  172. It probably does not make much sense to explain that this effect is formed by
  173. two signals being dephased and cancelling each other out. You can make a Darth
  174. Vader voice with it, or jet-like sounds.
  175. PitchShift
  176. ~~~~~~~~~~
  177. This effect allows the adjustment of the signal's pitch independently of its
  178. speed. All frequencies can be increased/decreased with minimal effect on
  179. transients. PitchShift can be useful to create unusually high or deep voices.
  180. Record
  181. ~~~~~~
  182. The Record effect allows the user to record sound from a microphone.
  183. Reverb
  184. ~~~~~~
  185. Reverb simulates rooms of different sizes. It has adjustable parameters that can
  186. be tweaked to obtain the sound of a specific room. Reverb is commonly outputted
  187. from :ref:`Areas <class_Area>`
  188. (see :ref:`Reverb buses <doc_audio_streams_reverb_buses>`), or to apply
  189. a "chamber" feel to all sounds.
  190. SpectrumAnalyzer
  191. ~~~~~~~~~~~~~~~~
  192. This effect doesn't alter audio, instead, you add this effect to buses you want
  193. a spectrum analysis of. This would typically be used for audio visualization. A
  194. demo project using this can be found `here <https://github.com/godotengine/godot-demo-projects/tree/master/audio/spectrum>`__.
  195. StereoEnhance
  196. ~~~~~~~~~~~~~
  197. This effect uses a few algorithms to enhance a signal's stereo spectrum.
  198. Automatic bus disabling
  199. -----------------------
  200. There is no need to disable buses manually when not in use. Godot detects
  201. that the bus has been silent for a few seconds and disables it (including
  202. all effects).
  203. .. figure:: img/audio_buses5.png
  204. Disabled buses have a blue VU meter instead of a red-green one.
  205. Bus rearrangement
  206. -----------------
  207. Stream Players use bus names to identify a bus, which allows adding, removing
  208. and moving buses around while the reference to them is kept. However, if a bus
  209. is renamed, the reference will be lost and the Stream Player will output
  210. to Master. This system was chosen because rearranging buses is a more common
  211. process than renaming them.
  212. Default bus layout
  213. ------------------
  214. The default bus layout is automatically saved to the
  215. ``res://default_bus_layout.tres`` file. Custom bus arrangements can be saved
  216. and loaded from disk.