Hi, I'm running into the same problem. However, after doing a bit of research, I discovered it is not "distortion", it is simply the fact that macOS is choosing a low-quality audio codec for use when your Bluetooth device is connected to your AVAudioEngine.
A low quality codec is, for example, "SCO" while a high quality codec is "AptX".
There is a page with easy instructions on how to troubleshoot the issue and how to set codec options for Bluetooth. See if this helps. Please let me know if you're able to get it working, as I am also struggling with the same problem.
Just Google "How to Enable the Optimal Audio Codec for Your Bluetooth Headphones in macOS" and look for a page on the MacRumors site that explains it. This forum won't let me post a direct link.
Post
Replies
Boosts
Views
Activity
This library does exactly what you want: https://github.com/adamwulf/ClippingBezier
I'm having the same problem and went insane trying to find a solution. Thank you !