音频流

简介

As you might have already read in 音频总线, sound is sent to each bus via an AudioStreamPlayer node. There are different kinds of AudioStreamPlayers. Each one loads an AudioStream and plays it back.

音频流

An audio stream is an abstract object that emits sound. The sound can come from many places, but is most commonly loaded from the filesystem. Audio files such as WAV (.wav) or Ogg Vorbis (.ogg) can be loaded as AudioStreams and placed inside an AudioStreamPlayer.

Here is a comparison of the two file types to help you choose the one that fits your use case best:

  • WAV files are quite large, but use little CPU power to play back. Hundreds of them can be played simultaneously with little impact on performance. This format is usually best for short sound effects.
  • Ogg Vorbis files are much smaller, but use considerably more CPU power to play back, so only a few can be played back at once (especially on mobile). This format works well for music, long sound effect sequences, and voice at relatively low bitrates.

Keep in mind that while WAV files may contain looping information in their metadata, Ogg Vorbis files do not. If looping an Ogg Vorbis file is desired, it must be set up using the import options:

../../_images/audio_stream_import1.png

There are other types of AudioStreamPlayer, such as AudioStreamRandomPitch. This one makes a random adjustment to the sound’s pitch every time it’s played back. This can be helpful for adding variation to sounds that are played back often.

AudioStreamPlayer

This is the standard, non-positional stream player. It can play to any bus. In 5.1 sound setups, it can send audio to stereo mix or front speakers.

AudioStreamPlayer2D

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.

注解

二维区域可以用来将声音从它们包含的任何二维音频流播放器转移到特定的总线。这使得创建具有不同混响或声音质量的总线成为可能,以处理在游戏世界的特定部分发生的动作。

../../_images/audio_stream_2d_area.png

AudioStreamPlayer3D

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 on the chosen audio setup.

与AudioStreamPlayer2D类似,Area可以将声音转移到音频总线。

../../_images/audio_stream_3d_area.png

与2D不同,AudioStreamPlayer的3D版本有一些更高级的选项:

混响总线

Godot allows for 3D audio streams that enter a specific Area node to send dry and wet audio to separate buses. This is useful when you have several reverb configurations for different types of rooms. This is done by enabling this type of reverb in the Reverb Bus section of the Area’s properties:

../../_images/audio_stream_reverb_bus.png

At the same time, a special bus layout is created where each area receives the reverb info from each area. A Reverb effect needs to be created and configured in each reverb bus to complete the setup for the desired effect:

../../_images/audio_stream_reverb_bus2.png

The Area’s Reverb Bus section also has a parameter named Uniformity. Some types of rooms bounce sounds more than others (like a warehouse), so reverberation can be heard almost uniformly across the room even though the source may be far away. Playing around with this parameter can simulate that effect.

多普勒

When the relative velocity between an emitter and listener changes, this is perceived as an increase or decrease in the pitch of the emitted sound. Godot can track velocity changes in the AudioStreamPlayer3D and Camera nodes. Both nodes have this property, which must be enabled manually:

../../_images/audio_stream_doppler.png

通过根据对象将如何被移动来启用他:对于使用 _process 来移动的对象,使用 Idle;对于使用 _physics_process 来移动的对象,使用 Physics 。追踪将自动发生。