AudioServer¶
继承: Object
用于低级音频访问的服务器接口。
描述¶
AudioServer是一个用于音频访问的低级服务器接口。它负责创建样本数据(可播放音频)以及通过语音接口进行播放。
属性¶
|
||
|
||
|
||
|
方法¶
void |
|
void |
add_bus_effect(bus_idx: int, effect: AudioEffect, at_position: int = -1) |
generate_bus_layout() const |
|
get_bus_channels(bus_idx: int) const |
|
get_bus_effect(bus_idx: int, effect_idx: int) |
|
get_bus_effect_count(bus_idx: int) |
|
get_bus_effect_instance(bus_idx: int, effect_idx: int, channel: int = 0) |
|
get_bus_index(bus_name: StringName) const |
|
get_bus_name(bus_idx: int) const |
|
get_bus_peak_volume_left_db(bus_idx: int, channel: int) const |
|
get_bus_peak_volume_right_db(bus_idx: int, channel: int) const |
|
get_bus_send(bus_idx: int) const |
|
get_bus_volume_db(bus_idx: int) const |
|
get_bus_volume_linear(bus_idx: int) const |
|
get_driver_name() const |
|
get_input_mix_rate() const |
|
get_mix_rate() const |
|
get_output_latency() const |
|
get_speaker_mode() const |
|
get_time_since_last_mix() const |
|
get_time_to_next_mix() const |
|
is_bus_bypassing_effects(bus_idx: int) const |
|
is_bus_effect_enabled(bus_idx: int, effect_idx: int) const |
|
is_bus_mute(bus_idx: int) const |
|
is_bus_solo(bus_idx: int) const |
|
void |
lock() |
void |
|
void |
register_stream_as_sample(stream: AudioStream) |
void |
remove_bus(index: int) |
void |
remove_bus_effect(bus_idx: int, effect_idx: int) |
void |
set_bus_bypass_effects(bus_idx: int, enable: bool) |
void |
set_bus_effect_enabled(bus_idx: int, effect_idx: int, enabled: bool) |
void |
set_bus_layout(bus_layout: AudioBusLayout) |
void |
set_bus_mute(bus_idx: int, enable: bool) |
void |
set_bus_name(bus_idx: int, name: String) |
void |
set_bus_send(bus_idx: int, send: StringName) |
void |
set_bus_solo(bus_idx: int, enable: bool) |
void |
set_bus_volume_db(bus_idx: int, volume_db: float) |
void |
set_bus_volume_linear(bus_idx: int, volume_linear: float) |
void |
|
void |
swap_bus_effects(bus_idx: int, effect_idx: int, by_effect_idx: int) |
void |
unlock() |
信号¶
bus_layout_changed() 🔗
添加、删除或移动音频总线时发出。
bus_renamed(bus_index: int, old_name: StringName, new_name: StringName) 🔗
bus_index处的音频总线从old_name重命名为new_name时发出。
枚举¶
enum SpeakerMode: 🔗
SpeakerMode SPEAKER_MODE_STEREO = 0
检测到两个或更少的扬声器。
SpeakerMode SPEAKER_SURROUND_31 = 1
检测到3.1通道环绕设置。
SpeakerMode SPEAKER_SURROUND_51 = 2
检测到5.1声道环绕设置。
SpeakerMode SPEAKER_SURROUND_71 = 3
检测到7.1声道环绕设置。
enum PlaybackType: 🔗
PlaybackType PLAYBACK_TYPE_DEFAULT = 0
实验性: 未来版本中可能会修改或移除该常量。
回放将被视为在ProjectSettings.audio/general/default_playback_type声明的类型。
PlaybackType PLAYBACK_TYPE_STREAM = 1
实验性: 未来版本中可能会修改或移除该常量。
强制将播放视为流。
PlaybackType PLAYBACK_TYPE_SAMPLE = 2
实验性: 未来版本中可能会修改或移除该常量。
强制将回放视为样本。这可以提供更低的延迟和更稳定的回放(音频爆裂的风险更小),但代价是灵活性更低。
注意:目前仅在Web平台上支持。
注意:当回放被视为样本时,不支持AudioEffect。
PlaybackType PLAYBACK_TYPE_MAX = 3
实验性: 未来版本中可能会修改或移除该常量。
表示PlaybackType枚举的大小。
属性说明¶
可用音频总线的数量。
String input_device = "Default" 🔗
用于音频输入的当前设备的名称(参见get_input_device_list())。在具有多个音频输入(如模拟、USB和HDMI音频)的系统上,这可用于选择音频输入设备。值“Default”将在系统范围的默认音频输入上录制音频。如果设置了无效的设备名称,该值将恢复为“Default”。
注意:ProjectSettings.audio/driver/enable_input必须为true,音频输入才能正常工作。另请参阅该设置的描述,了解与权限和操作系统隐私设置相关的警告。
String output_device = "Default" 🔗
用于音频输出的当前设备的名称(参见get_output_device_list())。在具有多个音频输出(如模拟、USB和HDMI音频)的系统上,这可用于选择音频输出设备。值“Default”将在系统范围的默认音频输出上播放音频。如果设置了无效的设备名称,该值将恢复为“Default”。
float playback_speed_scale = 1.0 🔗
缩放播放音频的速率(即将其设置为0.5将使音频以一半的速度播放)。另请参阅Engine.time_scale以影响一般模拟速度,该速度独立于playback_speed_scale。
方法说明¶
void add_bus(at_position: int = -1) 🔗
在at_position处添加总线。
void add_bus_effect(bus_idx: int, effect: AudioEffect, at_position: int = -1) 🔗
在at_position处向总线bus_idx添加AudioEffect效果。
AudioBusLayout generate_bus_layout() const 🔗
使用可用的总线和效果生成AudioBusLayout。
int get_bus_channels(bus_idx: int) const 🔗
返回索引bus_idx处总线的通道数。
AudioEffect get_bus_effect(bus_idx: int, effect_idx: int) 🔗
返回总线bus_idx中effect_idx位置的AudioEffect。
int get_bus_effect_count(bus_idx: int) 🔗
返回总线上bus_idx处的效果数。
AudioEffectInstance get_bus_effect_instance(bus_idx: int, effect_idx: int, channel: int = 0) 🔗
返回分配给给定总线和效果索引(以及可选的通道)的AudioEffectInstance。
int get_bus_index(bus_name: StringName) const 🔗
返回名称为bus_name的总线的索引。如果不存在具有指定名称的总线,则返回-1。
String get_bus_name(bus_idx: int) const 🔗
返回带有索引bus_idx的总线名称。
float get_bus_peak_volume_left_db(bus_idx: int, channel: int) const 🔗
返回左侧扬声器在总线索引bus_idx和通道索引channel处的峰值音量。
float get_bus_peak_volume_right_db(bus_idx: int, channel: int) const 🔗
返回右侧扬声器在总线索引bus_idx和通道索引channel处的峰值音量。
StringName get_bus_send(bus_idx: int) const 🔗
返回索引bus_idx处的总线发送到的总线的名称。
float get_bus_volume_db(bus_idx: int) const 🔗
返回索引bus_idx处的总线体积(以dB为单位)。
float get_bus_volume_linear(bus_idx: int) const 🔗
将索引bus_idx处的总线体积作为线性值返回。
注意:返回值等价于get_bus_volume_db()的结果上的@GlobalScope.db_to_linear()的结果。
String get_driver_name() const 🔗
返回当前音频驱动程序的名称。默认值通常取决于操作系统,但可以通过--audio-drive命令行参数覆盖。--head less也会自动将音频驱动程序设置为Dummy。另请参阅ProjectSettings.audio/driver/driver。
PackedStringArray get_input_device_list() 🔗
返回系统上检测到的所有音频输入设备的名称。
注意:ProjectSettings.audio/driver/enable_input必须为true,音频输入才能正常工作。另请参阅该设置的描述,了解与权限和操作系统隐私设置相关的警告。
float get_input_mix_rate() const 🔗
返回AudioServer输入处的采样率。
返回AudioServer输出处的采样率。
PackedStringArray get_output_device_list() 🔗
返回系统上检测到的所有音频输出设备的名称。
float get_output_latency() const 🔗
返回音频驱动程序的有效输出延迟。这基于ProjectSettings.audio/driver/output_latency,但确切的返回值会因操作系统和音频驱动程序而异。
注意:这可能很昂贵;不建议每帧调用get_output_latency()。
SpeakerMode get_speaker_mode() const 🔗
返回扬声器配置。
float get_time_since_last_mix() const 🔗
返回自上次混合发生以来的相对时间。
float get_time_to_next_mix() const 🔗
返回到下一次混合发生的相对时间。
bool is_bus_bypassing_effects(bus_idx: int) const 🔗
如果true,则索引bus_idx处的总线绕过效果。
bool is_bus_effect_enabled(bus_idx: int, effect_idx: int) const 🔗
如果true,则在索引effect_idx处的总线上启用索引bus_idx处的效果。
bool is_bus_mute(bus_idx: int) const 🔗
如果true,则索引bus_idx处的总线静音。
bool is_bus_solo(bus_idx: int) const 🔗
如果true,则索引bus_idx处的总线处于单机模式。
bool is_stream_registered_as_sample(stream: AudioStream) 🔗
实验性: 未来版本中可能会修改或移除该方法。
如果true,则流被注册为样本。引擎在播放样本之前不必注册它。
如果false,则必须在播放之前注册流。为了防止延迟尖峰,请使用register_stream_as_sample()将流注册为示例。
void lock() 🔗
锁定音频驱动程序的主循环。
注意:之后记得解锁。
void move_bus(index: int, to_index: int) 🔗
将总线从indexindex移动到indexto_index。
void register_stream_as_sample(stream: AudioStream) 🔗
实验性: 未来版本中可能会修改或移除该方法。
强制将流注册为样本。
注意:调用此方法时可能会出现延迟尖峰,尤其是在单线程构建中。建议在加载资产时调用此方法,其中延迟尖峰可能会被屏蔽,而不是在需要播放之前注册样本。
删除索引index处的总线。
void remove_bus_effect(bus_idx: int, effect_idx: int) 🔗
从索引effect_idx处的总线中删除索引bus_idx处的效果。
void set_bus_bypass_effects(bus_idx: int, enable: bool) 🔗
如果true,则索引bus_idx处的总线绕过效果。
void set_bus_effect_enabled(bus_idx: int, effect_idx: int, enabled: bool) 🔗
如果true,则在索引effect_idx处的总线上启用索引bus_idx处的效果。
void set_bus_layout(bus_layout: AudioBusLayout) 🔗
覆盖当前使用的AudioBusLayout。
void set_bus_mute(bus_idx: int, enable: bool) 🔗
如果true,则索引bus_idx处的总线静音。
void set_bus_name(bus_idx: int, name: String) 🔗
将索引bus_idx处的总线名称设置为name。
void set_bus_send(bus_idx: int, send: StringName) 🔗
将bus_idx处的总线输出连接到名为send的总线。
void set_bus_solo(bus_idx: int, enable: bool) 🔗
如果true,则索引bus_idx处的总线处于单机模式。
void set_bus_volume_db(bus_idx: int, volume_db: float) 🔗
将索引bus_idx处的总线体积(以分贝为单位)设置为volume_db。
void set_bus_volume_linear(bus_idx: int, volume_linear: float) 🔗
将体积设置为总线在索引bus_idx到volume_linear处的线性值。
注意:使用此方法相当于在一个值上调用@GlobalScope.linear_to_db()的结果的set_bus_volume_db()。
void set_enable_tagging_used_audio_streams(enable: bool) 🔗
如果设置为true,AudioStreamPlayback的所有实例将在每个混合步骤调用AudioStreamPlayback._tag_used_streams()。
注意:这在编辑器中默认启用,因为它被编辑器插件用于音频流预览。
void swap_bus_effects(bus_idx: int, effect_idx: int, by_effect_idx: int) 🔗
交换总线bus_idx中两个效果的位置。
void unlock() 🔗
解锁音频驱动程序的主循环。(锁定后,您应该始终解锁它。)