default_output_rate_calculator.cc (1580B)
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 "modules/audio_mixer/default_output_rate_calculator.h" 12 13 #include <algorithm> 14 #include <iterator> 15 16 #include "api/array_view.h" 17 #include "api/audio/audio_processing.h" 18 #include "rtc_base/checks.h" 19 20 namespace webrtc { 21 22 int DefaultOutputRateCalculator::CalculateOutputRateFromRange( 23 ArrayView<const int> preferred_sample_rates) { 24 if (preferred_sample_rates.empty()) { 25 return DefaultOutputRateCalculator::kDefaultFrequency; 26 } 27 using NativeRate = AudioProcessing::NativeRate; 28 const int maximal_frequency = *std::max_element( 29 preferred_sample_rates.cbegin(), preferred_sample_rates.cend()); 30 31 RTC_DCHECK_LE(NativeRate::kSampleRate8kHz, maximal_frequency); 32 RTC_DCHECK_GE(NativeRate::kSampleRate48kHz, maximal_frequency); 33 34 static constexpr NativeRate native_rates[] = { 35 NativeRate::kSampleRate8kHz, NativeRate::kSampleRate16kHz, 36 NativeRate::kSampleRate32kHz, NativeRate::kSampleRate48kHz}; 37 const auto* rounded_up_index = std::lower_bound( 38 std::begin(native_rates), std::end(native_rates), maximal_frequency); 39 RTC_DCHECK(rounded_up_index != std::end(native_rates)); 40 return *rounded_up_index; 41 } 42 } // namespace webrtc