audio_streams.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. .. _doc_audio-streams:
  2. Audio streams
  3. =============
  4. Introduction
  5. ------------
  6. As you might have already read in the :ref:`Audio Buses Tutorial<doc_audio-buses>` ,
  7. sound is sent to each bus via an AudioStreamPlayer.
  8. There are many types of AudioStreamPlayer, which will be explained in detail. Each one loads
  9. an AudioStream and plays it back.
  10. AudioStream
  11. -----------
  12. An audio stream is an abstract object that emits sound. It can come from many places, but most commonly
  13. from the filesystem. Audio files, such as .wav or .ogg, can be loaded as AudioStreams and placed
  14. inside an AudioStreamPlayer.
  15. Here is a comparison of the two, to help you choose which one fits your specific use case best:
  16. * Audio files of type *.wav* are quite large, but use little CPU power to play back. Hundreds of them can be played simultaneously with little impact to performance. This format is usually best for short sound effects, as the importer will trim and convert them to IMA-ADPCM.
  17. * Audio files of type *.ogg* are much smaller, but use considerably more CPU power to play back, so only a few can be played back (especially on mobile!). This format is usually best for music or long sound effect sequences. It also works well for voice at relatively low bitrates.
  18. Keep in mind neither .wav nor .ogg usually contains looping information, so this information must be set on the import options of each:
  19. .. image:: img/audio_stream_import.png
  20. There are other types of AudioStream, such as AudioStreamRandomPitch, which takes an existing AudioStream and modulates the pitch every time it's played back randomly (great for some sound effects),
  21. and more will keep appearing in the future.
  22. AudioStreamPlayer
  23. -----------------
  24. This is the standard stream player; it can play to any given bus. In 5.1 sound, it can send to stereo mix or front speakers.
  25. AudioStreamPlayer2D
  26. -------------------
  27. This is a variant of AudioStreamPlayer, but emits sound in a 2D positional environment. When close to the left of the screen, the panning will go left. When close to the right side, it will go right.
  28. While it's possible to send these effects to specific audio buses, one of the best strategies is to use an Area2D to divert sound to a specific bus. This allows you to create buses with different
  29. reverb or sound qualities and make it so the emitter will automatically send to them when entering the Area2D shapes.
  30. .. image:: img/audio_stream_2d_area.png
  31. AudioStreamPlayer3D
  32. -------------------
  33. This is a variant of AudioStreamPlayer, but emits sound in a 3D positional environment. Depending on the location of the player relative to the screen, it can position sound in Stereo, 5.1 or 7.1 depending
  34. on the chosen audio setup.
  35. Similar to AudioStreamPlayer2D, an Area can divert the sound to an audio bus.
  36. .. image:: img/audio_stream_3d_area.png
  37. Unlike for 2D, the 3D version of AudioStreamPlayer has a few more advanced options:
  38. Reverb buses
  39. ~~~~~~~~~~~~
  40. Godot allows 3D Audio Streams that enter a specific *Area* to send dry and wet audio to separate buses. This is useful when you have several reverb configurations for different types of rooms.
  41. This is done by enabling this type of reverb in the *Reverb Bus* section of *Area* properties:
  42. .. image:: img/audio_stream_reverb_bus.png
  43. At the same time, a special bus layout is created where each area receives the reverb info from each area. Of course, an actual Reverb effect must be created in that bus for anything to happen:
  44. .. image:: img/audio_stream_reverb_bus2.png
  45. The Area Reverb Bus section also has a specific parameter named "Uniformity". Some types of rooms bounce sounds more than others (like for example, a typical warehouse), so reverberation can be heard
  46. almost uniformly across the room even though the source is far away. Playing around with this parameter can simulate that effect.
  47. Doppler
  48. ~~~~~~~
  49. When the relative velocity between an emitter and listener changes, this is perceived as an increase or decrease of the pitch shift. Godot can track changes in velocities of *AudioStreamPlayer3D* or *Camera*.
  50. Both have this property, which must be enabled manually:
  51. .. image:: img/audio_stream_doppler.png
  52. Simply enable it by setting it depending on how objects will be moved (whether on regular *process* or *physics_process* step) and the tracking will happen automatically!