It doesn't sound like it should be all that difficult, you just need to use a mutex and lock it before pushing data onto the back of the queue, and lock it before removing data from the front of the queue. You also need to lock it in the audio thread when determining how much data is in the queue, though you probably don't need to keep it locked on the audio thread while actually pushing the data to the device.
On the other hand, it might make more sense and be easier to manage to just use a queue of audio chunks instead of a single byte array. Then you can just use a basic thread-safe queue for pushing/popping chunks on and off the queue. If you use a pool of pre-allocated chunks it will probably be more efficient too.
Show differencesHistory of post edits
#1krippy2k8
Posted 22 August 2012 - 12:29 AM
It doesn't sound like it should be all that difficult, you just need to use a mutex and lock it before pushing data onto the back of the queue, and lock it before removing data from the front of the queue. You also need to lock it in the audio queue when determining how much data is in the queue to push, though you probably don't need to keep it locked on the audio thread while actually pushing the data to the device.
On the other hand, it might make more sense and be easier to manage to just use a queue of audio chunks instead of a single byte array. Then you can just use a basic thread-safe queue for pushing/popping chunks on and off the queue. If you use a pool of pre-allocated chunks it will probably be more efficient too.
On the other hand, it might make more sense and be easier to manage to just use a queue of audio chunks instead of a single byte array. Then you can just use a basic thread-safe queue for pushing/popping chunks on and off the queue. If you use a pool of pre-allocated chunks it will probably be more efficient too.