summaryrefslogtreecommitdiff
path: root/tools/spectool.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-01-28 11:26:36 +0100
committerskal <pascal.massimino@gmail.com>2026-01-28 11:26:36 +0100
commit7d022d9a3923eb35f3acd3ed4a1795c497bc53ee (patch)
tree572c7a94fc4bffd1c2744175932ddb1556853413 /tools/spectool.cc
parent58a9a7c2426f543471747165131f37c766691997 (diff)
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.
Diffstat (limited to 'tools/spectool.cc')
-rw-r--r--tools/spectool.cc18
1 files changed, 18 insertions, 0 deletions
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) {