this repo has no description
0
fork

Configure Feed

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

bench

alice 924b9be5 35b0242a

+94 -2
+94 -2
src/ext/cqt.c
··· 8 8 #include <string.h> 9 9 #include <stdbool.h> 10 10 #include <stdio.h> 11 + #include <time.h> 11 12 12 13 #define CQT_DEBUG 13 14 ··· 16 17 static float* cqtAudioBuffer = NULL; 17 18 static kiss_fft_cpx* cqtFftOutput = NULL; 18 19 20 + // Benchmark different FFT sizes 21 + static void CQT_BenchmarkFFT(void) 22 + { 23 + printf("\nCQT FFT Benchmark on this CPU:\n"); 24 + printf("================================\n"); 25 + 26 + int sizes[] = {4096, 6144, 8192, 12288, 16384}; 27 + int numSizes = 5; 28 + 29 + for (int s = 0; s < numSizes; s++) 30 + { 31 + int fftSize = sizes[s]; 32 + 33 + // Allocate buffers 34 + float* testInput = (float*)calloc(fftSize, sizeof(float)); 35 + kiss_fft_cpx* testOutput = (kiss_fft_cpx*)malloc((fftSize/2 + 1) * sizeof(kiss_fft_cpx)); 36 + kiss_fftr_cfg testCfg = kiss_fftr_alloc(fftSize, 0, NULL, NULL); 37 + 38 + if (!testInput || !testOutput || !testCfg) 39 + { 40 + printf("Failed to allocate for size %d\n", fftSize); 41 + continue; 42 + } 43 + 44 + // Fill with test signal 45 + for (int i = 0; i < fftSize; i++) 46 + { 47 + testInput[i] = sin(2.0 * M_PI * 440.0 * i / 44100.0); 48 + } 49 + 50 + // Warm up 51 + for (int i = 0; i < 10; i++) 52 + { 53 + kiss_fftr(testCfg, testInput, testOutput); 54 + } 55 + 56 + // Time 100 iterations 57 + clock_t start = clock(); 58 + for (int i = 0; i < 100; i++) 59 + { 60 + kiss_fftr(testCfg, testInput, testOutput); 61 + } 62 + clock_t end = clock(); 63 + 64 + double avgTime = (double)(end - start) / CLOCKS_PER_SEC * 1000.0 / 100.0; 65 + printf("%5d-point FFT: %.3f ms\n", fftSize, avgTime); 66 + 67 + // Cleanup 68 + free(testInput); 69 + free(testOutput); 70 + free(testCfg); 71 + } 72 + 73 + printf("================================\n\n"); 74 + } 75 + 19 76 // Initialize CQT processing 20 77 bool CQT_Open(void) 21 78 { ··· 56 113 { 57 114 CQT_Close(); 58 115 return false; 116 + } 117 + 118 + // Run FFT benchmark on first initialization 119 + static bool benchmarkRun = false; 120 + if (!benchmarkRun) 121 + { 122 + CQT_BenchmarkFFT(); 123 + benchmarkRun = true; 59 124 } 60 125 61 126 // Debug: Print first few center frequencies and expected FFT bins ··· 172 237 return; 173 238 } 174 239 175 - // Perform 4096-point FFT 240 + // Profiling variables 241 + static double totalFftTime = 0.0; 242 + static double totalKernelTime = 0.0; 243 + static int profileCount = 0; 244 + 245 + // Perform 6144-point FFT with timing 246 + clock_t fftStart = clock(); 176 247 kiss_fftr(cqtFftCfg, cqtAudioBuffer, cqtFftOutput); 248 + clock_t fftEnd = clock(); 177 249 178 250 // Extract real and imaginary components for kernel application 179 251 float fftReal[CQT_FFT_SIZE/2 + 1]; ··· 185 257 fftImag[i] = cqtFftOutput[i].i; 186 258 } 187 259 188 - // Apply CQT kernels 260 + // Apply CQT kernels with timing 261 + clock_t kernelStart = clock(); 189 262 CQT_ApplyKernels(fftReal, fftImag); 263 + clock_t kernelEnd = clock(); 264 + 265 + // Calculate times in milliseconds 266 + double fftTime = (double)(fftEnd - fftStart) / CLOCKS_PER_SEC * 1000.0; 267 + double kernelTime = (double)(kernelEnd - kernelStart) / CLOCKS_PER_SEC * 1000.0; 268 + 269 + totalFftTime += fftTime; 270 + totalKernelTime += kernelTime; 271 + profileCount++; 272 + 273 + // Print profiling info every 60 frames (~1 second) 274 + if (profileCount % 60 == 0) 275 + { 276 + printf("CQT Performance (6K FFT):\n"); 277 + printf(" FFT avg: %.3fms\n", totalFftTime / profileCount); 278 + printf(" Kernels avg: %.3fms\n", totalKernelTime / profileCount); 279 + printf(" Total avg: %.3fms\n", (totalFftTime + totalKernelTime) / profileCount); 280 + printf(" Samples: %d\n\n", profileCount); 281 + } 190 282 191 283 #ifdef CQT_DEBUG 192 284 // Reduced debug output - CQT is working correctly now