this repo has no description
0
fork

Configure Feed

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

refactor; simplify; enumerate

alice 713a934a ef51394a

+59 -198
+45 -157
src/ext/fft.c
··· 1 + //TODO: disable this in the end 1 2 #define MA_DEBUG_OUTPUT 2 3 #define MINIAUDIO_IMPLEMENTATION 3 4 #include "fft.h" ··· 19 20 bool bCreated = false; 20 21 kiss_fft_cpx fftBuf[FFT_SIZE + 1]; 21 22 23 + void miniaudioLogCallback(void *userData, ma_uint32 level, const char *message) 24 + { 25 + // (void)userData; 26 + printf( "[FFT] log: %s", message ); 27 + return; 28 + } 29 + 22 30 void OnReceiveFrames(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) 23 31 { 24 32 frameCount = frameCount < FFT_SIZE * 2 ? frameCount : FFT_SIZE * 2; ··· 34 42 { 35 43 *(p++) = (samples[i * 2] + samples[i * 2 + 1]) / 2.0f * fAmplification; 36 44 } 37 - 38 - // kiss_fftr(fftcfg, sampleBuf, fftBuf); 39 45 } 40 46 41 47 // void FFT_EnumerateDevices(FFT_ENUMERATE_FUNC pEnumerationFunction, void* pUserContext) 42 - // { 43 - // if (!bCreated) 44 - // { 45 - // return; 46 - // } 48 + void FFT_EnumerateDevices() 49 + { 47 50 48 - // ma_device_info* pPlaybackDevices = NULL; 49 - // ma_device_info* pCaptureDevices = NULL; 50 - // ma_uint32 nPlaybackDeviceCount = 0; 51 - // ma_uint32 nCaptureDeviceCount = 0; 52 - // ma_result result = ma_context_get_devices(&context, &pPlaybackDevices, &nPlaybackDeviceCount, &pCaptureDevices, &nCaptureDeviceCount); 53 - // if (result != MA_SUCCESS) 54 - // { 55 - // printf("[FFT] Failed to enumerate audio devices: %d\n", result); 56 - // return; 57 - // } 51 + ma_context_config context_config = ma_context_config_init(); 52 + ma_log log; 53 + ma_log_init(NULL, &log); 54 + ma_log_register_callback(&log, ma_log_callback_init(miniaudioLogCallback, NULL)); 58 55 59 - // pEnumerationFunction(true, "<default device>", NULL, pUserContext); 60 - // for (ma_uint32 i = 0; i < nCaptureDeviceCount; i++) 61 - // { 62 - // pEnumerationFunction(true, pCaptureDevices[i].name, &pCaptureDevices[i].id, pUserContext); 63 - // } 64 - // if (ma_is_loopback_supported(context.backend)) 65 - // { 66 - // pEnumerationFunction(false, "<default device>", NULL, pUserContext); 67 - // for (ma_uint32 i = 0; i < nPlaybackDeviceCount; i++) 68 - // { 69 - // pEnumerationFunction(false, pPlaybackDevices[i].name, &pPlaybackDevices[i].id, pUserContext); 70 - // } 71 - // } 72 - // } 56 + context_config.pLog = &log; 73 57 74 - void miniaudioLogCallback(void *userData, ma_uint32 level, const char *message) 75 - { 76 - (void)userData; 58 + ma_result result = ma_context_init(NULL, 0, &context_config, &context); 59 + if (result != MA_SUCCESS) 60 + { 61 + printf("[FFT] Failed to initialize context: %s", ma_result_description(result)); 77 62 return; 78 - } 63 + } 79 64 80 - // bool FFT_Create() 81 - // { 82 - // bCreated = false; 83 - // ma_context_config context_config = ma_context_config_init(); 84 - // ma_log log; 85 - // ma_log_init(NULL, &log); 86 - // ma_log_register_callback(&log, ma_log_callback_init(miniaudioLogCallback, NULL)); 65 + printf( "[FFT] MAL context initialized, backend is '%s'\n", ma_get_backend_name( context.backend ) ); 87 66 88 - // context_config.pLog = &log; 89 - // ma_result result = ma_context_init(NULL, 0, &context_config, &context); 90 - // if (result != MA_SUCCESS) 91 - // { 92 - // printf("[FFT] Failed to initialize context: %d", result); 93 - // return false; 94 - // } 95 - 96 - // printf("[FFT] MAL context initialized, backend is '%s'\n", ma_get_backend_name(context.backend)); 97 - // bCreated = true; 98 - // return true; 99 - // } 67 + ma_device_info* pPlaybackDeviceInfos; 68 + ma_uint32 playbackDeviceCount; 69 + ma_device_info* pCaptureDeviceInfos; 70 + ma_uint32 captureDeviceCount; 71 + result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); 72 + if (result != MA_SUCCESS) { 73 + printf("Failed to retrieve device information.\n"); 74 + printf("Error: %s\n", ma_result_description(result)); 75 + return; 76 + } 100 77 101 - bool FFT_Destroy() 102 - { 103 - if (!bCreated) 104 - { 105 - return false; 78 + printf("Playback Devices\n"); 79 + for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { 80 + printf(" %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name); 106 81 } 82 + 83 + printf("\n"); 107 84 108 - ma_context_uninit(&context); 85 + printf("Capture Devices\n"); 86 + for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { 87 + printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name); 88 + } 109 89 110 - bCreated = false; 90 + printf("\n"); 111 91 112 - return true; 92 + return; 113 93 } 114 - 115 94 116 95 bool FFT_Open(bool CapturePlaybackDevices, const char* CaptureDeviceSearchString) 117 96 { ··· 159 138 printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name); 160 139 } 161 140 162 - // if(strlen(CaptureDeviceSearchString) > 0) { 163 - // if(CapturePlaybackDevices) { 164 - // for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { 165 - // std::string DeviceName = pPlaybackDeviceInfos[iDevice].name; 166 - // if(DeviceName.find(CaptureDeviceSearchString) != std::string::npos ){ 167 - // TargetDevice = &pPlaybackDeviceInfos[iDevice].id; 168 - // break; 169 - // } 170 - // } 171 - // } else { 172 - // for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { 173 - // std::string DeviceName = pCaptureDeviceInfos[iDevice].name; 174 - // if(DeviceName.find(CaptureDeviceSearchString) != std::string::npos ){ 175 - // TargetDevice = &pCaptureDeviceInfos[iDevice].id; 176 - // break; 177 - // } 178 - // } 179 - // } 180 - // } 181 - 182 141 printf("\n"); 183 142 184 - // bool useLoopback = ma_is_loopback_supported(context.backend) && !pSettings->bUseRecordingDevice; 185 - // ma_device_config config = ma_device_config_init(useLoopback ? ma_device_type_loopback : ma_device_type_capture); 186 - // config.capture.pDeviceID = (ma_device_id*)pSettings->pDeviceID; 187 - // config.capture.format = ma_format_f32; 188 - // config.capture.channels = 2; 189 - // config.sampleRate = 44100; 190 - // config.dataCallback = OnReceiveFrames; 191 - // config.pUserData = NULL; 192 - 143 + // for now always prefer loopback 144 + // TODO: what about CapturePlaybackDevices? 193 145 bool useLoopback = ma_is_loopback_supported(context.backend); 194 146 ma_device_config config = ma_device_config_init(useLoopback ? ma_device_type_loopback : ma_device_type_capture); 195 - 196 147 // ma_device_config config = ma_device_config_init( CapturePlaybackDevices ? ma_device_type_loopback : ma_device_type_capture ); 197 148 config.capture.pDeviceID = TargetDevice; 198 149 config.capture.format = ma_format_f32; ··· 223 174 return true; 224 175 } 225 176 226 - // bool FFT_Open(FFT_Settings* pSettings) 227 - // { 228 - // if (!bCreated) 229 - // { 230 - // return false; 231 - // } 232 - 233 - // memset(sampleBuf, 0, sizeof(float) * FFT_SIZE * 2); 234 - 235 - // fftcfg = kiss_fftr_alloc(FFT_SIZE * 2, false, NULL, NULL); 236 - 237 - // ma_device_info* pPlaybackDeviceInfos; 238 - // ma_uint32 playbackDeviceCount; 239 - // ma_device_info* pCaptureDeviceInfos; 240 - // ma_uint32 captureDeviceCount; 241 - // ma_result result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount); 242 - // if (result != MA_SUCCESS) { 243 - // printf("Failed to retrieve device information.\n"); 244 - // return false; 245 - // } 246 - 247 - // printf("Playback Devices\n"); 248 - // for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) { 249 - // printf(" %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name); 250 - // } 251 - 252 - // printf("\n"); 253 - 254 - // printf("Capture Devices\n"); 255 - // for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) { 256 - // printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name); 257 - // } 258 - 259 - // config.capture.pDeviceID = (ma_device_id*)pSettings->pDeviceID; 260 - // config.capture.format = ma_format_f32; 261 - // config.capture.channels = 2; 262 - // config.sampleRate = 44100; 263 - // config.dataCallback = OnReceiveFrames; 264 - // config.pUserData = NULL; 265 - 266 - // result = ma_device_init(&context, &config, &captureDevice); 267 - // if (result != MA_SUCCESS) 268 - // { 269 - // ma_context_uninit(&context); 270 - // printf("[FFT] Failed to initialize capture device: %d\n", result); 271 - // return false; 272 - // } 273 - 274 - // printf("[FFT] Selected capture device: %s\n", captureDevice.capture.name); 275 - 276 - // result = ma_device_start(&captureDevice); 277 - // if (result != MA_SUCCESS) 278 - // { 279 - // ma_device_uninit(&captureDevice); 280 - // ma_context_uninit(&context); 281 - // printf("[FFT] Failed to start capture device: %d\n", result); 282 - // return false; 283 - // } 284 - 285 - // return true; 286 - // } 287 - 288 177 void FFT_Close() 289 178 { 290 179 if (!bCreated) ··· 293 182 } 294 183 295 184 ma_device_stop(&captureDevice); 296 - 297 185 ma_device_uninit(&captureDevice); 298 - 186 + ma_context_uninit(&context); 299 187 kiss_fft_free(fftcfg); 300 188 } 301 189
+13 -18
src/ext/fft.h
··· 1 1 #pragma once 2 2 #include <stdbool.h> 3 3 4 + ////////////////////////////////////////////////////////////////////////// 4 5 5 - // typedef int BOOL; 6 - ////////////////////////////////////////////////////////////////////////// 6 + typedef struct FFT_Settings 7 + { 8 + bool bUseRecordingDevice; 9 + void* pDeviceID; 10 + } FFT_Settings; 7 11 8 - typedef struct FFT_Settings 9 - { 10 - bool bUseRecordingDevice; 11 - void* pDeviceID; 12 - } FFT_Settings; 12 + // typedef void (*FFT_ENUMERATE_FUNC)(const bool bIsCaptureDevice, const char* szDeviceName, void* pDeviceID, void* pUserContext); 13 13 14 - typedef void (*FFT_ENUMERATE_FUNC)(const bool bIsCaptureDevice, const char* szDeviceName, void* pDeviceID, void* pUserContext); 15 - 16 - void FFT_EnumerateDevices(FFT_ENUMERATE_FUNC pEnumerationFunction, void* pUserContext); 14 + bool FFT_Open(bool CapturePlaybackDevices, const char* CaptureDeviceSearchString); 15 + // void FFT_EnumerateDevices(FFT_ENUMERATE_FUNC pEnumerationFunction, void* pUserContext); 16 + void FFT_EnumerateDevices(); 17 + bool FFT_GetFFT(float* _samples); 18 + void FFT_Close(); 17 19 18 - bool FFT_Create(); 19 - bool FFT_Destroy(); 20 - // bool FFT_Open(FFT_Settings* pSettings); 21 - bool FFT_Open(bool CapturePlaybackDevices, const char* CaptureDeviceSearchString); 22 - bool FFT_GetFFT(float* _samples); 23 - void FFT_Close(); 24 - 25 - ////////////////////////////////////////////////////////////////////////// 20 + //////////////////////////////////////////////////////////////////////////
+1 -2
src/studio/studio.c
··· 2591 2591 #if defined(BUILD_EDITORS) 2592 2592 if (args.fftlist) 2593 2593 { 2594 - // FFT_Create(); 2595 - // FFT_EnumerateDevices(print_fft_devices, NULL); 2594 + FFT_EnumerateDevices(); 2596 2595 exit(0); 2597 2596 } 2598 2597 studio->config->data.fft = args.fft;
-21
src/system/sdl/main.c
··· 330 330 331 331 if (studio_config(platform.studio)->fft) 332 332 { 333 - // FFT_Create(); 334 - // FFT_Settings fftSettings; 335 - // fftSettings.bUseRecordingDevice = false; 336 - // fftSettings.pDeviceID = NULL; 337 - 338 - // if (studio_config(platform.studio)->fftdevice != NULL) 339 - // { 340 - // FFT_EnumerateDevices(find_fft_device_by_id, NULL); 341 - // if (deviceId != NULL) 342 - // { 343 - // fftSettings.pDeviceID = deviceId; 344 - // } 345 - // else 346 - // { 347 - // printf("Selected device was not found"); 348 - // exit(1); 349 - // } 350 - // } 351 - 352 333 FFT_Open(false, NULL); 353 - // FFT_Open(&fftSettings); 354 334 } 355 335 356 336 platform.audio.device = SDL_OpenAudioDevice(NULL, 0, &want, &platform.audio.spec, 0); ··· 1994 1974 if (studio_config(platform.studio)->fft) 1995 1975 { 1996 1976 FFT_Close(); 1997 - FFT_Destroy(); 1998 1977 } 1999 1978 } 2000 1979