From bb8197075161f9c9ded51beab913150b43954e2c Mon Sep 17 00:00:00 2001 From: skal Date: Mon, 2 Mar 2026 09:38:46 +0100 Subject: feat(audio): OLA-IDCT synthesis with Hann window to eliminate clicks Add v2 spectrogram format (SPEC_VERSION_V2_OLA) using overlap-add IDCT with 50% overlap (hop=256, OLA_OVERLAP=256) and Hann windowing. - dct.h: OLA_HOP_SIZE=256, OLA_OVERLAP=256 - synth.h: SPEC_VERSION_V1/V2_OLA constants; version field on Spectrogram - window.h/cc: hann_window_512() alongside existing hamming_window_512() - synth.cc: g_hann[] precomputed at init; OLA path in synth_render when ola_mode=true (IDCT -> Hann -> add overlap tail -> save new tail -> output OLA_HOP_SIZE samples); v1 path unchanged for backward compat - tracker.cc: MP3 encoder now uses sliding 512-sample Hann window with OLA_HOP_SIZE advance per frame; sets version=SPEC_VERSION_V2_OLA; .spec files propagate header->version; generated notes stay v1 Existing .spec files must be regenerated to benefit from click-free OLA. handoff(Claude): OLA done. .spec files need regen via MP3 tool to activate v2. --- src/audio/window.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/audio/window.cc') diff --git a/src/audio/window.cc b/src/audio/window.cc index b68c747..bcdd768 100644 --- a/src/audio/window.cc +++ b/src/audio/window.cc @@ -12,3 +12,11 @@ void hamming_window_512(float* window) { 0.54f - 0.46f * cosf(2.0f * PI * (float)i / (float)(WINDOW_SIZE - 1)); } } + +void hann_window_512(float* window) { + const float PI = 3.14159265358979323846f; + for (int i = 0; i < WINDOW_SIZE; ++i) { + window[i] = + 0.5f - 0.5f * cosf(2.0f * PI * (float)i / (float)(WINDOW_SIZE - 1)); + } +} -- cgit v1.2.3