2016-02-08 23:45:57 +01:00
|
|
|
.. _doc_importing_audio_samples:
|
2016-02-08 22:07:55 +01:00
|
|
|
|
2016-02-06 01:54:33 +01:00
|
|
|
Importing audio samples
|
|
|
|
=======================
|
|
|
|
|
|
|
|
Why importing?
|
|
|
|
--------------
|
|
|
|
|
|
|
|
Importing Audio Samples into the game engine is a process that should be
|
|
|
|
easier than it really is. Most readers are probably thinking "Why not
|
2016-05-20 06:48:44 +02:00
|
|
|
just copy the wav files to a folder inside the project and be over
|
|
|
|
with it?"
|
2016-02-06 01:54:33 +01:00
|
|
|
|
|
|
|
It's not usually that simple. Most game engines use uncompressed audio
|
2016-05-20 06:48:44 +02:00
|
|
|
(in memory, at least) for sound effects. The reason for this is because
|
2016-02-06 01:54:33 +01:00
|
|
|
it's really cheap to play back and resample. Compressed streamed audio
|
2016-05-20 06:48:44 +02:00
|
|
|
(such as ogg files) takes a large amount of processor to decode so no
|
2016-02-06 01:54:33 +01:00
|
|
|
more than one or two are streamed simultaneously. However, with sound
|
|
|
|
effects, one expects a dozen of them to be playing at the same time in
|
|
|
|
several situations.
|
|
|
|
|
|
|
|
Because of this, sound effects are loaded uncompressed into memory, and
|
|
|
|
here is where the problems begin.
|
|
|
|
|
|
|
|
As is usual with graphics, the situation where programmers don't really
|
|
|
|
know about audio and audio engineers don't know about programming is
|
|
|
|
also common in the industry. This leads to a scenario where a project
|
|
|
|
ends up wasting resources unnecessarily.
|
|
|
|
|
2016-05-20 06:48:44 +02:00
|
|
|
To be more precise, SFX artists tend to work with audio formats that
|
|
|
|
give them a lot of room for tweaking the audio with a low noise floor and
|
|
|
|
minimum aliasing, such as 96kHz, 24 bits. In many cases, they work in
|
2016-02-06 01:54:33 +01:00
|
|
|
stereo too. Added to that, many times they add effects with an infinite
|
2016-05-20 06:48:44 +02:00
|
|
|
or really long fadeout, such as reverb, which leads to apparent trailing
|
|
|
|
silences. Finally, many DAWs also add silence at the beginning when
|
2016-02-06 01:54:33 +01:00
|
|
|
normalizing to wav.
|
|
|
|
|
2016-05-20 06:48:44 +02:00
|
|
|
These often result in extremely large files to integration into a game engine
|
|
|
|
with sound effects taking dozens of megabytes.
|
2016-02-06 01:54:33 +01:00
|
|
|
|
|
|
|
How much does quality matter?
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
First of all, it is important to know that Godot has an internal reverb
|
|
|
|
generator. Sound effects can go to four different setups (small, medium
|
2016-05-20 06:48:44 +02:00
|
|
|
and large room, as well as hall), with different send amounts. This saves
|
|
|
|
SFX artists the need to add reverb to the sound effects, reducing their
|
2016-02-06 01:54:33 +01:00
|
|
|
size greatly and ensuring correct trimming. Say no to SFX with baked
|
|
|
|
reverb!
|
|
|
|
|
|
|
|
.. image:: /img/reverb.png
|
|
|
|
|
|
|
|
Another common problem is that, while it's useful for working inside a
|
2016-05-20 06:48:44 +02:00
|
|
|
DAW, high bit depths (24 bits) and high sampling rate (96kHz) are
|
2016-02-06 01:54:33 +01:00
|
|
|
completely unnecessary for use in a game, as there is no `audible
|
|
|
|
difference <http://www.youtube.com/watch?v=cIQ9IXSUzuM>`__. If
|
|
|
|
positional sound is going to be used (for 2D and 3D), the panning and
|
|
|
|
stereo reverb will be provided by the engine, so there is little need
|
|
|
|
for stereo sound. How does this affect the resource usage? Look at the
|
|
|
|
following comparison:
|
|
|
|
|
|
|
|
+---------------------------+---------------------+--------------+
|
|
|
|
| Format | 1 Second of Audio | Frame Size |
|
|
|
|
+===========================+=====================+==============+
|
2016-05-20 06:48:44 +02:00
|
|
|
| 24 bits, 96 kHz, Stereo | 576kb | 12 |
|
2016-02-06 01:54:33 +01:00
|
|
|
+---------------------------+---------------------+--------------+
|
2016-05-20 06:48:44 +02:00
|
|
|
| 16 bits, 44 kHz, Mono | 88kb | 2 |
|
2016-02-06 01:54:33 +01:00
|
|
|
+---------------------------+---------------------+--------------+
|
|
|
|
| 16 bits, IMA-ADPCM | 22kb | 1/2 |
|
|
|
|
+---------------------------+---------------------+--------------+
|
|
|
|
|
2016-05-20 06:48:44 +02:00
|
|
|
As seen, for being no audible difference, the 16 bits, 44kHz, mono conversion
|
|
|
|
takes *6 times less memory* than the 24 bits, 96kHz, Stereo version. The
|
|
|
|
IMA-ADPCM version (using computationally-light audio compression) takes *24
|
|
|
|
times less memory* than what was exported from the DAW.
|
2016-02-06 01:54:33 +01:00
|
|
|
|
|
|
|
Trimming
|
|
|
|
~~~~~~~~
|
|
|
|
|
|
|
|
One last issue that happens often is that the waveform files received
|
|
|
|
have silences at the beginning and at the end. These are inserted by
|
|
|
|
DAWs when saving to a waveform, increase their size unnecessarily and
|
|
|
|
add latency to the moment they are played back. Trimming them solves
|
2016-05-20 06:48:44 +02:00
|
|
|
this, but it takes effort for the SFX artist, as they have to do it in a
|
2016-02-06 01:54:33 +01:00
|
|
|
separate application. In the worst case, they may not even know the
|
|
|
|
silences are being added.
|
|
|
|
|
|
|
|
.. image:: /img/trim.png
|
|
|
|
|
|
|
|
Importing audio samples
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
Godot has a simple screen for importing audio samples to the engine. SFX
|
2016-05-20 06:48:44 +02:00
|
|
|
artists only have to save the wav files to a folder outside the
|
2016-02-06 01:54:33 +01:00
|
|
|
project, and the import dialog will fix the files for inclusion, as well
|
|
|
|
as doing it automatically every time they are modified and re-imported.
|
|
|
|
|
|
|
|
.. image:: /img/importaudio.png
|
|
|
|
|
|
|
|
In this screen, the quality of the audio can be limited to what is
|
2016-05-20 06:48:44 +02:00
|
|
|
needed, and trimming is done automatically. In addition, several samples
|
|
|
|
can be loaded and batch-converted, just as textures can.
|
2016-02-06 01:54:33 +01:00
|
|
|
|
|
|
|
Looping
|
|
|
|
~~~~~~~
|
|
|
|
|
|
|
|
Godot supports looping in the samples (Tools such as Sound Forge or
|
2016-05-20 06:48:44 +02:00
|
|
|
Audition can add loop points to wav files). This is useful for sound
|
2016-02-06 01:54:33 +01:00
|
|
|
effects such as engines, machine guns, etc. Ping-pong looping is also
|
|
|
|
supported.
|
|
|
|
|
|
|
|
As an alternative, the import screen has a "loop" option that enables
|
|
|
|
looping for the entire sample when importing.
|