audio_streams.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. .. _doc_audio_streams:
  2. Audio streams
  3. =============
  4. Introduction
  5. ------------
  6. As you might have already read in :ref:`doc_audio_buses`, sound is sent to
  7. each bus via an AudioStreamPlayer node. There are different kinds
  8. of AudioStreamPlayers. Each one loads an AudioStream and plays it back.
  9. AudioStream
  10. -----------
  11. An audio stream is an abstract object that emits sound. The sound can come from
  12. many places, but is most commonly loaded from the filesystem. Audio files such
  13. as WAV (``.wav``) or Ogg Vorbis (``.ogg``) can be loaded as AudioStreams and
  14. placed inside an AudioStreamPlayer.
  15. Here is a comparison of the two file types to help you choose the one that fits
  16. your use case best:
  17. - WAV files are quite large, but use little CPU power to play back.
  18. Hundreds of them can be played simultaneously with little impact
  19. on performance. This format is usually best for short sound effects.
  20. - Ogg Vorbis files are much smaller, but use considerably more CPU power
  21. to play back, so only a few can be played back at once (especially on mobile).
  22. This format works well for music, long sound effect sequences, and voice
  23. at relatively low bitrates.
  24. Keep in mind that while WAV files may contain looping information in their metadata,
  25. Ogg Vorbis files do not. If looping an Ogg Vorbis file is desired,
  26. it must be set up using the import options:
  27. .. image:: img/audio_stream_import.png
  28. There are other types of AudioStreamPlayer, such as AudioStreamRandomPitch.
  29. This one makes a random adjustment to the sound's pitch every time it's
  30. played back. This can be helpful for adding variation to sounds that are
  31. played back often.
  32. AudioStreamPlayer
  33. -----------------
  34. This is the standard, non-positional stream player. It can play to any bus.
  35. In 5.1 sound setups, it can send audio to stereo mix or front speakers.
  36. AudioStreamPlayer2D
  37. -------------------
  38. This is a variant of AudioStreamPlayer, but emits sound in a 2D positional
  39. environment. When close to the left of the screen, the panning will go left.
  40. When close to the right side, it will go right.
  41. .. note::
  42. Area2Ds can be used to divert sound from any AudioStreamPlayer2Ds they
  43. contain to specific buses. This makes it possible to create buses with
  44. different reverb or sound qualities to handle action happening in a
  45. particular parts of your game world.
  46. .. image:: img/audio_stream_2d_area.png
  47. AudioStreamPlayer3D
  48. -------------------
  49. This is a variant of AudioStreamPlayer, but emits sound in a 3D positional
  50. environment. Depending on the location of the player relative to the screen,
  51. it can position sound in stereo, 5.1 or 7.1 depending on the chosen audio setup.
  52. Similar to AudioStreamPlayer2D, an Area can divert the sound to an audio bus.
  53. .. image:: img/audio_stream_3d_area.png
  54. Unlike for 2D, the 3D version of AudioStreamPlayer has a few more advanced options:
  55. .. _doc_audio_streams_reverb_buses:
  56. Reverb buses
  57. ~~~~~~~~~~~~
  58. Godot allows for 3D audio streams that enter a specific Area node to send dry
  59. and wet audio to separate buses. This is useful when you have several reverb
  60. configurations for different types of rooms. This is done by enabling this type
  61. of reverb in the **Reverb Bus** section of the Area's properties:
  62. .. image:: img/audio_stream_reverb_bus.png
  63. At the same time, a special bus layout is created where each area receives the
  64. reverb info from each area. A Reverb effect needs to be created and configured
  65. in each reverb bus to complete the setup for the desired effect:
  66. .. image:: img/audio_stream_reverb_bus2.png
  67. The Area's **Reverb Bus** section also has a parameter named **Uniformity**.
  68. Some types of rooms bounce sounds more than others (like a warehouse), so
  69. reverberation can be heard almost uniformly across the room even though the
  70. source may be far away. Playing around with this parameter can simulate
  71. that effect.
  72. Doppler
  73. ~~~~~~~
  74. When the relative velocity between an emitter and listener changes, this is
  75. perceived as an increase or decrease in the pitch of the emitted sound.
  76. Godot can track velocity changes in the AudioStreamPlayer3D and Camera nodes.
  77. Both nodes have this property, which must be enabled manually:
  78. .. image:: img/audio_stream_doppler.png
  79. Enable it by setting it depending on how objects will be moved:
  80. use **Idle** for objects moved using ``_process``, or **Physics**
  81. for objects moved using ``_physics_process``. The tracking will
  82. happen automatically.