thestk / rtaudio

A set of C++ classes that provide a common API for realtime audio input/output across Linux (native ALSA, JACK, PulseAudio and OSS), Macintosh OS X (CoreAudio and JACK), and Windows (DirectSound, ASIO, and WASAPI) operating systems.
Other
1.49k stars 317 forks source link

Understanding duplex mode with different sample rates (if possible) #391

Closed gvnnz closed 1 year ago

gvnnz commented 1 year ago

Say I want to both play and record audio at the same time with two different devices, which support different sample rates. For example:

Is this technically possible? If so, what value should I pass as sampleRate to the RtAudio::openStream method, since it takes only one parameter relative to the sample rate to use?

garyscavone commented 1 year ago

It is not possible to open a duplex stream with input and output devices running at different rates. If both devices have a rate in common, you can obviously use that. The only other option is to try to open two separate input and output streams, running at different rates and perform your own sample rate conversion if you want to share the data between streams. However, you may run into synchronization or overrun/underrun issues. If you have output data that needs to be played at 96K and you want to record resulting audio at 44.1K, then two separate input and output streams at the two different rates should work fine.

gvnnz commented 1 year ago

Hi @garyscavone , thanks a lot for your explanation. That was helpful. I guess I can close this.