Work in progress
The content of this page was not yet updated for Godot
4.4
and may be outdated. If you know how to improve this page or you can confirm
that it's up to date, feel free to open a pull request.
音频流
前言
你可能已经在《音频总线》中读到过,声音通过 AudioStreamPlayer 节点发送到每条总线。有不同类型的 AudioStreamPlayer。每种 AudioStreamPlayer 都会加载一个 AudioStream 并播放它。
AudioStream(音频流)
音频流是一种产生声音的抽象对象。声音可以来自许多地方,但最常见的是从文件系统加载。音频文件可以作为 AudioStream 加载并放置在 AudioStreamPlayer 中。你可以在《导入音频采样》中找到支持的格式和格式差异等信息。
还有其他类型的 AudioStream,例如 AudioStreamRandomizer。这种音频流每次都会从音频流列表中挑选不同的音频流进行播放,并应用随机音高和音量调整,这有助于为经常播放的声音添加变化。
AudioStreamPlayer(音频流播放器)

这是一种标准的非位置型的流播放器。它可以播放到任何总线。在 5.1 声音设置中,它可以将音频发送到立体声混音或前置扬声器。
播放类型是一种实验性设置,可能会在 Godot 的未来版本中发生变化。它的存在使得 Web 导出使用基于 Web Audio-API 的样本,而不是像大多数平台那样将所有声音流式传输到浏览器。这可以防止音频在单线程 Web 导出中出现乱码。默认情况下,只有 Web 平台会使用样本。除非有明确的理由,否则不建议更改此设置。你可以在项目设置的音频 > 常规(必须打开高级设置才能看到)下更改 Web 和其他平台的默认播放类型。
AudioStreamPlayer2D

这是 AudioStreamPlayer 的一种变体,但在 2D 位置环境中发出声音。当靠近屏幕左侧时,声像将向左移动。当靠近右侧时,声像将向右移动。
备注
Area2D 可用于将声音从其包含的任何 AudioStreamPlayer2D 转移到特定总线。这样就可以创造具有不同混响或音质的总线,从而来处理游戏世界特定部分发生的动作。

AudioStreamPlayer3D

这是 AudioStreamPlayer 的一种变体,但在 3D 位置环境中发出声音。根据播放器相对于屏幕的位置,它可以将声音定位为立体声、5.1 或 7.1,具体取决于所选的音频设置。
与 AudioStreamPlayer2D 类似,Area3D 可以将声音转移到特定的音频总线上。

与 2D 版本不同的是,3D 版本的 AudioStreamPlayer 还有一些更高级的选项:
Reverb buses(混响总线)
警告
This feature is not supported on the web platform if the AudioStreamPlayer's playback mode is set to Sample, which is the default. It will only work if the playback mode is set to Stream, at the cost of increased latency if threads are not enabled.
See Audio playback in the Exporting for the Web documentation for details.
Godot 允许进入特定 Area3D 节点的 3D 音频流,将干音频和湿音频发送到单独的总线上。这有益于为不同类型的房间配置多种混响配置。这可以通过在 Area3D 属性的 Reverb Bus(混响总线)部分中启用这种类型的混响来实现:

同时,还创建了一个特殊的总线布局,其中每个 Area3D 都从每个 Area3D 接收混响信息。需要在每个混响总线中创建和配置混响效果,才能完成所需效果的设置:

Area3D 的 Reverb Bus(混响总线)部分还有一个名为 Uniformity(统一性)的参数。某些类型的房间比其他类型的房间反射的声音更多(例如仓库),因此即使声源可能很远,整个房间几乎都可以均匀地听到混响。尝试使用该参数可以模拟这种效果。
Doppler(多普勒)
警告
This feature is not supported on the web platform if the AudioStreamPlayer's playback mode is set to Sample, which is the default. It will only work if the playback mode is set to Stream, at the cost of increased latency if threads are not enabled.
See Audio playback in the Exporting for the Web documentation for details.
当发射源和侦听者之间的相对速度发生变化时,这被视为发出的声音的音高增加或减少。Godot 可以跟踪 AudioStreamPlayer3D 和 Camera 节点的速度变化。 这两个节点都具有该属性,必须手动启用:

根据对象的移动方式通过设置启用它:对于使用 _process
移动的对象使用 Idle,对于使用 _physics_process
移动的对象使用 Physics。跟踪将自动进行。