Skip to content
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 AudioStreamMP3 load_from_file/load_from_buffer and harmonize other audio streams #100307

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

akien-mga
Copy link
Member

@akien-mga akien-mga commented Dec 12, 2024

Move OggVorbis and MP3 loading code to their AudioStream class, matching how it's done for WAV.

The duplicate functions in ResourceImporterOggVorbis are now deprecated.

Tested with the following project (credits to @StayAtHomeDev for the guest appearance):
test-audiostream-loading.zip

gouda.mp4

Comment on lines -726 to -731
void AudioStreamWAV::_bind_methods() {
ClassDB::bind_static_method("AudioStreamWAV", D_METHOD("load_from_file", "path", "options"), &AudioStreamWAV::load_from_file, DEFVAL(Dictionary()));
ClassDB::bind_static_method("AudioStreamWAV", D_METHOD("load_from_buffer", "buffer", "options"), &AudioStreamWAV::load_from_buffer, DEFVAL(Dictionary()));

ClassDB::bind_method(D_METHOD("set_data", "data"), &AudioStreamWAV::set_data);
ClassDB::bind_method(D_METHOD("get_data"), &AudioStreamWAV::get_data);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just being moved further down to follow the usual structure:

  • Public methods
  • _bind_methods
  • Constructor
  • Destructor

Comment on lines -127 to -131
Ref<AudioStreamOggVorbis> ResourceImporterOggVorbis::load_from_buffer(const Vector<uint8_t> &file_data) {
Ref<AudioStreamOggVorbis> ogg_vorbis_stream;
ogg_vorbis_stream.instantiate();

Ref<OggPacketSequence> ogg_packet_sequence;
ogg_packet_sequence.instantiate();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved as is to AudioStreamOggVorbis::load_from_buffer (with just the parameter renamed to p_stream_data as it doesn't necessarily come from an actual file on disk).

@akien-mga akien-mga force-pushed the mp3-load_from_file branch 2 times, most recently from a31fdde to 12f5b51 Compare December 12, 2024 11:36
Copy link
Member

@Calinou Calinou left a 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. This can load and play my entire MP3 music collection (3,000+ tracks) without any errors.

Code looks good to me.

Testing project: test_pr_100307.zip

@dustdfg
Copy link
Contributor

dustdfg commented Dec 13, 2024

#97855 should be closed too? But it seems to me that error propagation suggested by @adamscott in that PR would be good

@adamscott adamscott self-requested a review December 18, 2024 01:51
Copy link
Member

@adamscott adamscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you @akien-mga to have taken the time to harmonize this mess. About #97855 and my suggestion of error propagation, I think it still stands, but I wouldn't not merge this PR for that reason.

…other audio streams

Move OggVorbis and MP3 loading code to their AudioStream class, matching how it's done for WAV.

The duplicate functions in ResourceImporterOggVorbis are now deprecated.

Co-authored-by: MaxIsJoe <34368774+MaxIsJoe@users.noreply.github.com>
@akien-mga
Copy link
Member Author

I finally took time to look into #97855. The added error propagation seems interesting, but as is I don't see the immediate benefit, since it doesn't seem to actually be used anywhere to change behavior.

So I would leave that to future work, which should also include WAV and likely non-audio formats if we want to change the logic of resource format loaders to do better error handling.

@akien-mga akien-mga merged commit d5b73e2 into godotengine:master Jan 9, 2025
20 checks passed
@akien-mga akien-mga deleted the mp3-load_from_file branch January 9, 2025 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants