signalflow icon indicating copy to clipboard operation
signalflow copied to clipboard

Support for setting non-default sample_rate in Core Audio

Open ideoforms opened this issue 3 years ago • 0 comments

On macOS, setting the sample rate to a non-default value is not currently supported. It should be a simple fix on line ~182 of graph.cpp:

    if (this->sample_rate)
    {
        // use specified Fs
        this->outstream->sample_rate = this->sample_rate;
    }
    else
    {
        this->outstream->sample_rate = this->device->sample_rate_current;
    }

However, this subsequently seems to require a buffer size that is not the same as the configured one:

(base) (1101)(master)(MacBook-Pro:signalflow)$ python3 test-sr.py
Output device: MacBook Pro Speakers (48000Hz, buffer size 256 samples, 2 channels)
Exception in AudioGraph: Node audioout-soundio cannot render because output buffer size is insufficient (279 samples requested, buffer size = 256). Increase the buffer size.

The HAL appears to be requesting 256*(48000/44100) samples. This may be related to this libsoundio issue: https://github.com/andrewrk/libsoundio/issues/138

"What is happening is that the output is requesting an unexpected amount of samples, 3344 (so 1115 samples at 16khz), and quickly ends up consuming more samples than the input can provide, getting underflows.

Is there additional, uncontrollable hardware latency that makes the approach I am taking unfeasible? Or am I missing something .."

ideoforms avatar Apr 08 '22 10:04 ideoforms