this repo has no description
0
fork

Configure Feed

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

add normalization; weird bugs happening where it sometimes works sometimes not; needs investigation; time to add debug logging

alice b3efa3f1 04ee60a0

+51 -10
+5
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 471 471 472 if (!core->state.initialized) 472 473 { ··· 748 749 749 750 // fftData memset 750 751 memset(fftData, 0, sizeof(float) * FFT_SIZE); 752 + memset(fftSmoothingData, 0, sizeof(float) * FFT_SIZE); 753 + memset(fftNormalizedData, 0, sizeof(float) * FFT_SIZE); 754 + memset(fftNormalizedMaxData, 0, sizeof(float) * FFT_SIZE); 755 + 751 756 tic80* product = &core->memory.product; 752 757 753 758 core->screen_format = format;
+29 -8
src/ext/fft.c
··· 1 1 //TODO: disable this in the end 2 2 #define MA_DEBUG_OUTPUT 3 3 #define MINIAUDIO_IMPLEMENTATION 4 + #include "../fftdata.h" 4 5 #include "fft.h" 5 6 #include "miniaudio.h" 6 7 ··· 229 230 fPeakSmoothValue = fPeakSmoothValue * fPeakSmoothing + peakValue * (1 - fPeakSmoothing); 230 231 } 231 232 fAmplification = 1.0f / fPeakSmoothValue; 232 - float fFFTSmoothingFactor = 0.9; 233 - for ( int i = 0; i < FFT_SIZE; i++ ) 234 - { 235 - _samples[i] = _samples[i] * fFFTSmoothingFactor + (1 - fFFTSmoothingFactor) * _samples[i]; 236 - } 237 233 } else { 238 234 for (int i = 0; i < FFT_SIZE; i++) 239 235 { ··· 242 238 } 243 239 } 244 240 245 - return true; 241 + float fFFTSmoothingFactor = 0.9; 242 + bool bSmoothing = true; 243 + if (bSmoothing) 244 + { 245 + for ( int i = 0; i < FFT_SIZE; i++ ) 246 + { 247 + fftSmoothingData[i] = fftSmoothingData[i] * fFFTSmoothingFactor + (1 - fFFTSmoothingFactor) * _samples[i]; 248 + } 249 + } 250 + 251 + bool bNormalization = true; 252 + if (bNormalization) 253 + { 254 + for ( int i = 0; i < FFT_SIZE; i++ ) 255 + { 256 + float v = fftSmoothingData[i]; 257 + fftNormalizedMaxData[i] = MAX(fftNormalizedMaxData[i], v); 258 + fftNormalizedData[i] = v / MAX(0.001, fftNormalizedMaxData[i]); 259 + fftNormalizedMaxData[i] = fftNormalizedMaxData[i] * 0.9999; 260 + } 261 + } 262 + 263 + return true; 246 264 } 247 265 248 - double tic_api_fft(tic_mem* memory, s32 freq) 266 + double tic_api_fft(tic_mem* memory, s32 freq/*, bool bSmoothing, bool bNormalization*/) 249 267 { 250 - return fftData[freq]; 268 + // if (bSmoothing) return fftSmoothingData[freq]; 269 + // return fftData[freq]; 270 + return fftSmoothingData[freq]; 271 + // return fftNormalizedData[freq]; 251 272 }
+4 -1
src/fftdata.c
··· 3 3 float fPeakSmoothing = 0.995f; 4 4 float fPeakSmoothValue = 0.0f; 5 5 float fAmplification = 1.0f; 6 - float fftData[FFT_SIZE] = {0}; 6 + float fftData[FFT_SIZE] = {0}; 7 + float fftSmoothingData[FFT_SIZE] = {0}; 8 + float fftNormalizedData[FFT_SIZE] = {0}; 9 + float fftNormalizedMaxData[FFT_SIZE] = {0};
+4 -1
src/fftdata.h
··· 4 4 extern float fPeakSmoothing; 5 5 extern float fPeakSmoothValue; 6 6 extern float fAmplification; 7 - extern float fftData[FFT_SIZE]; 7 + extern float fftData[FFT_SIZE]; 8 + extern float fftSmoothingData[FFT_SIZE]; 9 + extern float fftNormalizedData[FFT_SIZE]; 10 + extern float fftNormalizedMaxData[FFT_SIZE];
+9
src/studio/studio.c
··· 21 21 // SOFTWARE. 22 22 23 23 #include "studio.h" 24 + #include "../fftdata.h" 24 25 25 26 #if defined(BUILD_EDITORS) 26 27 ··· 1561 1562 1562 1563 void runGame(Studio* studio) 1563 1564 { 1565 + fPeakMinValue = 0.01f; 1566 + fPeakSmoothing = 0.995f; 1567 + fPeakSmoothValue = 0.0f; 1568 + fAmplification = 1.0f; 1569 + memset(fftData, 0, sizeof(fftData[0]) * FFT_SIZE); 1570 + memset(fftSmoothingData, 0, sizeof(fftSmoothingData[0]) * FFT_SIZE); 1571 + memset(fftNormalizedData, 0, sizeof(fftNormalizedData[0]) * FFT_SIZE); 1572 + memset(fftNormalizedMaxData, 0, sizeof(fftNormalizedMaxData[0]) * FFT_SIZE); 1564 1573 #if defined(BUILD_EDITORS) 1565 1574 if(studio->console->args.keepcmd 1566 1575 && studio->console->commands.count