this repo has no description
0
fork

Configure Feed

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

something is working

alice 296a6318 e85cdbd4

+96 -36
+1
cmake/core.cmake
··· 6 6 7 7 set(TIC80CORE_DIR ${CMAKE_SOURCE_DIR}/src) 8 8 set(TIC80CORE_SRC 9 + ${TIC80CORE_DIR}/fftdata.c 9 10 ${TIC80CORE_DIR}/core/core.c 10 11 ${TIC80CORE_DIR}/core/languages.c 11 12 ${TIC80CORE_DIR}/core/draw.c
+9
src/core/core.c
··· 20 20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 21 // SOFTWARE. 22 22 23 + #include "fftdata.h" 24 + #include "../ext/fft.h" 25 + 23 26 #include "api.h" 24 27 #include "core.h" 25 28 #include "tilesheet.h" ··· 462 465 463 466 core->data = data; 464 467 468 + FFT_GetFFT(fftData); 469 + printf("FFT_GetFFT has been called\n"); 470 + 465 471 if (!core->state.initialized) 466 472 { 467 473 const char* code = tic->cart.code.data; ··· 734 740 tic_core_blit_ex(tic, (tic_blit_callback){scanline, border, NULL}); 735 741 } 736 742 743 + 737 744 tic_mem* tic_core_create(s32 samplerate, tic80_pixel_color_format format) 738 745 { 739 746 tic_core* core = (tic_core*)malloc(sizeof(tic_core)); 740 747 memset(core, 0, sizeof(tic_core)); 741 748 749 + // fftData memset 750 + memset(fftData, 0, sizeof(float) * FFT_SIZE); 742 751 tic80* product = &core->memory.product; 743 752 744 753 core->screen_format = format;
+79 -35
src/ext/fft.c
··· 8 8 #include <stdio.h> 9 9 #include <memory.h> 10 10 #include "api.h" 11 + #include "fftdata.h" 11 12 12 13 ////////////////////////////////////////////////////////////////////////// 13 14 ··· 35 36 *(p++) = (samples[i * 2] + samples[i * 2 + 1]) / 2.0f * fAmplification; 36 37 } 37 38 38 - kiss_fftr(fftcfg, sampleBuf, fftBuf); 39 + // kiss_fftr(fftcfg, sampleBuf, fftBuf); 39 40 } 40 41 41 42 void FFT_EnumerateDevices(FFT_ENUMERATE_FUNC pEnumerationFunction, void* pUserContext) ··· 191 192 } 192 193 193 194 ////////////////////////////////////////////////////////////////////////// 194 - float fFFTSmoothingFactor = 0.9f; // higher value, smoother FFT 195 - static float fftDataSmoothed[FFT_SIZE] = {0}; // Initialize the array with zeros 196 195 static const float fPeakMinValue = 0.01f; 197 196 static const float fPeakSmoothing = 0.995f; 198 197 static float fPeakSmoothValue = 0.0f; 199 198 200 - double tic_api_fft(tic_mem* memory, s32 freq/*, bool bPeakNormalization, bool bSmoothing*/) 199 + bool FFT_GetFFT( float * _samples ) 201 200 { 202 - u32 interval = FFT_SIZE / 256 / 2; // the 2 is to discard super high frequencies, they suck 203 - freq = freq * interval; 204 - freq = fmin(freq, FFT_SIZE); 205 - freq = fmax(freq, 0); 206 - 207 - bool bPeakNormalization = true; 208 - bool bSmoothing = true; 201 + kiss_fft_cpx out[ FFT_SIZE + 1 ]; 202 + kiss_fftr( fftcfg, sampleBuf, out ); 209 203 204 + // TODO: make it an option? 205 + bool bPeakNormalization = true; 210 206 if (bPeakNormalization) { 211 207 float peakValue = fPeakMinValue; 212 - for (int i = freq; i < freq + interval; ++i) { 213 - float val = 2.0f * sqrtf(fftBuf[i].r * fftBuf[i].r + fftBuf[i].i * fftBuf[i].i); 214 - if (val > peakValue) { 215 - peakValue = val; 216 - } 208 + for ( int i = 0; i < FFT_SIZE; i++ ) 209 + { 210 + float val = 2.0f * sqrtf(out[i].r * out[i].r + out[i].i * out[i].i); 211 + if (val > peakValue) peakValue = val; 212 + _samples[ i ] = val * fAmplification; 217 213 } 218 214 if (peakValue > fPeakSmoothValue) { 219 215 fPeakSmoothValue = peakValue; ··· 221 217 if (peakValue < fPeakSmoothValue) { 222 218 fPeakSmoothValue = fPeakSmoothValue * fPeakSmoothing + peakValue * (1 - fPeakSmoothing); 223 219 } 224 - if (fPeakSmoothValue > 0.0f) { 225 - fAmplification = 1.0f / fPeakSmoothValue; 226 - } else { 227 - fAmplification = 1.0f; 220 + fAmplification = 1.0f / fPeakSmoothValue; 221 + } else { 222 + for (int i = 0; i < FFT_SIZE; i++) 223 + { 224 + static const float scaling = 1.0f / (float)FFT_SIZE; 225 + _samples[i] = 2.0f * sqrtf(out[i].r * out[i].r + out[i].i * out[i].i) * scaling * fAmplification; 228 226 } 229 227 } 230 228 231 - static const float scaling = 1.0f / (float)FFT_SIZE; 232 - float res = 0; 233 - for (int i = freq; i < freq + interval; ++i) { 234 - float val = 2.0f * sqrtf(fftBuf[i].r * fftBuf[i].r + fftBuf[i].i * fftBuf[i].i) * scaling * fAmplification; 235 - if (bSmoothing) { 236 - if (i < FFT_SIZE) { 237 - fftDataSmoothed[i] = fftDataSmoothed[i] * fFFTSmoothingFactor + (1 - fFFTSmoothingFactor) * val; 238 - res += fftDataSmoothed[i]; 239 - } 240 - } else { 241 - res += val; 242 - } 243 - } 229 + return true; 230 + } 231 + 232 + 233 + double tic_api_fft(tic_mem* memory, s32 freq) 234 + { 235 + return fftData[freq]; 236 + } 237 + 238 + // float fFFTSmoothingFactor = 0.9f; // higher value, smoother FFT 239 + // static float fftDataSmoothed[FFT_SIZE] = {0}; // Initialize the array with zeros 240 + // static const float fPeakMinValue = 0.01f; 241 + // static const float fPeakSmoothing = 0.995f; 242 + // static float fPeakSmoothValue = 0.0f; 243 + 244 + // double tic_api_fft(tic_mem* memory, s32 freq/*, bool bPeakNormalization, bool bSmoothing*/) 245 + // { 246 + // u32 interval = FFT_SIZE / 256 / 2; // the 2 is to discard super high frequencies, they suck 247 + // freq = freq * interval; 248 + // freq = fmin(freq, FFT_SIZE); 249 + // freq = fmax(freq, 0); 250 + 251 + // bool bPeakNormalization = true; 252 + // bool bSmoothing = true; 253 + 254 + // if (bPeakNormalization) { 255 + // float peakValue = fPeakMinValue; 256 + // for (int i = freq; i < freq + interval; ++i) { 257 + // float val = 2.0f * sqrtf(fftBuf[i].r * fftBuf[i].r + fftBuf[i].i * fftBuf[i].i); 258 + // if (val > peakValue) { 259 + // peakValue = val; 260 + // } 261 + // } 262 + // if (peakValue > fPeakSmoothValue) { 263 + // fPeakSmoothValue = peakValue; 264 + // } 265 + // if (peakValue < fPeakSmoothValue) { 266 + // fPeakSmoothValue = fPeakSmoothValue * fPeakSmoothing + peakValue * (1 - fPeakSmoothing); 267 + // } 268 + // if (fPeakSmoothValue > 0.0f) { 269 + // fAmplification = 1.0f / fPeakSmoothValue; 270 + // } else { 271 + // fAmplification = 1.0f; 272 + // } 273 + // } 274 + 275 + // static const float scaling = 1.0f / (float)FFT_SIZE; 276 + // float res = 0; 277 + // for (int i = freq; i < freq + interval; ++i) { 278 + // float val = 2.0f * sqrtf(fftBuf[i].r * fftBuf[i].r + fftBuf[i].i * fftBuf[i].i) * scaling * fAmplification; 279 + // if (bSmoothing) { 280 + // if (i < FFT_SIZE) { 281 + // fftDataSmoothed[i] = fftDataSmoothed[i] * fFFTSmoothingFactor + (1 - fFFTSmoothingFactor) * val; 282 + // res += fftDataSmoothed[i]; 283 + // } 284 + // } else { 285 + // res += val; 286 + // } 287 + // } 244 288 245 - return res; 246 - } 289 + // return res; 290 + // }
+3 -1
src/ext/fft.h
··· 1 1 #pragma once 2 - #define FFT_SIZE 2048 2 + // #define FFT_SIZE 2048 3 + #define FFT_SIZE 1024 3 4 #include <stdbool.h> 5 + 4 6 5 7 // typedef int BOOL; 6 8 //////////////////////////////////////////////////////////////////////////
+2
src/fftdata.c
··· 1 + #include "fftdata.h" 2 + float fftData[1024] = {0};
+2
src/fftdata.h
··· 1 + #pragma once 2 + extern float fftData[1024];