Thread-safe AudioBuffer queue
Thread-safe AudioBuffer queue
- Subject: Thread-safe AudioBuffer queue
- From: Lieven Dekeyser <email@hidden>
- Date: Wed, 9 Jan 2002 18:34:02 +0100 (CET)
Hi!
I'm trying to make a sound converter class which uses SoundConverter from
<Carbon/Sound.h> to convert any files QuickTime can read to CoreAudio's
Float32 format and play back the converted data through the default audio
device.
I'm doing this using a thread (started by [NSThread detachNewThreadSelector])
that does the actual converting and then there's the thread that runs the
output device's IOProc when needed. In the converter thread the converted
stuff is malloced & enqueued, in the IOProc it's dequeued, memcpyd to the
audio device's first buffer and then freed.
I'm using the extra thread & queue because I tried to do the
conversion in the IOProc, but this resulted in skipping playback, so I
guess the conversion is too heavy for the IOProc.
My approach works fine... most of the time :-(
tough sometimes it crashes telling me I have accessed the memory illegally
(EXC_BAD_ACCESS)
I suspect this has something to do with my queue not being completely
thread safe. I tried to make the enqueue & dequeue operations as safe as
possible with virtually no critical operations, but I guess that's not
enough.
Has anyone tried & succeeded to do something similar?
greetz & thanks!
--Lieven
ps: as soon as it gets stable, I'll put the source code on my website