MCPcopy Create free account
hub / github.com/CalcProgrammer1/KeyboardVisualizer / Update

Method Update

KeyboardVisualizerCommon/Visualizer.cpp:459–670  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

457}
458
459void Visualizer::Update()
460{
461 float fft_tmp[512];
462
463 for (int i = 0; i < 256; i++)
464 {
465 //Clear the buffers
466 fft_tmp[i] = 0;
467
468 //Decay previous values
469 fft[i] = fft[i] * (((float)decay) / 100.0f);
470 }
471
472#ifdef WIN32
473 unsigned int buffer_pos = 0;
474 static float input_wave[512];
475
476 unsigned int nextPacketSize = 1;
477 unsigned int flags;
478
479 while (nextPacketSize > 0)
480 {
481 float *buf;
482 if (pAudioCaptureClient != NULL)
483 {
484 pAudioCaptureClient->GetBuffer((BYTE**)&buf, &nextPacketSize, (DWORD *)&flags, NULL, NULL);
485
486 if (buf == NULL && nextPacketSize > 0)
487 {
488 pAudioClient->Stop();
489 pAudioCaptureClient->Release();
490 pAudioClient->Release();
491 pAudioCaptureClient = NULL;
492 pAudioClient = NULL;
493 }
494 else
495 {
496 for (unsigned int i = 0; i < nextPacketSize; i += 4)
497 {
498 for (int j = 0; j < 255; j++)
499 {
500 input_wave[2 * j] = input_wave[2 * (j + 1)];
501 input_wave[(2 * j) + 1] = input_wave[2 * j];
502 }
503
504 float avg_buf = (buf[i] + buf[i + 1] + buf[i + 2] + buf[i + 3]) / 4;
505 input_wave[510] = avg_buf * 2.0f * amplitude;
506 input_wave[511] = input_wave[510];
507 }
508
509 buffer_pos += nextPacketSize / 4;
510 pAudioCaptureClient->ReleaseBuffer(nextPacketSize);
511 }
512 }
513 }
514
515 memcpy(fft_tmp, input_wave, sizeof(input_wave));
516#else

Callers

nothing calls this directly

Calls 2

apply_windowFunction · 0.85
rfftFunction · 0.85

Tested by

no test coverage detected