Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

(fix) AirPods and other Bluetooth headphones are no longer silent

Egor Khindikaynen46a359beaf7a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5cfd56e6..993ac17a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -79,6 +79,11 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
### Fixed
- A note pressed and released within a few milliseconds (a very quick tap, a fast MIDI roll)
could keep ringing: its release was played ahead of its press.
+- **AirPods and other Bluetooth headphones are no longer silent** as Nota's output on
+ macOS. Nota used to force its sample rate onto the headphones, which broke their
+ Bluetooth stream (a moment of crackle, then silence, in every app). Nota now leaves the
+ rate of Bluetooth devices, and any rate a device doesn't list, alone and converts
+ instead.
## [0.43.1] — 2026-10-02
diff --git a/src/native/nota.engine/src/CoreAudioBackend.mm b/src/native/nota.engine/src/CoreAudioBackend.mm
index 4e1cb9f9..8515a761 100644
--- a/src/native/nota.engine/src/CoreAudioBackend.mm
+++ b/src/native/nota.engine/src/CoreAudioBackend.mm
@@ -6,6 +6,8 @@
#import <AudioToolbox/AudioToolbox.h>
#import <CoreAudio/CoreAudio.h>
+#include <vector>
+
namespace nota {
struct CoreAudioBackend::Impl {
@@ -73,6 +75,36 @@ double deviceNominalSampleRate(AudioDeviceID dev) {
return sr;
}
+// Bluetooth outputs (AirPods etc.) get their rate from the link codec. Forcing a
+// nominal rate on them (e.g. 44.1 kHz on AirPods that run AAC at 48 kHz) leaves
+// the A2DP stream losing sync — a second of crackle, then silence — for every
+// app until Bluetooth restarts. Never touch their rate; AUHAL resamples instead.
+bool isBluetoothDevice(AudioDeviceID dev) {
+ AudioObjectPropertyAddress addr{ kAudioDevicePropertyTransportType,
+ kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMain };
+ UInt32 transport = 0;
+ UInt32 size = sizeof(transport);
+ if (AudioObjectGetPropertyData(dev, &addr, 0, nullptr, &size, &transport) != noErr) return false;
+ return transport == kAudioDeviceTransportTypeBluetooth
+ || transport == kAudioDeviceTransportTypeBluetoothLE;
+}
+
+bool deviceSupportsSampleRate(AudioDeviceID dev, double sr) {
+ AudioObjectPropertyAddress addr{ kAudioDevicePropertyAvailableNominalSampleRates,
+ kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMain };
+ UInt32 size = 0;
+ if (AudioObjectGetPropertyDataSize(dev, &addr, 0, nullptr, &size) != noErr || size == 0)
+ return false;
+ std::vector<AudioValueRange> ranges(size / sizeof(AudioValueRange));
+ if (AudioObjectGetPropertyData(dev, &addr, 0, nullptr, &size, ranges.data()) != noErr)
+ return false;
+ for (const auto& r : ranges)
+ if (sr >= r.mMinimum - 0.5 && sr <= r.mMaximum + 0.5) return true;
+ return false;
+}
+
} // namespace
bool CoreAudioBackend::start(RenderCallback render, const BackendConfig& cfg) {
@@ -109,7 +141,12 @@ bool CoreAudioBackend::start(RenderCallback render, const BackendConfig& cfg) {
}
// Apply requested nominal sample rate + buffer size on the device (best effort).
- if (cfg.sampleRate > 0.0 && dev != kAudioObjectUnknown) {
+ // The rate is only changed when the device lists it and isn't Bluetooth;
+ // otherwise the client format below still runs at the requested rate and
+ // AUHAL converts to whatever the device is running at.
+ if (cfg.sampleRate > 0.0 && dev != kAudioObjectUnknown
+ && deviceNominalSampleRate(dev) != cfg.sampleRate
+ && !isBluetoothDevice(dev) && deviceSupportsSampleRate(dev, cfg.sampleRate)) {
Float64 sr = cfg.sampleRate;
AudioObjectPropertyAddress a{ kAudioDevicePropertyNominalSampleRate,
kAudioObjectPropertyScopeGlobal,