音频总线

简介

Godot的音频处理代码是为了游戏而写的,以达到性能和音质之间的最佳平衡。

Godot的音频引擎允许创建任意数量的音频总线,并且可以向每个总线添加任意数量的效果处理器。运行游戏的设备的硬件会限制总线的数量,以及在性能开始下降之前可以使用的效果。

分贝大小

Godot’s sound interface is designed to meet the expectations of sound design professionals. To this end, it primarily uses the decibel scale.

对于那些不熟悉它的人,可以用一些事实来解释:

  • The decibel (dB) scale is a relative scale. It represents the ratio of sound power by using 20 times the base 10 logarithm of the ratio (20 × log10(P/P0)).
  • For every 6 dB, sound amplitude doubles or halves. 12 dB represents a factor of 4, 18 dB a factor of 8, 20 dB a factor of 10, 40 dB a factor of 100, etc.
  • 由于比例是对数的,因此无法表示真零(无音频)。
  • 0 dB is the maximum amplitude possible in a digital audio system. This limit is not the human limit, but a limit from the sound hardware. Audio with amplitudes that are too high to be represented properly below 0 dB create a kind of distortion called clipping.
  • To avoid clipping, your sound mix should be arranged so that the output of the master bus (more on that later) never exceeds 0 dB.
  • Every 6 dB below the 0 dB limit, sound energy is halved. It means the sound volume at -6 dB is half as loud as 0dB. -12 dB is half as loud as -6 dB and so on.
  • When working with decibels, sound is considered no longer audible between -60 dB and -80 dB. This makes your working range generally between -60 dB and 0 dB.

这可能需要一点时间习惯,但它最终会更友好,并允许您与音频专业人士更好地沟通。

音频总线

Audio buses can be found in the bottom panel of the Godot editor:

../../_images/audio_buses1.png

An audio bus (also called an audio channel) can be considered a place that audio is channeled through on the way to playback through a device’s speakers. Audio data can be modified and re-routed by an audio bus. An audio bus has a VU meter (the bars that light up when sound is played) which indicates the amplitude of the signal passing through.

最左边的总线是 主总线 。 此总线将混音输出到您的扬声器,因此,正如之前*分贝刻度*部分所述,请确保您在此总线中的混音水平永远不会达到 0 dB。其余的音频总线可以被灵活路由。 在修改声音之后,它们会将其送往位于左侧的另一个总线。非主总线的目标总线可以被单独设置。右侧总线的音频总是会被路由至左侧总线,这避免了无限循环。

../../_images/audio_buses2.png

In the above image, the output of Bus 2 has been routed to the Master bus.

Playback of audio through a bus

To test passing audio to a bus, create an AudioStreamPlayer node, load an AudioStream and select a target bus for playback:

../../_images/audio_buses3.png

Finally, toggle the Playing property to On and sound will flow.

参见

You may also be interested in reading about 音频流 now.

添加特效

音频总线可以包含各种效果。 这些效果以某种方式修改声音并按顺序应用。

../../_images/audio_buses4.png

Try them all out to get a sense of how they alter sound. Here follows a short description of the available effects:

Amplify

增强改变了信号的振幅。使用时要小心。把音量调得太高的话,声音就会被截断,这通常是不可取的。

BandLimit and BandPass

这些是共振滤波器,它在*截止*点附近阻断频率。带通滤波器可以用来模拟声音通过旧电话线路或扩音器。调制带通滤波器频率,可以模拟哇哇吉他踏板的声音,想想吉米·亨德里克斯在*魔法之子(轻微的回报)*中使用的吉他吧。

Chorus

The Chorus effect duplicates the incoming audio, delays the duplicate slightly and uses an LFO to continuously modulate the pitch of the duplicated signal before mixing the duplicated signal(s) and the original together again. This creates a shimmering effect and adds stereo width to the sound.

Compressor

当输入信号的幅度超过某一阈值时,动态范围压缩器会自动衰减该信号的电平。衰减的程度与传入的音频超过阈值的程度成正比。压缩器的比例参数控制着衰减的程度。压缩器的主要用途之一,是降低信号的动态范围与非常响亮和安静的部分。减小信号的动态范围,可以使混合变得更容易。

The compressor has many uses. For example:

  • 它可以在主总线中用于压缩整个输出(尽管限制器可能更好)。
  • 它可以在语音通道中使用,以确保它们尽可能地发声。
  • It can be sidechained. This means it can reduce the sound level of one signal using the level of another audio bus for threshold detection. This technique is very common in video game mixing to “duck” the level of music or sound effects when voices need to be heard.
  • It can accentuate transients by using a slower attack. This can make sound effects more punchy.

注解

If your goal is to prevent a signal from exceeding a given amplitude altogether, rather than to reduce the dynamic range of the signal, a limiter is likely a better choice than a compressor.

Delay

Adds an “echo” effect with a feedback loop. It can be used together with Reverb to simulate wide rooms, canyons, etc. where sound bounces are far apart.

Distortion

Makes the sound distorted. Godot offers several types of distortion: overdrive, tan and bit crushing. Distortion can be used to simulate sound coming through a low-quality speaker or device.

EQ

EQ is what all other equalizers inherit from. It can be extended with with Custom scripts to create an equalizer with a custom number of bands.

EQ6, EQ10, EQ21

Godot provides three equalizers with different numbers of bands. An equalizer on the Master bus can be useful to cut frequencies that the device’s speakers can’t reproduce well (e.g. a mobile phone’s speakers won’t reproduce bass content well). The equalizer effect can be disabled when headphones are plugged in.

过滤器

Filter is what all other filters inherit from and should not be used directly.

HighPassFilter

Cuts frequencies below a specific Cutoff frequency. HighPassFilter is used to reduce the bass content of a signal.

HighShelfFilter

Reduces all frequencies above a specific Cutoff frequency.

Limiter

A limiter is similar to a compressor, but it’s less flexible and designed to prevent a signal’s amplitude exceeding a given dB threshold. Adding a limiter to the Master bus is a safeguard against clipping.

LowPassFilter

Cuts frequencies above a specific Cutoff frequency and can also resonate (boost frequencies close to the Cutoff frequency). Low pass filters can be used to simulate “muffled” sound. For instance, underwater sounds, sounds blocked by walls, or distant sounds.

LowShelfFilter

Reduces all frequencies below a specific Cutoff frequency.

NotchFilter

The opposite of the BandPassFilter, it removes a band of sound from the frequency spectrum at a given Cutoff frequency.

Panner

The Panner allows the stereo balance of a signal to be adjusted between the left and right channels (wear headphones to audition this effect).

Phaser

It probably does not make much sense to explain that this effect is formed by two signals being dephased and cancelling each other out. You can make a Darth Vader voice with it, or jet-like sounds.

PitchShift

This effect allows the adjustment of the signal’s pitch independently of its speed. All frequencies can be increased/decreased with minimal effect on transients. PitchShift can be useful to create unusually high or deep voices.

录制

录制效果允许将通过总线的音频写入文件。

Reverb

Reverb simulates rooms of different sizes. It has adjustable parameters that can be tweaked to obtain the sound of a specific room. Reverb is commonly outputted from Areas (see Reverb buses), or to apply a “chamber” feel to all sounds.

频谱分析仪

This effect doesn’t alter audio, instead, you add this effect to buses you want a spectrum analysis of. This would typically be used for audio visualization. A demo project using this can be found here.

StereoEnhance

This effect uses a few algorithms to enhance a signal’s stereo spectrum.

自动总线禁用

There is no need to disable buses manually when not in use. Godot detects that the bus has been silent for a few seconds and disables it (including all effects).

../../_images/audio_buses5.png

Disabled buses have a blue VU meter instead of a red-green one.

总线重排

Stream Players use bus names to identify a bus, which allows adding, removing and moving buses around while the reference to them is kept. However, if a bus is renamed, the reference will be lost and the Stream Player will output to Master. This system was chosen because rearranging buses is a more common process than renaming them.

默认总线布局

The default bus layout is automatically saved to the res://default_bus_layout.tres file. Custom bus arrangements can be saved and loaded from disk.