From e3f3daac6f52d80ba2f3c7f166a93bc1111bdd7e Mon Sep 17 00:00:00 2001 From: DeeJayLSP Date: Sat, 14 Sep 2024 19:14:47 -0300 Subject: [PATCH] AudioStreamMP3: Use a LocalVector to store data --- modules/minimp3/audio_stream_mp3.cpp | 8 ++------ modules/minimp3/audio_stream_mp3.h | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/modules/minimp3/audio_stream_mp3.cpp b/modules/minimp3/audio_stream_mp3.cpp index e29fe9295ab..4963cfdf1af 100644 --- a/modules/minimp3/audio_stream_mp3.cpp +++ b/modules/minimp3/audio_stream_mp3.cpp @@ -221,10 +221,9 @@ void AudioStreamMP3::clear_data() { void AudioStreamMP3::set_data(const Vector &p_data) { int src_data_len = p_data.size(); - const uint8_t *src_datar = p_data.ptr(); mp3dec_ex_t *mp3d = memnew(mp3dec_ex_t); - int err = mp3dec_ex_open_buf(mp3d, src_datar, src_data_len, MP3D_SEEK_TO_SAMPLE); + int err = mp3dec_ex_open_buf(mp3d, p_data.ptr(), src_data_len, MP3D_SEEK_TO_SAMPLE); if (err || mp3d->info.hz == 0) { memdelete(mp3d); ERR_FAIL_MSG("Failed to decode mp3 file. Make sure it is a valid mp3 audio file."); @@ -237,10 +236,7 @@ void AudioStreamMP3::set_data(const Vector &p_data) { mp3dec_ex_close(mp3d); memdelete(mp3d); - clear_data(); - - data.resize(src_data_len); - memcpy(data.ptrw(), src_datar, src_data_len); + data = p_data; data_len = src_data_len; } diff --git a/modules/minimp3/audio_stream_mp3.h b/modules/minimp3/audio_stream_mp3.h index 39d389b8cd5..bb4c7f524cf 100644 --- a/modules/minimp3/audio_stream_mp3.h +++ b/modules/minimp3/audio_stream_mp3.h @@ -96,7 +96,7 @@ class AudioStreamMP3 : public AudioStream { friend class AudioStreamPlaybackMP3; - PackedByteArray data; + LocalVector data; uint32_t data_len = 0; float sample_rate = 1.0;