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}
This commit is contained in:
parent
fbeb97e01f
commit
ec80f03b3c
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user