-
-
Notifications
You must be signed in to change notification settings - Fork 22.4k
Move WAV loading functionality to a wav_loader
module with dr_wav
(adds AIFF support)
#96545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@@ -35,6 +35,15 @@ | |||
#include "core/io/resource_saver.h" | |||
#include "scene/resources/audio_stream_wav.h" | |||
|
|||
#define DRWAV_IMPLEMENTATION | |||
#define DR_WAV_NO_STDIO | |||
#define DR_WAV_LIBSNDFILE_COMPAT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite not using libsndfile
, the way Godot converts streams from/to f32 follows similar calculations, therefore not defining this leads to some test errors (save/reimport datas being different).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Horray
Added a check to detect if the container is RF64 or W64. Even if they could be imported in theory, this is the best non-compatibility breaking way to deny getting a stream that is too big for |
Modified the check again, this time it actually checks the amount of samples (maximum of 2147483647). Normally, the importer uses an |
Does the dr mp4 problem affect dr_wav? Not sure of the exact problem. |
The problem with Doesn't apply to WAV. |
0925491
to
ce27e00
Compare
Added |
else if (loop.type == drwav_smpl_loop_type_backward) | ||
loop_mode = AudioStreamWAV::LOOP_BACKWARD; | ||
loop_begin = loop.firstSampleByteOffset; | ||
loop_end = loop.lastSampleByteOffset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Byte" in the names here is misleading, it's actually the offsets of loop begin/end in frames, not bytes.
I have tested this considering the old read code actually copied a sample value directly, not a byte offset.
Works the same way as the previous implementation just fine.
ffbc68e
to
723e117
Compare
Updated ResourceImporterWAV documentation to point out it also supports AIFF. |
c133869
to
67fe879
Compare
Rebased. I took the opportunity to redo how the data is read. dr_wav offers 3 ways: From a file through stdio, from memory and from custom read/seek functions. Before the last push, it was loading the entire file data into the memory, then reading from memory, which resulted into a massive increase in memory usage during import if the file was too large. Now it uses custom functions (lambdas) that tell FileAccess to react accordingly, effectively being an integration between FileAccess and dr_wav. I don't know if I violated any Godot style guideline, so I'd like to ask for another review. The patch in dr_wav could be applied directly into a define, so it was removed. |
AIFF is also the default format for Garage Band, so it comes in very handy to have this support. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like the idea of having a function load_from_dr_wav
. It exposes needlessly the thirdparty used.
0900079
to
8ffb6ea
Compare
I realized removing a check from the file seek callback would speed up imports without making anything fail. I thought it was some kind of overhead from |
f1355f8
to
fd16410
Compare
Something that just came to mind: how about making this a module similar to All the The size penalty would still exist in distributed editor and template builds, but at least there would be an easy option to make a custom build without it. |
dr_wav
module (AIFF support)
Rework done. The entire Much like the Since there is a small but considerable demand for AIFF support, but in order to do so in an easy way would result into a big size penalty, I thought a module would be the best approach. |
f8cddbe
to
bb2ce00
Compare
dr_wav
module (AIFF support)dr_wav
module (adds AIFF support)
Rebased and renamed to a more specific title. |
f54e0c8
to
e265d2a
Compare
dr_wav
module (adds AIFF support)wav_loader
module with dr_wav
(adds AIFF support)
Renamed the module to |
… (adds AIFF support)
Changes
Moves the entire
AudioStreamWAV
load functionality into a module, which usesdr_wav
to read and decode data and will be required to use the respectiveAudioStreamWAV::load_from_*
functions (not required for playingAudioStreamWAV
audio or creating streams throughAudioEffectRecord
).Formats already supported by Godot and loop info detection should remain supported without regressions.
Extra WAV encoding formats like A-law, μ-law, MS ADPCM and IMA ADPCM can now be imported.
Indirectly fixes #90957.
AIFF support
dr_wav
is also able to read AIFF files, soResourceImporterWAV
was enabled to recognize it too.load_from_buffer
andload_from_file
should recognize AIFF data/files as well.The importer was renamed from
Microsoft WAV
toMicrosoft WAV/Apple AIFF
to reflect that.When it comes to sound effects, freesound.org provides much more AIFF than Ogg Vorbis files, so I thought adding support was reasonable:

wave
,aif
,aiff
andaifc
file extensions have been added as recognized extensions alongsidewav
in the importer.Actually load from file instead of a file buffer
#93831 changed the load function to copy the entire file data into memory from using
FileAccess
to get values.You can tell
dr_wav
to use specific read/seek callbacks, so I wrote callbacks to makeload_from_file
read using FileAccess instead of a memory copy.Caveats
I noticed a 36 KiB size penalty on production template_release builds (71991600 -> 72028464). This PR was opened when the load procedure was editor-only, and during its development was moved into
AudioStreamWAV
to serve as a load function. I don't know if 36 KiB is too much for this, but as a side effect reduces the probability of errors.And once again, it is a module that can be disabled.