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 318 forks source link

clamp values when converting from floats #373

Closed asapha closed 1 year ago

asapha commented 1 year ago

Hi,

I heard artifacts on some songs while using RtAudio to record my PC's audio.

When recording from float formats, it seems that some values can fall out of the expected range. Adding std::max alongside the existing std::min calls work around the issue. Let me know if that's not correct.

I'm using macOS 12.6, I don't know if it's specific to CoreAudio.

Repro:

Using soundflower instead of BlackHole lead to the same issue. Recording the virtual devices via audacity is artifact free (it uses Portaudio). Chrome and VLC seem to correct the audio themselves, use Safari or Firefox to repro.

CleanShot 2022-10-17 at 22 35 39

before.mp4 after-fix.mp4