From 7d022d9a3923eb35f3acd3ed4a1795c497bc53ee Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 28 Jan 2026 11:26:36 +0100 Subject: feat(spectool): Optimize .spec file size by trimming trailing zeros Implements logic to remove unused trailing zero frames from spectrogram data before saving, reducing file size and improving loading efficiency. --- tools/spectool.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tools/spectool.cc') diff --git a/tools/spectool.cc b/tools/spectool.cc index e57e77b..954aa52 100644 --- a/tools/spectool.cc +++ b/tools/spectool.cc @@ -67,6 +67,24 @@ int analyze_audio(const char *in_path, const char *out_path) { ma_decoder_uninit(&decoder); + // Trim trailing zero frames + int last_frame = spec_data.size() / DCT_SIZE; + while (last_frame > 0) { + bool all_zeros = true; + for (int i = 0; i < DCT_SIZE; ++i) { + if (spec_data[ (last_frame - 1) * DCT_SIZE + i ] != 0.0f) { + all_zeros = false; + break; + } + } + if (all_zeros) { + last_frame--; + } else { + break; + } + } + spec_data.resize(last_frame * DCT_SIZE); + // Write to .spec file FILE *f_out = fopen(out_path, "wb"); if (!f_out) { -- cgit v1.2.3