Skip to content

Commit

Permalink
[macOS] Avoid HALOutput sample rate audio conversion
Browse files Browse the repository at this point in the history
rdar://116794643
https://bugs.webkit.org/show_bug.cgi?id=271821

Reviewed by Eric Carlson.

Stick to hardware sample rate to avoid sample rate audio conversion at HAL output level.
Manually tested.

* Source/WebCore/platform/mediastream/mac/CoreAudioSharedUnit.cpp:
(WebCore::CoreAudioSharedUnit::setupAudioUnit):

Canonical link: https://commits.webkit.org/276775@main
  • Loading branch information
youennf committed Mar 28, 2024
1 parent 50bd98e commit 178e479
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Source/WebCore/platform/mediastream/mac/CoreAudioSharedUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,18 @@ OSStatus CoreAudioSharedUnit::setupAudioUnit()
RELEASE_LOG_ERROR_IF(err, WebRTC, "CoreAudioSharedUnit::setupAudioUnit(%p) unable to set capture unit output device ID %d, error %d (%.4s)", this, (int)defaultOutputDeviceID, (int)err, (char*)&err);
}
setOutputDeviceID(!err ? defaultOutputDeviceID : 0);
} else {
// With HALOutput, we cannot rely on sample rate conversions, we stick to hardware sample rate.
static const AudioObjectPropertyAddress nominalSampleRateAddress = {
kAudioDevicePropertyNominalSampleRate,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMain
};

Float64 nominalSampleRate;
UInt32 nominalSampleRateSize = sizeof(Float64);
if (AudioObjectGetPropertyData(deviceID, &nominalSampleRateAddress, 0, 0, &nominalSampleRateSize, (void*)&nominalSampleRate) == noErr)
setSampleRate(nominalSampleRate);
}
#endif

Expand Down

0 comments on commit 178e479

Please sign in to comment.