Ah, I see what you are asking. Sorry I misunderstood.
I doubt that the application mixing is actually adding any latency compared to if the application only had a single logical stream internally.
Regardless of the application's internal structure, you will at every moment have a set of audio buffers:
1. the one the sound card is currently playing
2. the one the OS is preparing for the sound card (it gets one buffer's worth of time to synthesize this).
3. the one the application is preparing for the OS (it gets one buffer's worth of time to synthesize this).
If the OS isn't doing any mixing, then you could make buffer 2 and 3 the same and save a buffer's worth of latency. But if the OS is doing mixing, then it needs a chance to add up all the application buffers before they go to the sound card (that is its "synthesize" step). So the application can't be writing directly into the OS's buffer.
You might ask "why can't the application and OS both do their work within a single buffer's worth of time?
Hmm, I guess it is an interesting question whether the OS could, inside the write() call, do the mixing immediately. I'm reaching the point where I'd have to speculate: I'm not exactly sure how existing OSs design their mixing and whether this would be feasible or not.
I doubt that the application mixing is actually adding any latency compared to if the application only had a single logical stream internally.
Regardless of the application's internal structure, you will at every moment have a set of audio buffers:
1. the one the sound card is currently playing
2. the one the OS is preparing for the sound card (it gets one buffer's worth of time to synthesize this).
3. the one the application is preparing for the OS (it gets one buffer's worth of time to synthesize this).
If the OS isn't doing any mixing, then you could make buffer 2 and 3 the same and save a buffer's worth of latency. But if the OS is doing mixing, then it needs a chance to add up all the application buffers before they go to the sound card (that is its "synthesize" step). So the application can't be writing directly into the OS's buffer.
You might ask "why can't the application and OS both do their work within a single buffer's worth of time?
Hmm, I guess it is an interesting question whether the OS could, inside the write() call, do the mixing immediately. I'm reaching the point where I'd have to speculate: I'm not exactly sure how existing OSs design their mixing and whether this would be feasible or not.