Skip to content

Instantly share code, notes, and snippets.

@the-nerdery-dot-info
Created October 29, 2016 00:24
Show Gist options
  • Save the-nerdery-dot-info/55dfc67d8a8622b9ba23bce40042b3d6 to your computer and use it in GitHub Desktop.
Save the-nerdery-dot-info/55dfc67d8a8622b9ba23bce40042b3d6 to your computer and use it in GitHub Desktop.
Unreal Engine 4 Mic Input Snippet from quoteunquotestudio.com
// Additional includes:
#include "Voice.h"
#include "OnlineSubsystemUtils.h"
// New class member:
TSharedPtr<class IVoiceCapture> voiceCapture;
// Initialisation:
voiceCapture = FVoiceModule::Get().CreateVoiceCapture();
voiceCapture->Start();
// Capturing samples:
uint32 bytesAvailable = 0;
EVoiceCaptureState::Type captureState = voiceCapture->GetCaptureState(bytesAvailable);
if (captureState == EVoiceCaptureState::Ok && bytesAvailable > 0)
{
uint8 buf[maxBytes];
memset(buf, 0, maxBytes);
uint32 readBytes = 0;
voiceCapture->GetVoiceData(buf, maxBytes, readBytes);
uint32 samples = readBytes / 2;
float* sampleBuf = new float[samples];
int16_t sample;
for (uint32 i = 0; i < samples; i++)
{
sample = (buf[i * 2 + 1] << 8) | buf[i * 2];
sampleBuf[i] = float(sample) / 32768.0f;
}
// Do fun stuff here
delete[] sampleBuf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment