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

Side by Side Diff: webrtc/modules/audio_mixer/default_output_rate_calculator.cc

Issue 2557713006: Injectable output rate calculater for AudioMixer. (Closed)
Patch Set: stl instead of loop, renamed SetOutputFrequency. Created 4 years 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
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/audio_mixer/default_output_rate_calculator.h"
12
13 #include <algorithm>
14
15 #include "webrtc/modules/audio_processing/include/audio_processing.h"
16
17 namespace webrtc {
18
19 int DefaultOutputRateCalculator::CalculateOutputRate(
20 const std::vector<int>& preferred_sample_rates) {
21 if (preferred_sample_rates.empty()) {
22 return DefaultOutputRateCalculator::kDefaultFrequency;
23 }
24 using NativeRate = AudioProcessing::NativeRate;
25 const int maximal_frequency = *std::max_element(
26 preferred_sample_rates.begin(), preferred_sample_rates.end());
27
28 RTC_DCHECK_LE(NativeRate::kSampleRate8kHz, maximal_frequency);
29 RTC_DCHECK_GE(NativeRate::kSampleRate48kHz, maximal_frequency);
30
31 static constexpr NativeRate native_rates[] = {
32 NativeRate::kSampleRate8kHz, NativeRate::kSampleRate16kHz,
33 NativeRate::kSampleRate32kHz, NativeRate::kSampleRate48kHz};
34 const auto rounded_up_index = std::lower_bound(
35 std::begin(native_rates), std::end(native_rates), maximal_frequency);
36 RTC_DCHECK(rounded_up_index != std::end(native_rates));
37 return *rounded_up_index;
38 }
39 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_mixer/default_output_rate_calculator.h ('k') | webrtc/modules/audio_mixer/output_rate_calculator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698