6 ms·
> What kind of "stream" did you have in mind? The same kind the author means. I didn't coin this term or introduce it to the discussion. > For the OS to do so
by scottlamb 10y ago
> What kind of "stream" did you have in mind?
The same kind the author means. I didn't coin this term or introduce it to the discussion.
> For the OS to do software mixing, it is basically going to run a "for" loop over the audio buffers and add them up to produce the audio buffer that goes to the hardware. When is it going to run that loop?
Right, the author is saying that the OS is already doing this, and additionally the application does the same thing before sending a combined stream to the OS. So to answer your question of "when is [the OS] going to run that loop?" My answer is the same time it does now. I'm not proposing any changes to how the OS works.
My question is: why does the application need to do that work? Why can't it send each stream to the OS to have them be combined in only one place?
- haberman 10y agoAh, 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.
- byuu 10y ago> My question is: why does the application need to do that work? Why can't it send each stream to the OS to have them be combined in only one place? Two reasons. One, the audio API used is a simple push buffer design (eg OSS) and so you have to do your own mixing first. XAudio2 and friends will spare you this detail. Two, you're emulating a piece of gaming hardware that has its own internal mixer. And when that internal mixer doesn't have enough sound channels, the video games running on said emulated system can include their own software mixers to make it even more fun.