Hacker News new | ask | show | jobs
by zelphirkalt 161 days ago
Is this not the job of the operating system or its supporting parts, to deal with audio from various sources? It should not be necessary to inspect the state of the OS your game is running on, to know what kind of audio you can playback. In fact, that could even be considered spying on things you shouldn't. Maybe the OS or its sound system does not abstract that from you and I am wrong about the state of OS in reality, but this seems to me like a pretty big oversight, if true. If I extrapolate from your use-case, then that would mean any application performing any playback of sound, needs to inspect whether something else is running on the system. That seems like a pretty big overreach.

As an example, lets say I change frequency in Audacity and press the play button. Does Audacity now go and inspect, whether anything else on my system is making any sound?

4 comments

It is and it is done but you might not have control over process.

In PulseAudio you can choose resample method you want to use for the whole mixing daemon but I don't think that's option in windows/macos

The OS "deals with it" by resampling when necessary.
Depends on platform. But yes.

It is also the job of the operating system or its supporting parts to allow applications to configure audio devices to specific sample rates if that's what the application needs.

It's fine to just take whatever you get if you are a game app, and either allow the OS to resample, or do the resampling yourself on the fly.

Not so fine if you are authoring audio, where the audio device rate ABSOLUTELY has to match the rate of content that's being created. It is NOT acceptable to have the OS doing resampling when that's the case.

Audacity allows you to force the sample rate of the input and output devices on both Windows and Linux. Much easier on Windows; utterly chaotic and bug-filled and miserable and unpredictable on Linux (although up-to-date versions of Pipewire can almost mostly sometimes do the right thing, usually).

> Is this not the job of the operating system or its supporting parts, to deal with audio from various sources

I think that's the point? In practice the OS (or its supporting parts) resample audio all the time. It's "under the hood" but the only way to actually avoid it would be to limit all audio files and playback systems to a single rate.

I don't understand then, why they need to deal with that when making a game, unless they are not satisfied with the way that the OS resamples under the hood.
My reading is not that they're saying it's something they necessarily have deal with themselves, but that it's something they can't practically avoid.
But they CAN practically avoid it. lol. Just let the system do it for them.
If my audio files are 44.1kHz, and the user plays 48kHz audio at the same time, how do I practically avoid my audio being resampled?
You cannot avoid it either way then, I guess. Either you let the system do it for you, or you take matters into your own hands. But why do you feel it necessary to take matters into your own hands? I think that's the actual question that begs answering. Are you unsatisfied with how the system does the resampling? Does it result in a worse quality than your own implementation of resampling? Or is there another reason?
I suppose, if you interpret "avoid" as "not care about".
I interpret them to mean "avoid doing it oneself" not "avoid it happening entirely".