this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

GPT5-high pass 3: spectral whitening pt1

alice 7164a4dd 6f329b30

+66
+49
src/ext/vqt.c
··· 281 281 clock_t kernelStart = clock(); 282 282 VQT_ApplyKernels(fftReal, fftImag); 283 283 clock_t kernelEnd = clock(); 284 + 285 + // Optional spectral whitening to flatten spectral envelope for clearer peaks 286 + #if VQT_SPECTRAL_WHITENING_ENABLED 287 + { 288 + const float eps = VQT_WHITENING_EPS; 289 + int width = VQT_WHITENING_WIDTH_BINS; 290 + if (width < 1) width = 1; 291 + int half = width / 2; 292 + float alpha = VQT_WHITENING_STRENGTH; 293 + if (alpha < 0.0f) alpha = 0.0f; else if (alpha > 1.0f) alpha = 1.0f; 294 + 295 + float logM[VQT_BINS]; 296 + float env[VQT_BINS]; 297 + 298 + // Log domain magnitudes 299 + for (int i = 0; i < VQT_BINS; i++) 300 + { 301 + float m = vqtData[i]; 302 + if (!isfinite(m) || m < 0.0f) m = 0.0f; 303 + logM[i] = logf(m + eps); 304 + } 305 + 306 + // Smooth spectral envelope with a simple box filter of width 'width' 307 + for (int i = 0; i < VQT_BINS; i++) 308 + { 309 + int start = i - half; 310 + int end = i + half; 311 + if (start < 0) start = 0; 312 + if (end >= VQT_BINS) end = VQT_BINS - 1; 313 + float sum = 0.0f; 314 + int count = 0; 315 + for (int j = start; j <= end; j++) { sum += logM[j]; count++; } 316 + env[i] = count > 0 ? sum / (float)count : logM[i]; 317 + } 318 + 319 + // Whiten: ratio in log domain, baseline to 0 (exp(w)-1), mix in amplitude domain 320 + for (int i = 0; i < VQT_BINS; i++) 321 + { 322 + float m = vqtData[i]; 323 + if (!isfinite(m) || m < 0.0f) m = 0.0f; 324 + float wLog = logM[i] - env[i]; // log(m+eps) - log(env) 325 + float wAmp = expf(wLog) - 1.0f; // = (m+eps)/env - 1 → 0 on flat 326 + if (!isfinite(wAmp) || wAmp < 0.0f) wAmp = 0.0f; 327 + float mp = (1.0f - alpha) * m + alpha * wAmp; 328 + if (!isfinite(mp) || mp < 0.0f) mp = 0.0f; 329 + vqtData[i] = mp; 330 + } 331 + } 332 + #endif 284 333 285 334 // Calculate times in milliseconds 286 335 double fftTime = (double)(fftEnd - fftStart) / CLOCKS_PER_SEC * 1000.0;
+17
src/vqtdata.h
··· 15 15 #define VQT_SMOOTHING_FACTOR 0.3f // Reduced from 0.7f for more responsive display 16 16 #define VQT_SPARSITY_THRESHOLD 0.01f 17 17 18 + // Spectral whitening configuration (disabled by default) 19 + #ifndef VQT_SPECTRAL_WHITENING_ENABLED 20 + #define VQT_SPECTRAL_WHITENING_ENABLED 1 21 + #endif 22 + 23 + #ifndef VQT_WHITENING_WIDTH_BINS 24 + #define VQT_WHITENING_WIDTH_BINS 11 // odd window width for envelope smoothing 25 + #endif 26 + 27 + #ifndef VQT_WHITENING_STRENGTH 28 + #define VQT_WHITENING_STRENGTH 0.7f // 0..1 mix toward whitened spectrum 29 + #endif 30 + 31 + #ifndef VQT_WHITENING_EPS 32 + #define VQT_WHITENING_EPS 1e-6f // floor to stabilize log domain 33 + #endif 34 + 18 35 // Raw VQT magnitude data 19 36 extern float vqtData[VQT_BINS]; 20 37