C API Sound callbacks happen on another thread?

I am seeing some weird behaviour so I added logging and it seems to confirm that the FilePlayer fadeVolume() function will call its completion callback on a separate thread.

What I see is that the completion callback starts running, and then the system updateCallback runs at the same time, before the completion callback exits.

Is this intended? I see no mention of it in the docs. Are all the sound callbacks called on another thread from the update callback? Do they share a thread?

1 Like

Ah, yep, you're right. That's not good. :confused: I think I was expecting if you're running in C you should be able to handle that on your own, but then we don't give you any tools for the job. I'll try and get this to work like it does in Lua, where the callbacks are deferred to the main run loop, outside of the update callback

okay, now that I'm remembering how this works.. I guess my idea was if the callback is only doing a quick action that won't stall audio rendering that should be fine, and if you need to do more you can set a flag and pick it up in the update callback, which is effectively how it works under the hood on the Lua side. I'd forgotten that we moved audio rendering to a separate task, thought that putting slow code in an audio callback would be dragging the entire system down, but it's not that bad--it'll just make your audio stutter.

I'd like to move those callbacks to the main task like we have in Lua, but I don't think I'll be able to get to it this update. For now I'll make a note in the docs, point out that the callbacks should return quickly to not starve audio

Thanks Dave. It would be very nice to have them run on the same thread interleaved with the update callback.