Stream capture data to sound source
My game has dynamic reverb based on the environment around the player, and I'd like to be able to speak and hear my voice echo.
Currently I'm using a capture device to get the short* data out, and then feed it back into a sound source to hear it in-game. This works great but there's a half a second delay on the playback.
Is it possible to instead route the capture data data directly into a sound source? This way the data would stay within the OpenAL system and potentially remove the delay.
My code for creating the capture device is:
var captureDevice = alcCaptureOpenDevice(CurrentInputDeviceName, 48000, AL_FORMAT_MONO16, 1024);
alcCaptureStart(captureDevice);
My code for streaming the capture data to the source is:
var samples = alcGetIntegerv(captureDevice, ALC_CAPTURE_SAMPLES);
alcCaptureSamples(captureDevice, captureBuffer, samples);
// Usually samples is 480 or 960, but sometimes it's 8191. Not sure why
if (samples == 8191) return;
// This helper function calls alGenBuffers or reuses an old buffer
var bufferID = GetBufferID();
// * 2 for 2 bytes per short
alBufferData(bufferID, AL_FORMAT_MONO16, captureBuffer, length * 2, 48000);
// Queue it for playing
alSourceQueueBuffers(source.ID, added, playBuffers);
// If it's not playing, play it
var state = alGetSourcei(source.ID, AL_SOURCE_STATE);
if (state != AL_PLAYING)
alSourcePlay(source.ID);
// Other code for alSourceUnqueueBuffers is omitted for clarity
Also, to only hear the reverb from my voice, I'm applying a low pass filter with 0.0 high frequency and 0.0 low frequency gain to the sound source directly, and applying no filter to the source's reverb. Is this the correct way to do this?
alSourcei(ID, AL_DIRECT_FILTER, silentFilterID);
alSource3i(ID, AL_AUXILIARY_SEND_FILTER, effectSlotID, 0, reverbFilterID);