Sound playback under Carbon
Sound playback under Carbon
- Subject: Sound playback under Carbon
- From: Martin Hairer <email@hidden>
- Date: Wed, 20 Feb 2002 13:24:31 +0100
Hi all,
I have a problem playing back a sound smoothly under Carbon. I
implemented a simple bufferCmd/callBackCmd loop and it happens that the
playback stream is interrupted when the file I/O activity is too
high. This sometimes happens simply because the OS is swapping.
I tried the following three approaches:
1. If I fill the buffers using an asynchronous read request, it happens
that the buffer is not filled sufficiently fast. I tried to circumvent
this by using several (more than two) buffers in a circular way, but
even with very large buffer sizes (5 times 0.4 seconds) it happens that
the buffers are not ready in time. It seems that the problem with this approach
is that the asynchronous read request runs in a thread of low priority.
2. If I fill the buffers using a synchronous read request, things seem
to work slightly better, but then the problem is that it happens sometimes
that the synchronous read request takes some time, thus introducing
a short silence in the playback.
3. The approach that seems to work best is to have a callback function
with the following structure (fill is a global variable):
void callback(SndChannelPtr channel, SndCommand)
{
// Set up bufferCommand and callBackCommand
if (fill) {
FillBuffers(); // synchronous read request
fill = false;
}
else {
SndDoImmediate(channel, &bufferCommand);
SndDoCommand(channel, &callBackCommand, true);
fill = true;
SndDoImmediate(channel, &callBackCommand);
}
}
The third approach works quite well, but I somehow don't feel very
comfortable with it. My feeling is that the best way to do would be
to make asynchronous read requests but with a higher priority (I don't
know if/how this is possible). What do you think? Is there an approach
that I am missing? Sorry for the lengthy post...
Martin
------------------------------------------------------------
Dipartement de Physique Thiorique
24, Ernest Ansermet Homepage:
http://mpej.unige.ch/~hairer/
CH-1211 Genhve 4 EMail: email@hidden
Switzerland Tel.: ++41 22 702 63 84
------------------------------------------------------------
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.