tinyaudio icon indicating copy to clipboard operation
tinyaudio copied to clipboard

High callback rate not supported for macos

Open rishadbaniya opened this issue 1 year ago • 2 comments

If i were to put a output device params as something like this

            let out_device_params = OutputDeviceParameters {
                sample_rate: 44000
                channels_count: 2,
                channel_sample_count: 1,
            };

it would work very well with pulseaudio(i.e in linux), but with macos it seems the callback isn't called "fast enough" i.e it doesn't call it 44000 times in this case

rishadbaniya avatar Jan 12 '25 11:01 rishadbaniya

This crate may not support output with very low latency, simply because it uses more or less high level OS APIs under the hood. 2 sample buffer is definitely some extreme values, given the fact that it stands for just ~22 microseconds. Instead, you should prefer having reasonably large buffer, for example 1/10th of sample rate will be 100ms which is already decently low latency for most applications.

mrDIMAS avatar Jan 12 '25 13:01 mrDIMAS

I agree that very low buffer sizes as 1 samples could not be expected to work properly, but something like 64 to 256 samples should be ok.

Interestingly, I can get much lower buffer sizes with my old Intel MacPro running High Sierra than using a M2 Mac mini on macOS Sonoma with the same code. Something must have been changed in the scheduling of the OS with the newer versions.

sourcebox avatar Apr 16 '25 20:04 sourcebox