I have such code to execute a microphone echo with openAL on windows.
I want to create a file CapturedAudioDatato record all the audio data recorded during the loop. This way it will look like unformatted PCM. And I need it to be filled 25 times per second.
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <al.h>
#include <alc.h>
using namespace std;
int main()
{
ALCdevice *dev[2];
ALCcontext *ctx;
ALuint source, buffers[3];
char data[5000];
ALuint buf;
ALint val;
dev[0] = alcOpenDevice(NULL);
ctx = alcCreateContext(dev[0], NULL);
alcMakeContextCurrent(ctx);
alGenSources(1, &source);
alGenBuffers(3, buffers);
alBufferData(buffers[0], AL_FORMAT_MONO16, data, sizeof(data), 22050);
alBufferData(buffers[1], AL_FORMAT_MONO16, data, sizeof(data), 22050);
alBufferData(buffers[2], AL_FORMAT_MONO16, data, sizeof(data), 22050);
alSourceQueueBuffers(source, 3, buffers);
alDistanceModel(AL_NONE);
dev[1] = alcCaptureOpenDevice(NULL, 22050, AL_FORMAT_MONO16, sizeof(data)/2);
alSourcePlay(source);
alcCaptureStart(dev[1]);
while(1)
{
alGetSourcei(source, AL_BUFFERS_PROCESSED, &val);
if(val <= 0)
continue;
alcGetIntegerv(dev[1], ALC_CAPTURE_SAMPLES, 1, &val);
alcCaptureSamples(dev[1], data, val);
alSourceUnqueueBuffers(source, 1, &buf);
alBufferData(buf, AL_FORMAT_MONO16, data, val*2 , 22050);
alSourceQueueBuffers(source, 1, &buf);
alGetSourcei(source, AL_SOURCE_STATE, &val);
if(val != AL_PLAYING)
{
alSourcePlay(source);
}
}
alcCaptureStop(dev[1]);
alcCaptureCloseDevice(dev[1]);
alSourceStop(source);
alDeleteSources(1, &source);
alDeleteBuffers(3, buffers);
alcMakeContextCurrent(NULL);
alcDestroyContext(ctx);
alcCloseDevice(dev[0]);
return 0;
}
How to create such a thing - what do I need to change / add to my code?