On Tuesday 05 May 2009 2:17:05 am Stefan Kögel wrote:
> Hello Fellows,
>
> i am using OpenAL to capture Audio from the microphone. This works quite
> well, the only thing that bothers me, is that I have to poll the number
> of available samples.
> This is so cpu intensive. There must be some other way. Isnt there a
> blocking call, which returns a previous specified number of samples in a
> buffer. Or some kind of callback construction.
OpenAL doesn't have a blocking call, and it doesn't do callbacks.
> So far I have not found something like inside the OpenAL source.
>
> Does anyone know if there exists such a thing? Or has anyone done this
> before and can tell me what approach I can use?
>
> Here is what I do:
>
> while (tNumSamplesAvail < tCaptureSamples-1)
> {
> //Get number of captured samples
> alcGetIntegerv(mCaptureDevice, ALC_CAPTURE_SAMPLES,
> sizeof(tNumSamplesAvail), &tNumSamplesAvail);
> if (tNumSamplesAvail < tCaptureSamples-1)
> usleep(10);
> }
> alcCaptureSamples(mCaptureDevice, (ALCvoid *)pBuffer,
> tNumSamplesAvail);
>
> I hate to use "usleep". Actively waiting is not very sophisticated.
You can probably do something like this:
void BlockingCapture(ALCdevice *mCaptureDevice, ALCubyte *pBuffer,
ALCint iSamplesToGet)
{
ALCint capturedSamples = 0;
while(capturedSamples < iSamplesToGet)
{
ALCint avail;
alcGetIntegerv(mCaptureDevice, ALC_CAPTURE_SAMPLES, 1, &avail);
if(avail > 0/*or some threshold*/)
{
avail = min(avail, iSamplesToGet-capturedSamples);
alcCaptureSamples(mCaptureDevice, pBuffer, avail);
capturedSamples += avail;
pBuffer += avail;
}
else
usleep(10);
}
}
This shouldn't be unreasonably CPU intensive as it will be resting while
waiting for the data to get captured. It also lets you capture more samples
than the device was opened for.
_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal