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

AudioStreamMP3: Use a LocalVector to store data #97026

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions modules/minimp3/audio_stream_mp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,9 @@ void AudioStreamMP3::clear_data() {

void AudioStreamMP3::set_data(const Vector<uint8_t> &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.");
Expand All @@ -237,10 +236,7 @@ void AudioStreamMP3::set_data(const Vector<uint8_t> &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;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/minimp3/audio_stream_mp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class AudioStreamMP3 : public AudioStream {

friend class AudioStreamPlaybackMP3;

PackedByteArray data;
LocalVector<uint8_t> data;
uint32_t data_len = 0;

float sample_rate = 1.0;
Expand Down
Loading