From 3691d87e0915f844c2b0ce03d583c2ccc307ecb5 Mon Sep 17 00:00:00 2001 From: prayerie Date: Sun, 3 May 2026 19:55:11 +0100 Subject: [PATCH 1/2] speed up 24/32 bit wav loads --- libntxm/arm9/source/wav.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/libntxm/arm9/source/wav.cpp b/libntxm/arm9/source/wav.cpp index 4dc667d..1a8cf37 100644 --- a/libntxm/arm9/source/wav.cpp +++ b/libntxm/arm9/source/wav.cpp @@ -198,17 +198,24 @@ bool Wav::load(const char *filename) // Read the data if(bit_per_sample > bit_per_sample_) { - int skip_bytes = (bit_per_sample - bit_per_sample_) / 8; - u32 i = 0; - for(; i < n_samples_; i++) { - fseek(fileh, skip_bytes, SEEK_CUR); - if(fread(audio_data_ + i * 2, 2, 1, fileh) <= 0) { - break; - } + int byte_per_sample = bit_per_sample_/8; + + u8 *audio_data_tmp = (u8*)ntxm_umalloc(chunk_size); + if (audio_data_tmp == 0) { + ntxm_dprintf("Could not alloc mem(%ld) for wav.\n", chunk_size); + ntxm_free(audio_data_); + fclose(fileh); + return false; } - if(i < n_samples_) { - memset(audio_data_ + i * 2, 0, chunk_size - i * 2); + fread(audio_data_tmp, 1, chunk_size, fileh); + + u32 i=0; + for(; i < n_samples_; i++) { + memcpy(audio_data_ + i * byte_per_sample, audio_data_tmp + i * byte_per_sample + skip_bytes, + (bit_per_sample_ / 8)); } + + ntxm_free(audio_data_tmp); } else { size_t bytes_read = fread(audio_data_, 1, chunk_size, fileh); if (bytes_read < chunk_size) { From 10ccaa588a2d64cfc58a97fbf6abb95ff76c31a7 Mon Sep 17 00:00:00 2001 From: prayerie Date: Sun, 3 May 2026 20:02:57 +0100 Subject: [PATCH 2/2] whoops accidentally removed skip_bytes --- libntxm/arm9/source/wav.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libntxm/arm9/source/wav.cpp b/libntxm/arm9/source/wav.cpp index 1a8cf37..0f51243 100644 --- a/libntxm/arm9/source/wav.cpp +++ b/libntxm/arm9/source/wav.cpp @@ -198,6 +198,7 @@ bool Wav::load(const char *filename) // Read the data if(bit_per_sample > bit_per_sample_) { + int skip_bytes = (bit_per_sample - bit_per_sample_) / 8; int byte_per_sample = bit_per_sample_/8; u8 *audio_data_tmp = (u8*)ntxm_umalloc(chunk_size);