/* * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #include "modules/audio_processing/agc2/compute_interpolated_gain_curve.h" #include <algorithm> #include <cmath> #include <queue> #include <tuple> #include <utility> #include <vector> #include "modules/audio_processing/agc2/agc2_common.h" #include "modules/audio_processing/agc2/agc2_testing_common.h" #include "modules/audio_processing/agc2/limiter_db_gain_curve.h" #include "rtc_base/checks.h" namespace webrtc { namespace { std::pair<double, double> ComputeLinearApproximationParams( const LimiterDbGainCurve* limiter, const double x) { … } double ComputeAreaUnderPiecewiseLinearApproximation( const LimiterDbGainCurve* limiter, const double x0, const double x1) { … } // Computes the approximation error in the limiter region for a given interval. // The error is computed as the difference between the areas beneath the limiter // curve to approximate and its linear under-approximation. double LimiterUnderApproximationNegativeError(const LimiterDbGainCurve* limiter, const double x0, const double x1) { … } // Automatically finds where to sample the beyond-knee region of a limiter using // a greedy optimization algorithm that iteratively decreases the approximation // error. // The solution is sub-optimal because the algorithm is greedy and the points // are assigned by halving intervals (starting with the whole beyond-knee region // as a single interval). However, even if sub-optimal, this algorithm works // well in practice and it is efficiently implemented using priority queues. std::vector<double> SampleLimiterRegion(const LimiterDbGainCurve* limiter) { … } // Compute the parameters to over-approximate the knee region via linear // interpolation. Over-approximating is saturation-safe since the knee region is // convex. void PrecomputeKneeApproxParams(const LimiterDbGainCurve* limiter, test::InterpolatedParameters* parameters) { … } // Compute the parameters to under-approximate the beyond-knee region via linear // interpolation and greedy sampling. Under-approximating is saturation-safe // since the beyond-knee region is concave. void PrecomputeBeyondKneeApproxParams( const LimiterDbGainCurve* limiter, test::InterpolatedParameters* parameters) { … } } // namespace namespace test { InterpolatedParameters ComputeInterpolatedGainCurveApproximationParams() { … } } // namespace test } // namespace webrtc