ideoforms / signalflow

A sound synthesis framework for Python, designed for clear and concise expression of musical ideas
https://signalflow.dev
Other
179 stars 14 forks source link

Support for setting non-default sample_rate in Core Audio #89

Open ideoforms opened 2 years ago

ideoforms commented 2 years ago

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 .."