aboutsummaryrefslogtreecommitdiff
path: root/webrtc
diff options
context:
space:
mode:
authorandrew <andrew@webrtc.org>2016-01-08 01:16:17 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-08 09:16:25 +0000
commitec80f03b3cd919614d82ba70837de87718e1c4a7 (patch)
tree08a156e3bcc446f89420853e9c8a7aeffb4643c1 /webrtc
parentfbeb97e01f02a528cce02f076942a779195270a5 (diff)
downloadwebrtc-ec80f03b3cd919614d82ba70837de87718e1c4a7.tar.gz
Check the mic volume only periodically on Mac.
Ask the OS for the mic volume every 1 second rather than with every 10 ms chunk. The previous behavior was consuming ~2% of the CPU load of a voice engine call, and is now negligible. This is consistent with the webrtc Windows Core Audio implementation, as well as the Chromium Mac implementation: https://code.google.com/p/chromium/codesearch#chromium/src/media/audio/agc_audio_stream.h TEST=voe_cmd_test with AGC continues to work well on Mac. Review URL: https://codereview.webrtc.org/1564223002 Cr-Commit-Position: refs/heads/master@{#11182}
Diffstat (limited to 'webrtc')
-rw-r--r--webrtc/modules/audio_device/mac/audio_device_mac.cc20
-rw-r--r--webrtc/modules/audio_device/mac/audio_device_mac.h14
2 files changed, 25 insertions, 9 deletions
diff --git a/webrtc/modules/audio_device/mac/audio_device_mac.cc b/webrtc/modules/audio_device/mac/audio_device_mac.cc
index 3449188dc0..d963f2b7f2 100644
--- a/webrtc/modules/audio_device/mac/audio_device_mac.cc
+++ b/webrtc/modules/audio_device/mac/audio_device_mac.cc
@@ -149,7 +149,8 @@ AudioDeviceMac::AudioDeviceMac(const int32_t id) :
_paRenderBuffer(NULL),
_captureBufSizeSamples(0),
_renderBufSizeSamples(0),
- prev_key_state_()
+ prev_key_state_(),
+ get_mic_volume_counter_ms_(0)
{
WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id,
"%s created", __FUNCTION__);
@@ -379,6 +380,8 @@ int32_t AudioDeviceMac::Init()
_recWarning = 0;
_recError = 0;
+ get_mic_volume_counter_ms_ = 0;
+
_initialized = true;
return 0;
@@ -3181,12 +3184,17 @@ bool AudioDeviceMac::CaptureWorkerThread()
if (AGC())
{
- // store current mic level in the audio buffer if AGC is enabled
- if (MicrophoneVolume(currentMicLevel) == 0)
- {
- // this call does not affect the actual microphone volume
- _ptrAudioBuffer->SetCurrentMicLevel(currentMicLevel);
+ // Use mod to ensure we check the volume on the first pass.
+ if (get_mic_volume_counter_ms_ % kGetMicVolumeIntervalMs == 0) {
+ get_mic_volume_counter_ms_ = 0;
+ // store current mic level in the audio buffer if AGC is enabled
+ if (MicrophoneVolume(currentMicLevel) == 0)
+ {
+ // this call does not affect the actual microphone volume
+ _ptrAudioBuffer->SetCurrentMicLevel(currentMicLevel);
+ }
}
+ get_mic_volume_counter_ms_ += kBufferSizeMs;
}
_ptrAudioBuffer->SetVQEData(msecOnPlaySide, msecOnRecordSide, 0);
diff --git a/webrtc/modules/audio_device/mac/audio_device_mac.h b/webrtc/modules/audio_device/mac/audio_device_mac.h
index bb900e07aa..849e74ce45 100644
--- a/webrtc/modules/audio_device/mac/audio_device_mac.h
+++ b/webrtc/modules/audio_device/mac/audio_device_mac.h
@@ -38,20 +38,26 @@ const uint32_t N_REC_CHANNELS = 1; // default is mono recording
const uint32_t N_PLAY_CHANNELS = 2; // default is stereo playout
const uint32_t N_DEVICE_CHANNELS = 64;
-const uint32_t ENGINE_REC_BUF_SIZE_IN_SAMPLES = (N_REC_SAMPLES_PER_SEC / 100);
-const uint32_t ENGINE_PLAY_BUF_SIZE_IN_SAMPLES = (N_PLAY_SAMPLES_PER_SEC / 100);
+const int kBufferSizeMs = 10;
+
+const uint32_t ENGINE_REC_BUF_SIZE_IN_SAMPLES =
+ N_REC_SAMPLES_PER_SEC * kBufferSizeMs / 1000;
+const uint32_t ENGINE_PLAY_BUF_SIZE_IN_SAMPLES =
+ N_PLAY_SAMPLES_PER_SEC * kBufferSizeMs / 1000;
const int N_BLOCKS_IO = 2;
const int N_BUFFERS_IN = 2; // Must be at least N_BLOCKS_IO.
const int N_BUFFERS_OUT = 3; // Must be at least N_BLOCKS_IO.
-const uint32_t TIMER_PERIOD_MS = (2 * 10 * N_BLOCKS_IO * 1000000);
+const uint32_t TIMER_PERIOD_MS = 2 * 10 * N_BLOCKS_IO * 1000000;
const uint32_t REC_BUF_SIZE_IN_SAMPLES =
ENGINE_REC_BUF_SIZE_IN_SAMPLES * N_DEVICE_CHANNELS * N_BUFFERS_IN;
const uint32_t PLAY_BUF_SIZE_IN_SAMPLES =
ENGINE_PLAY_BUF_SIZE_IN_SAMPLES * N_PLAY_CHANNELS * N_BUFFERS_OUT;
+const int kGetMicVolumeIntervalMs = 1000;
+
class AudioDeviceMac: public AudioDeviceGeneric
{
public:
@@ -372,6 +378,8 @@ private:
// Typing detection
// 0x5c is key "9", after that comes function keys.
bool prev_key_state_[0x5d];
+
+ int get_mic_volume_counter_ms_;
};
} // namespace webrtc