Barramentos de áudio

Introdução

O código de processamento de áudio do Godot foi escrito com jogos em mente, com o intuito de alcançar um equilíbrio favorável entre desempenho e qualidade de som.

O motor de áudio do Godot permite qualquer número de barramentos de áudio a serem criados e qualquer número de processadores de efeito podem ser adicionados a cada barramento. Apenas o hardware do dispositivo executando seu jogo irá limitar o número de barramentos e efeitos que podem ser usados antes que o desempenho comece a cair.

Escala decibel

A interface de som do Godot é designada para combinar com as expectativas dos profissionais de design de som. Para este fim, utiliza-se primariamente a escala decibel.

Para aqueles não familiarizados, pode-se explicar com alguns fatos:

  • A escala decibel (dB) é uma escala relativa. Ela representa a taxa de potência de som ao usar 20 vezes o logaritmo de base 10 da proporção (20 × log10(P/P0)).
  • Para cada 6 dB, a amplitude de som se duplica ou se divide pela metade. 12 dB representam um fator de 4, 18 dB um fator de 8, 20 dB um fator de 10, 40dB um fator de 100, etc.
  • Como a escala é logarítmica, um zero verdadeiro (sem áudio) não pode ser representado.
  • 0 dB é a amplitude máxima possível em um sistema de áudio digital. Este não é o limite humano, mas um limite do hardware de som. Áudio com amplitudes que são muito altas para serem representados corretamente criam uma distorção chamada clipping.
  • Para evitar clipping, sua mixagem de som deve ser organizada para que a saída do barramento mestre (mais detalhes depois) nunca exceda 0dB.
  • Para cada 6 dB abaixo do limite de 0 dB, a energia de som é cortada pela metade. Significa que o volume de som em -6 dB possui metade da intensidade de 0 dB. -12 dB possui metade da intensidade de -6 dB e assim por diante.
  • Ao trabalhar com decibels, um som é considerado inaudível entre -60 dB e -80 dB. Isso faz com que seu alcance de trabalho seja geralmente entre -60 dB e 0 dB.

Pode levar um pouco de tempo para pegar o jeito, porém é mais amigável no fim e permitirá que você se comunique melhor com profissionais de áudio.

Barramentos de áudio

Barramentos de áudio podem ser encontrados no painel inferior do editor do Godot:

../../_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.

O barramento mais à esquerda é o barramento mestre. Este barramento gera o mix para seus alto-falantes então, como mencionado na seção Escala decibel acima, certifique-se de que seu nível de mixagem não chegue a 0 dB neste barramento. O resto dos barramentos de áudio podem ser flexivelmente encaminhados. Após modificar o som, eles o enviam para outro barramento à esquerda. O barramento destinatário pode ser especificado por cada um dos barramentos não-mestre. O encaminhamento sempre passa áudio de barramentos na direita para barramentos além para a esquerda. Isso evita ciclos de encaminhamento infinitos.

../../_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.

Ver também

You may also be interested in reading about Fluxos de áudio now.

Adding effects

Audio buses can contain all sorts of effects. These effects modify the sound in one way or another and are applied in order.

../../_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

Amplify changes the amplitude of the signal. Some care needs to be taken. Setting the level too high can make the sound clip, which is usually undesirable.

BandLimit and BandPass

These are resonant filters which block frequencies around the Cutoff point. BandPass can be used to simulate sound passing through an old telephone line or megaphone. Modulating the BandPass frequency can simulate the sound of a wah-wah guitar pedal, think of the guitar in Jimi Hendrix's Voodoo Child (Slight Return).

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

A dynamic range compressor automatically attenuates the level of the incoming signal when its amplitude exceeds a certain threshold. The level of attenuation applied is proportional to how far the incoming audio exceeds the threshold. The compressor's Ratio parameter controls the degree of attenuation. One of the main uses of a compressor is to reduce the dynamic range of signals with very loud and quiet parts. Reducing the dynamic range of a signal can make it easier to mix.

The compressor has many uses. For example:

  • It can be used in the Master bus to compress the whole output.
  • It can be used in voice channels to ensure they sound as even as possible.
  • 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.

Nota

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

Distortion effects make the sound "dirty". 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.

Filtro

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

HighPassFilter, HighShelfFilter

These are filters that cut frequencies below a specific Cutoff frequency. HighPassFilter and HighShelfFilter are used to reduce the bass content of a signal.

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, LowShelfFilter

These are the most common filters, they cut 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.

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.

Record

The Record effect allows audio passing through the bus to be written to a file.

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.

SpectrumAnalyzer

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.

Automatic bus disabling

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.

Bus rearrangement

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.

Default bus layout

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.