summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-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) {