audio_buses.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. :article_outdated: True
  2. .. _doc_audio_buses:
  3. Audio buses
  4. ===========
  5. Introduction
  6. ------------
  7. Godot's audio processing code has been written with games in mind, with the aim
  8. of achieving an optimal balance between performance and sound quality.
  9. Godot's audio engine allows any number of audio buses to be created and any
  10. number of effect processors can be added to each bus. Only the hardware of the
  11. device running your game will limit the number of buses and effects that can be
  12. used before performance starts to suffer.
  13. Decibel scale
  14. -------------
  15. Godot's sound interface is designed to meet the expectations of sound design
  16. professionals. To this end, it primarily uses the decibel scale.
  17. For those unfamiliar with it, it can be explained with a few facts:
  18. - The decibel (dB) scale is a relative scale. It represents the ratio of
  19. sound power by using 20 times the base 10 logarithm of the ratio
  20. (20 × log\ :sub:`10`\ (P/P\ :sub:`0`\ )).
  21. - For every 6 dB, sound amplitude doubles or halves. 12 dB represents a factor
  22. of 4, 18 dB a factor of 8, 20 dB a factor of 10, 40 dB a factor of 100, etc.
  23. - Since the scale is logarithmic, true zero (no audio) can't be represented.
  24. - 0 dB is the maximum amplitude possible in a digital audio system.
  25. This limit is not the human limit, but a limit from the sound hardware.
  26. Audio with amplitudes that are too high to be represented properly below 0 dB
  27. create a kind of distortion called *clipping*.
  28. - To avoid clipping, your sound mix should be arranged so that the output of the
  29. *master bus* (more on that later) never exceeds 0 dB.
  30. - Every 6 dB below the 0 dB limit, sound energy is *halved*.
  31. It means the sound volume at -6 dB is half as loud as 0dB.
  32. -12 dB is half as loud as -6 dB and so on.
  33. - When working with decibels, sound is considered no longer audible
  34. between -60 dB and -80 dB. This makes your working range generally
  35. between -60 dB and 0 dB.
  36. This can take a bit getting used to, but it's friendlier in the end
  37. and will allow you to communicate better with audio professionals.
  38. Audio buses
  39. -----------
  40. Audio buses can be found in the bottom panel of the Godot editor:
  41. .. image:: img/audio_buses1.png
  42. An *audio bus* (also called an *audio channel*) can be considered a place that
  43. audio is channeled through on the way to playback through a device's speakers.
  44. Audio data can be *modified* and *re-routed* by an audio bus. An audio bus
  45. has a VU meter (the bars that light up when sound is played) which indicates the
  46. amplitude of the signal passing through.
  47. The leftmost bus is the *master bus*. This bus outputs the mix to your speakers
  48. so, as mentioned in the *Decibel scale* section above, make sure that your mix
  49. level doesn't reach 0 dB in this bus. The rest of the audio buses can be
  50. flexibly routed. After modifying the sound, they send it to another bus to
  51. the left. The destination bus can be specified for each of the non-master audio
  52. buses. Routing always passes audio from buses on the right to buses further
  53. to the left. This avoids infinite routing loops.
  54. .. image:: img/audio_buses2.png
  55. In the above image, the output of *Bus 2* has been routed to the *Master* bus.
  56. Playback of audio through a bus
  57. -------------------------------
  58. To test passing audio to a bus, create an AudioStreamPlayer node, load an
  59. AudioStream and select a target bus for playback:
  60. .. image:: img/audio_buses3.png
  61. Finally, toggle the **Playing** property to **On** and sound will flow.
  62. .. seealso::
  63. You may also be interested in reading about :ref:`doc_audio_streams` now.
  64. Adding effects
  65. --------------
  66. .. warning::
  67. This feature is not supported on the web platform if the AudioStreamPlayer's
  68. playback mode is set to **Sample**, which is the default. It will only work if the
  69. playback mode is set to **Stream**, at the cost of increased latency if threads
  70. are not enabled.
  71. See :ref:`Audio playback in the Exporting for the Web documentation <doc_exporting_for_web_audio_playback>`
  72. for details.
  73. Audio buses can contain all sorts of effects. These effects modify the sound in
  74. one way or another and are applied in order.
  75. .. image:: img/audio_buses4.webp
  76. For information on what each effect does, see :ref:`doc_audio_effects`.
  77. Automatic bus disabling
  78. -----------------------
  79. There is no need to disable buses manually when not in use. Godot detects
  80. that the bus has been silent for a few seconds and disables it (including
  81. all effects).
  82. .. figure:: img/audio_buses5.png
  83. Disabled buses have a blue VU meter instead of a red-green one.
  84. Bus rearrangement
  85. -----------------
  86. Stream Players use bus names to identify a bus, which allows adding, removing
  87. and moving buses around while the reference to them is kept. However, if a bus
  88. is renamed, the reference will be lost and the Stream Player will output
  89. to Master. This system was chosen because rearranging buses is a more common
  90. process than renaming them.
  91. Default bus layout
  92. ------------------
  93. The default bus layout is automatically saved to the
  94. ``res://default_bus_layout.tres`` file. Custom bus arrangements can be saved
  95. and loaded from disk.