[Openal] Recording and Playing Simultaneously
Daniel PEACOCK
dpeacock at creativelabs.com
Tue Jul 24 15:00:24 PDT 2007
Hi,
I haven't seen anyone use that technique of querying the current buffer in
the queue to determine what buffers must have been processed!
Anyway ... I *think* that there are two reasons why you are running out of
buffers after a pause ...
1) When you re-start the playback Source you are not emptying the queue of
Buffers that have already played (which in your case will be all the
buffers in the queue except the last one you just added). This means some
Buffers are going to be played twice.
and
2) Capture is still working in the background, so after a pause in your
application, there could be a lot of captured data ready to be consumed.
This means your playback Source will be trailing behind the capture input
and it will never catch up. You will either have to increase the play
speed (pitch) to catch up - or throw out some captured data.
Dan
Creative Labs, Inc.
Notice
The information in this message is confidential and may be legally
privileged. It is intended solely for the addressee. Access to this
message by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying or distribution of the message, or
any action taken by you in reliance on it, is prohibited and may be
unlawful. If you have received this message in error, please delete it
and contact the sender immediately. Thank you.
Spike7d5
<spike7d5 at yahoo.c
om> To
Sent by: openal at opensource.creative.com
openal-bounces at op cc
ensource.creative
.com Subject
Re: [Openal] Recording and Playing
Simultaneously
07/24/2007 08:18
AM
I have finally recorded and played the sound at the same time. Thank you!
Unfortunately, there is one more problem: if the cpu usage is too high the
number of free buffers drops (the same behavior appears if I freeze the
program for a couple of seconds). So, what should I do to be sure that the
program always has some free buffers? Should I increase the number of
maximum buffers or does the code have some bugs? Here is the whole main
loop
(BUFFERS is defined as 32):
int currentBuffer = 0, lastBuffer = 0;
int freeBuffers = BUFFERS, freeBuffersMin = BUFFERS;
char *bufferCapture[BUFFERS];
while (key != 27)
{
ALCint samples;
alcGetIntegerv(deviceCapture, ALC_CAPTURE_SAMPLES, 1,
&samples);
if (samples >= 1)
{
bufferCapture[currentBuffer] = (char *)
malloc(samples * 2);
alcCaptureSamples(deviceCapture,
bufferCapture[currentBuffer], samples);
if ((result = alcGetError(deviceCapture)) ==
AL_NO_ERROR)
{
alBufferData(buffer[currentBuffer],
AL_FORMAT_MONO16,
bufferCapture[currentBuffer], samples * 2, 22050);
if ((result = alGetError()) !=
AL_NO_ERROR) ERROR_MESSAGE
alSourceQueueBuffers(source, 1,
&buffer[currentBuffer]);
if ((result = alGetError()) !=
AL_NO_ERROR) ERROR_MESSAGE
ALint state;
alGetSourcei(source, AL_SOURCE_STATE,
&state);
if ((result = alGetError()) !=
AL_NO_ERROR) ERROR_MESSAGE
if (state != AL_PLAYING)
{
alSourcePlay(source);
if ((result =
alGetError()) != AL_NO_ERROR) ERROR_MESSAGE
}
freeBuffers--;
if (freeBuffersMin > freeBuffers)
freeBuffersMin = freeBuffers;
ALint bufferProcessed;
alGetSourcei(source, AL_BUFFER,
&bufferProcessed);
if ((result = alGetError()) !=
AL_NO_ERROR) ERROR_MESSAGE
// unenque the buffers that aren't in
the source queue anymore
for (int i = lastBuffer; buffer[i] !=
bufferProcessed; i = (i + 1) %
BUFFERS)
{
alSourceUnqueueBuffers(source, 1, &buffer[i]);
if ((result =
alGetError()) != AL_NO_ERROR) ERROR_MESSAGE
free(bufferCapture[i]);
lastBuffer = (i + 1) %
BUFFERS;
freeBuffers++;
}
currentBuffer = (currentBuffer + 1) %
BUFFERS;
printf("%d / %d (%d)\n", freeBuffers,
BUFFERS, freeBuffersMin);
}
else
{
printf("Error getting samples\n");
return -1;
}
}
if (_kbhit()) key = _getch();
}
--
View this message in context:
http://www.nabble.com/Recording-and-Playing-Simultaneously-tf4132517.html#a11765463
Sent from the OpenAL - User mailing list archive at Nabble.com.
_______________________________________________
Openal mailing list
Openal at opensource.creative.com
http://opensource.creative.com/mailman/listinfo/openal
ForwardSourceID:NT000445F6
More information about the Openal
mailing list