Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1038)

Side by Side Diff: webrtc/modules/audio_processing/audio_processing_impl.cc

Issue 1338833002: Fix the maximum native sample rate in AudioProcessing (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Format Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 // VolumeCallbacks implementation. 141 // VolumeCallbacks implementation.
142 void SetMicVolume(int volume) override { volume_ = volume; } 142 void SetMicVolume(int volume) override { volume_ = volume; }
143 int GetMicVolume() override { return volume_; } 143 int GetMicVolume() override { return volume_; }
144 144
145 private: 145 private:
146 GainControl* real_gain_control_; 146 GainControl* real_gain_control_;
147 int volume_; 147 int volume_;
148 }; 148 };
149 149
150 const int AudioProcessing::kNativeSampleRatesHz[] = {
151 AudioProcessing::kSampleRate8kHz,
152 AudioProcessing::kSampleRate16kHz,
153 AudioProcessing::kSampleRate32kHz,
154 AudioProcessing::kSampleRate48kHz};
155 const size_t AudioProcessing::kNumNativeSampleRates =
156 arraysize(AudioProcessing::kNativeSampleRatesHz);
157 const int AudioProcessing::kMaxNativeSampleRateHz = AudioProcessing::
158 kNativeSampleRatesHz[AudioProcessing::kNumNativeSampleRates - 1];
159 const int AudioProcessing::kMaxAECMSampleRateHz = kSampleRate16kHz;
160
150 AudioProcessing* AudioProcessing::Create() { 161 AudioProcessing* AudioProcessing::Create() {
151 Config config; 162 Config config;
152 return Create(config, nullptr); 163 return Create(config, nullptr);
153 } 164 }
154 165
155 AudioProcessing* AudioProcessing::Create(const Config& config) { 166 AudioProcessing* AudioProcessing::Create(const Config& config) {
156 return Create(config, nullptr); 167 return Create(config, nullptr);
157 } 168 }
158 169
159 AudioProcessing* AudioProcessing::Create(const Config& config, 170 AudioProcessing* AudioProcessing::Create(const Config& config,
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 return kBadNumberChannelsError; 404 return kBadNumberChannelsError;
394 } 405 }
395 406
396 api_format_ = config; 407 api_format_ = config;
397 408
398 // We process at the closest native rate >= min(input rate, output rate)... 409 // We process at the closest native rate >= min(input rate, output rate)...
399 const int min_proc_rate = 410 const int min_proc_rate =
400 std::min(api_format_.input_stream().sample_rate_hz(), 411 std::min(api_format_.input_stream().sample_rate_hz(),
401 api_format_.output_stream().sample_rate_hz()); 412 api_format_.output_stream().sample_rate_hz());
402 int fwd_proc_rate; 413 int fwd_proc_rate;
403 if (min_proc_rate > kSampleRate32kHz) { 414 for (size_t i = 0; i < kNumNativeSampleRates; ++i) {
404 fwd_proc_rate = kSampleRate48kHz; 415 fwd_proc_rate = kNativeSampleRatesHz[i];
405 } else if (min_proc_rate > kSampleRate16kHz) { 416 if (fwd_proc_rate >= min_proc_rate) {
406 fwd_proc_rate = kSampleRate32kHz; 417 break;
407 } else if (min_proc_rate > kSampleRate8kHz) { 418 }
408 fwd_proc_rate = kSampleRate16kHz;
409 } else {
410 fwd_proc_rate = kSampleRate8kHz;
411 } 419 }
412 // ...with one exception. 420 // ...with one exception.
413 if (echo_control_mobile_->is_enabled() && min_proc_rate > kSampleRate16kHz) { 421 if (echo_control_mobile_->is_enabled() &&
414 fwd_proc_rate = kSampleRate16kHz; 422 min_proc_rate > kMaxAECMSampleRateHz) {
423 fwd_proc_rate = kMaxAECMSampleRateHz;
415 } 424 }
416 425
417 fwd_proc_format_ = StreamConfig(fwd_proc_rate); 426 fwd_proc_format_ = StreamConfig(fwd_proc_rate);
418 427
419 // We normally process the reverse stream at 16 kHz. Unless... 428 // We normally process the reverse stream at 16 kHz. Unless...
420 int rev_proc_rate = kSampleRate16kHz; 429 int rev_proc_rate = kSampleRate16kHz;
421 if (fwd_proc_format_.sample_rate_hz() == kSampleRate8kHz) { 430 if (fwd_proc_format_.sample_rate_hz() == kSampleRate8kHz) {
422 // ...the forward stream is at 8 kHz. 431 // ...the forward stream is at 8 kHz.
423 rev_proc_rate = kSampleRate8kHz; 432 rev_proc_rate = kSampleRate8kHz;
424 } else { 433 } else {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 return kNullPointerError; 594 return kNullPointerError;
586 } 595 }
587 // Must be a native rate. 596 // Must be a native rate.
588 if (frame->sample_rate_hz_ != kSampleRate8kHz && 597 if (frame->sample_rate_hz_ != kSampleRate8kHz &&
589 frame->sample_rate_hz_ != kSampleRate16kHz && 598 frame->sample_rate_hz_ != kSampleRate16kHz &&
590 frame->sample_rate_hz_ != kSampleRate32kHz && 599 frame->sample_rate_hz_ != kSampleRate32kHz &&
591 frame->sample_rate_hz_ != kSampleRate48kHz) { 600 frame->sample_rate_hz_ != kSampleRate48kHz) {
592 return kBadSampleRateError; 601 return kBadSampleRateError;
593 } 602 }
594 if (echo_control_mobile_->is_enabled() && 603 if (echo_control_mobile_->is_enabled() &&
595 frame->sample_rate_hz_ > kSampleRate16kHz) { 604 frame->sample_rate_hz_ > kMaxAECMSampleRateHz) {
596 LOG(LS_ERROR) << "AECM only supports 16 or 8 kHz sample rates"; 605 LOG(LS_ERROR) << "AECM only supports 16 or 8 kHz sample rates";
597 return kUnsupportedComponentError; 606 return kUnsupportedComponentError;
598 } 607 }
599 608
600 // TODO(ajm): The input and output rates and channels are currently 609 // TODO(ajm): The input and output rates and channels are currently
601 // constrained to be identical in the int16 interface. 610 // constrained to be identical in the int16 interface.
602 ProcessingConfig processing_config = api_format_; 611 ProcessingConfig processing_config = api_format_;
603 processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_); 612 processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_);
604 processing_config.input_stream().set_num_channels(frame->num_channels_); 613 processing_config.input_stream().set_num_channels(frame->num_channels_);
605 processing_config.output_stream().set_sample_rate_hz(frame->sample_rate_hz_); 614 processing_config.output_stream().set_sample_rate_hz(frame->sample_rate_hz_);
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 int err = WriteMessageToDebugFile(); 1251 int err = WriteMessageToDebugFile();
1243 if (err != kNoError) { 1252 if (err != kNoError) {
1244 return err; 1253 return err;
1245 } 1254 }
1246 1255
1247 return kNoError; 1256 return kNoError;
1248 } 1257 }
1249 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 1258 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1250 1259
1251 } // namespace webrtc 1260 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698