音频流
前言
正如你可能已经在 音频总线 中读到的一样, 声音通过AudioStreamPlayer节点发送到每个总线.AudioStreamPlayer有很多种. 每一个都会加载一个AudioStream并进行播放.
AudioStream
音频流(audio stream)是一种发出声音的抽象对象. 声音可以来自许多地方, 最常见的是从文件系统加载. 音频文件可以作为AudioStreams加载并放置在AudioStreamPlayer中. 你可以在 导入音频采样 中找到有关支持的格式和格式差异的信息.
There are other types of AudioStreams, such as AudioStreamRandomizer. This one picks a different audio stream from a list of streams each time it’s played back, and applies random pitch and volume shifting. This can be helpful for adding variation to sounds that are played back often.
AudioStreamPlayer
这是一个标准的, 非位置型的流播放器, 可以播放到任意总线. 在5.1立体声中, 它可以将音频发送到立体声混音或前置扬声器.
Playback Type is an experimental setting, and could change in future versions of Godot. It exists so Web exports use Web Audio-API based samples instead of streaming all sounds to the browser, unlike most platforms. This prevents the audio from being garbled in single-threaded Web exports. By default, only the Web platform will use samples. Changing this setting is not recommended, unless you have an explicit reason to. You can change the default playback type for the web and other platforms in the project settings under Audio > General (advanced settings must be turned on to see the setting).
AudioStreamPlayer2D
这是AudioStreamPlayer的一种变体, 它将声音发散到2D位置环境中. 当靠近屏幕左侧时, 声像将向左偏移. 靠近右侧时, 则向右偏移.
备注
Area2D可以将它们包含的AudioStreamPlayer2D的声音转移到特定的总线上. 这样就可以创造具有不同混响或声音质量的总线, 从而处理在游戏世界的特定区域中发生的动作.
AudioStreamPlayer3D
这是AudioStreamPlayer的一种变体, 它将声音发散到3D位置环境中. 根据播放器相对于屏幕的位置, 它可以将声音定位在立体声(5.1或7.1)中, 具体取决于所选的音频设置.
Similar to AudioStreamPlayer2D, an Area3D can divert the sound to an audio bus.
与2D不同,AudioStreamPlayer的3D版本有一些更高级的选项:
混响总线
Godot allows for 3D audio streams that enter a specific Area3D 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 Area3D’s properties:
At the same time, a special bus layout is created where each Area3D receives the reverb info from each Area3D. A Reverb effect needs to be created and configured in each reverb bus to complete the setup for the desired effect:
The Area3D’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.
多普勒
当发射源和接收者之间的相对速度发生变化时, 发出声音的音高会随之升高/降低.Godot可以跟踪AudioStreamPlayer3D和Camera节点的速度变化. 这两个节点都有这个属性, 需要手动启用:
根据对象的移动方法选择启用设置: 如果用 _process
来移动, 选择 Idle ;如果使用 _physics_process
来移动, 选择 Physics . 追踪将自动进行.