-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Add runtime file loading to AudioStreamWAV
#93831
Conversation
Because the passed parameters are identical to the contents of ResourceImporterWAV, why not just passing a singular ResourceImporterWAV object? |
Thanks for the idea, I don't know how I didn't think of that before 😅, will look into that ASAP! |
After looking into this further it doesn't seem like I can use a |
Okay, indeed. Then what may be worth doing for the time being is providing a |
Out of curiosity, why is this functionality exposed both in AudioStreamWAV and ResourceImporterWAV, especially since their arguments are the same? I'd suggest only exposing it in AudioStreamWAV, as ResourceImporter is not meant to be used outside of editor builds. |
Added a
I exposed it in both because I was using I think now the main thing I'm looking at is getting this working outside editor builds, as currently it seems that (unsurprisingly) a file inside the |
Instead of moving the files around I realized I could just move the logic for Any other feedback appreciated if any improvements can be thought of here (currently I think everything is pretty alright as-is for this feature though). |
544da24
to
2ea1589
Compare
AudioStreamWAV
and ResourceImporterWAV
AudioStreamWAV
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.
Tested locally, it works as expected. WAV files of varying sample rates are handled correctly out of the box, along with mono/stereo audio.
However, AudioStreamWAV.load_from_buffer()
should be added for parity with AudioStreamOggVorbis. This allows loading audio data from memory, without needing it to be written to disk first. This is useful for networked scenarios and unit testing.
Testing project: runtime_save_load.zip1
Footnotes
-
This is https://github.com/godotengine/godot-demo-projects/tree/master/loading/runtime_save_load modified to support WAV loading. No WAV samples are included in
examples/
. ↩
2ea1589
to
2358bb6
Compare
Added a |
2358bb6
to
7408fc4
Compare
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.
4ecf1b2
to
a58f8ab
Compare
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.
And fix the indentation
a58f8ab
to
e886299
Compare
e49712a
to
95fef79
Compare
Updated the commit to fix IMA ADPCM compression not being supported by AudioEffectRecord at runtime, since with the moving of the compression function it is now entirely possible to do it without referencing ResourceImporterWAV. |
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.
Minor nitpicks I may have caused.
Either way, now that it's been rebased someone could nicely test it.
95fef79
to
1784921
Compare
Fixed the minor nitpicks in the docs. |
1784921
to
c8b6692
Compare
Fixed up remaining merge conflicts (due to some |
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.
Looks good to me.
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.
Seems ok!
c8b6692
to
707f103
Compare
Fixed accidental reversion in the docs of the new functions. |
Thanks! Congratulations on your first merged contribution! 🎉 |
This PR adds a
load_from_file
andload_from_buffer
method toAudioStreamWAV
. Theload_from_file
method has the parameterspath:String
andoptions:Dictionary
, andload_from_buffer
hasbuffer:PackedBytesArray
andoptions:Dictionary
.This is helpful in the use-case where you want to load audio files at runtime (ex: a music player), and need to load a WAV file. These methods reuse the code for the normal import functionality for WAV files to stay consistent with the rest of the engine, while allowing users to access this functionality in a convenient way.
This should fix godotengine/godot-proposals#732, although a slight refactor of WAV importing may be something to consider in the future.
Also: if there is a better way to provide the import parameters other than a
Dictionary
I would love to improve that for these new methods, I was just having issues trying to bind a static method using theHashMap
s that are used when importing files normally, so I decided to switch it to aDictionary
for this specific function because of that. (I'm not the most knowledgeable on the Godot codebase currently, so I wasn't sure what else to do).