Skip to content

Commit

Permalink
Remove MacBookPro audio pan right code (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie authored and cloudwebrtc committed Jan 18, 2023
1 parent e0f9739 commit d4ff918
Showing 1 changed file with 1 addition and 92 deletions.
93 changes: 1 addition & 92 deletions modules/audio_device/mac/audio_device_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ AudioDeviceMac::AudioDeviceMac()
_twoDevices(true),
_doStop(false),
_doStopRec(false),
_macBookPro(false),
_macBookProPanRight(false),
_captureLatencyUs(0),
_renderLatencyUs(0),
_captureDelayUs(0),
Expand Down Expand Up @@ -294,23 +292,6 @@ AudioDeviceGeneric::InitStatus AudioDeviceMac::Init() {
WEBRTC_CA_LOG_ERR(AudioObjectAddPropertyListener(
kAudioObjectSystemObject, &propertyAddress, &objectListenerProc, this));

// Determine if this is a MacBook Pro
_macBookPro = false;
_macBookProPanRight = false;
char buf[128];
size_t length = sizeof(buf);
memset(buf, 0, length);

int intErr = sysctlbyname("hw.model", buf, &length, NULL, 0);
if (intErr != 0) {
RTC_LOG(LS_ERROR) << "Error in sysctlbyname(): " << err;
} else {
RTC_LOG(LS_VERBOSE) << "Hardware model: " << buf;
if (strncmp(buf, "MacBookPro", 10) == 0) {
_macBookPro = true;
}
}

_initialized = true;

return InitStatus::OK;
Expand Down Expand Up @@ -979,34 +960,8 @@ int32_t AudioDeviceMac::InitPlayout() {
_renderDeviceIsAlive = 1;
_doStop = false;

// The internal microphone of a MacBook Pro is located under the left speaker
// grille. When the internal speakers are in use, we want to fully stereo
// pan to the right.
AudioObjectPropertyAddress propertyAddress = {
kAudioDevicePropertyDataSource, kAudioDevicePropertyScopeOutput, 0};
if (_macBookPro) {
_macBookProPanRight = false;
Boolean hasProperty =
AudioObjectHasProperty(_outputDeviceID, &propertyAddress);
if (hasProperty) {
UInt32 dataSource = 0;
size = sizeof(dataSource);
WEBRTC_CA_LOG_WARN(AudioObjectGetPropertyData(
_outputDeviceID, &propertyAddress, 0, NULL, &size, &dataSource));

if (dataSource == 'ispk') {
_macBookProPanRight = true;
RTC_LOG(LS_VERBOSE)
<< "MacBook Pro using internal speakers; stereo panning right";
} else {
RTC_LOG(LS_VERBOSE) << "MacBook Pro not using internal speakers";
}

// Add a listener to determine if the status changes.
WEBRTC_CA_LOG_WARN(AudioObjectAddPropertyListener(
_outputDeviceID, &propertyAddress, &objectListenerProc, this));
}
}

// Get current stream description
propertyAddress.mSelector = kAudioDevicePropertyStreamFormat;
Expand Down Expand Up @@ -1511,16 +1466,6 @@ int32_t AudioDeviceMac::StopPlayout() {
WEBRTC_CA_LOG_WARN(AudioObjectRemovePropertyListener(
_outputDeviceID, &propertyAddress, &objectListenerProc, this));

if (_macBookPro) {
Boolean hasProperty =
AudioObjectHasProperty(_outputDeviceID, &propertyAddress);
if (hasProperty) {
propertyAddress.mSelector = kAudioDevicePropertyDataSource;
WEBRTC_CA_LOG_WARN(AudioObjectRemovePropertyListener(
_outputDeviceID, &propertyAddress, &objectListenerProc, this));
}
}

_playIsInitialized = false;
_playing = false;

Expand Down Expand Up @@ -2061,28 +2006,10 @@ int32_t AudioDeviceMac::HandleStreamFormatChange(
int32_t AudioDeviceMac::HandleDataSourceChange(
const AudioObjectID objectId,
const AudioObjectPropertyAddress propertyAddress) {
OSStatus err = noErr;

if (_macBookPro &&
propertyAddress.mScope == kAudioDevicePropertyScopeOutput) {
RTC_LOG(LS_VERBOSE) << "Data source changed";

_macBookProPanRight = false;
UInt32 dataSource = 0;
UInt32 size = sizeof(UInt32);
WEBRTC_CA_RETURN_ON_ERR(AudioObjectGetPropertyData(
objectId, &propertyAddress, 0, NULL, &size, &dataSource));
if (dataSource == 'ispk') {
_macBookProPanRight = true;
RTC_LOG(LS_VERBOSE)
<< "MacBook Pro using internal speakers; stereo panning right";
} else {
RTC_LOG(LS_VERBOSE) << "MacBook Pro not using internal speakers";
}
}

return 0;
}

int32_t AudioDeviceMac::HandleProcessorOverload(
const AudioObjectPropertyAddress propertyAddress) {
// TODO(xians): we probably want to notify the user in some way of the
Expand Down Expand Up @@ -2400,24 +2327,6 @@ bool AudioDeviceMac::RenderWorkerThread() {
uint32_t nOutSamples = nSamples * _outDesiredFormat.mChannelsPerFrame;

SInt16* pPlayBuffer = (SInt16*)&playBuffer;
if (_macBookProPanRight && (_playChannels == 2)) {
// Mix entirely into the right channel and zero the left channel.
SInt32 sampleInt32 = 0;
for (uint32_t sampleIdx = 0; sampleIdx < nOutSamples; sampleIdx += 2) {
sampleInt32 = pPlayBuffer[sampleIdx];
sampleInt32 += pPlayBuffer[sampleIdx + 1];
sampleInt32 /= 2;

if (sampleInt32 > 32767) {
sampleInt32 = 32767;
} else if (sampleInt32 < -32768) {
sampleInt32 = -32768;
}

pPlayBuffer[sampleIdx] = 0;
pPlayBuffer[sampleIdx + 1] = static_cast<SInt16>(sampleInt32);
}
}

PaUtil_WriteRingBuffer(_paRenderBuffer, pPlayBuffer, nOutSamples);

Expand Down

0 comments on commit d4ff918

Please sign in to comment.