this repo has no description
0
fork

Configure Feed

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

debug function, some formatting etc.

alice 81534c9c b4ff76dd

+79 -29
+1 -1
src/core/core.c
··· 467 467 468 468 // TODO: make it conditional 469 469 FFT_GetFFT(fftData); 470 - printf("FFT_GetFFT got called\n"); 470 + FFT_DebugLog(FFT_LOG_TRACE, "FFT_GetFFT got called\n"); 471 471 472 472 if (!core->state.initialized) 473 473 {
+24 -22
src/ext/fft.c
··· 23 23 24 24 void miniaudioLogCallback(void *userData, ma_uint32 level, const char *message) 25 25 { 26 - // (void)userData; 26 + FFT_DebugLog(FFT_LOG_TRACE, "miniaudioLogCallback got called\n"); 27 + // TODO: I don't know why we need this or if we even need this but, whatever 28 + (void)userData; 27 29 switch (level) { 28 30 case MA_LOG_LEVEL_DEBUG: 29 - printf( "[FFT] DEBUG log: %s", message ); 30 - break; 31 + printf( "[FFT] DEBUG log: %s", message ); 32 + break; 31 33 case MA_LOG_LEVEL_INFO: 32 - printf( "[FFT] INFO log: %s", message ); 33 - break; 34 + printf( "[FFT] INFO log: %s", message ); 35 + break; 34 36 case MA_LOG_LEVEL_WARNING: 35 - printf( "[FFT] WARNING log: %s", message ); 36 - break; 37 + printf( "[FFT] WARNING log: %s", message ); 38 + break; 37 39 case MA_LOG_LEVEL_ERROR: 38 - printf( "[FFT] ERROR log: %s", message ); 39 - break; 40 + printf( "[FFT] ERROR log: %s", message ); 41 + break; 40 42 } 41 43 42 44 return; ··· 44 46 45 47 void OnReceiveFrames(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) 46 48 { 47 - frameCount = frameCount < FFT_SIZE * 2 ? frameCount : FFT_SIZE * 2; 49 + frameCount = frameCount < FFT_SIZE * 2 ? frameCount : FFT_SIZE * 2; 48 50 49 51 // Just rotate the buffer; copy existing, append new 50 - const float* samples = (const float*)pInput; 51 - float* p = sampleBuf; 52 - for (int i = 0; i < FFT_SIZE * 2 - frameCount; i++) 53 - { 54 - *(p++) = sampleBuf[i + frameCount]; 55 - } 56 - for (int i = 0; i < frameCount; i++) 57 - { 58 - *(p++) = (samples[i * 2] + samples[i * 2 + 1]) / 2.0f * fAmplification; 59 - } 52 + const float* samples = (const float*)pInput; 53 + float* p = sampleBuf; 54 + for (int i = 0; i < FFT_SIZE * 2 - frameCount; i++) 55 + { 56 + *(p++) = sampleBuf[i + frameCount]; 57 + } 58 + for (int i = 0; i < frameCount; i++) 59 + { 60 + *(p++) = (samples[i * 2] + samples[i * 2 + 1]) / 2.0f * fAmplification; 61 + } 60 62 } 61 63 62 64 // void FFT_EnumerateDevices(FFT_ENUMERATE_FUNC pEnumerationFunction, void* pUserContext) ··· 281 283 { 282 284 // if (bSmoothing) return fftSmoothingData[freq]; 283 285 // return fftData[freq]; 284 - return fftSmoothingData[freq]; 285 - // return fftNormalizedData[freq]; 286 + // return fftSmoothingData[freq]; 287 + return fftNormalizedData[freq]; 286 288 }
+41 -5
src/fftdata.c
··· 1 1 #include "fftdata.h" 2 2 #include <stdarg.h> // For va_list 3 3 #include <stdio.h> // for vprintf 4 + #include <time.h> 4 5 5 6 #define FFT_DEBUG 6 7 7 - void FFT_DebugLog(const char* format, ...) 8 + FFT_LogLevel g_currentLogLevel = FFT_LOG_DEBUG; 9 + 10 + void FFT_DebugLog(FFT_LogLevel level, const char* format, ...) 8 11 { 9 12 #ifdef FFT_DEBUG 10 - va_list args; 11 - va_start(args, format); 12 - vprintf(format, args); 13 - va_end(args); 13 + if (level <= g_currentLogLevel) { 14 + // Get current time 15 + time_t now = time(NULL); 16 + struct tm *tm_now = localtime(&now); 17 + char time_str[20]; // ISO 8601 format requires 19 characters + null terminator 18 + strftime(time_str, sizeof(time_str), "%Y-%m-%dT%H:%M:%S", tm_now); 19 + 20 + // Print time and log level 21 + printf("%s ", time_str); // Print the time 22 + va_list args; 23 + va_start(args, format); 24 + switch(level) { 25 + case FFT_LOG_TRACE: 26 + printf("[FFT TRACE]: "); 27 + break; 28 + case FFT_LOG_DEBUG: 29 + printf("[FFT DEBUG]: "); 30 + break; 31 + case FFT_LOG_INFO: 32 + printf("[FFT INFO]: "); 33 + break; 34 + case FFT_LOG_WARNING: 35 + printf("[FFT WARNING]: "); 36 + break; 37 + case FFT_LOG_ERROR: 38 + printf("[FFT ERROR]: "); 39 + break; 40 + case FFT_LOG_FATAL: 41 + printf("[FFT FATAL]: "); 42 + break; 43 + case FFT_LOG_OFF: 44 + // Optionally handle the OFF level by returning early or similar 45 + return; 46 + } 47 + vprintf(format, args); 48 + va_end(args); 49 + } 14 50 #endif 15 51 } 16 52 float fPeakMinValue = 0.01f;
+13 -1
src/fftdata.h
··· 9 9 extern float fftNormalizedData[FFT_SIZE]; 10 10 extern float fftNormalizedMaxData[FFT_SIZE]; 11 11 12 - void FFT_DebugLog(const char* format, ...); 12 + typedef enum { 13 + FFT_LOG_OFF = 0, 14 + FFT_LOG_FATAL, 15 + FFT_LOG_ERROR, 16 + FFT_LOG_WARNING, 17 + FFT_LOG_INFO, 18 + FFT_LOG_DEBUG, 19 + FFT_LOG_TRACE 20 + } FFT_LogLevel; 21 + 22 + extern FFT_LogLevel g_currentLogLevel; 23 + 24 + void FFT_DebugLog(FFT_LogLevel level, const char *format, ...);