Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
freq_estimator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Roc Streaming authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_audio/freq_estimator.h
10//! @brief Frequency estimator.
11
12#ifndef ROC_AUDIO_FREQ_ESTIMATOR_H_
13#define ROC_AUDIO_FREQ_ESTIMATOR_H_
14
16#include "roc_audio/sample.h"
18#include "roc_packet/units.h"
19
20namespace roc {
21namespace audio {
22
23//! FreqEstimator tunable parameters.
25 float P; //!< Proportional gain of PI-controller.
26 float I; //!< Integral gain of PI-controller.
27
28 //! How much downsample input value (latency buffer size) on the first stage. Must be
29 //! less or equal to fe_decim_factor_max and must be greater than zero.
31 //! How much downsample input value on the second stage. Must be
32 //! less or equal to fe_decim_factor_max. Could be zero to disable the second
33 //! decimation stage.
35
37 : P(100e-8f)
38 , I(0.5e-8f)
39 , decimation_factor1(fe_decim_factor_max)
40 , decimation_factor2(fe_decim_factor_max) {
41 }
42};
43
44//! Evaluates sender's frequency to receivers's frequency ratio.
46public:
47 //! Initialize.
48 //!
49 //! @b Parameters
50 //! - @p target_latency defines latency we want to archive.
52 packet::timestamp_t target_latency);
53 //! Get current frequecy coefficient.
54 float freq_coeff() const;
55
56 //! Compute new value of frequency coefficient.
57 void update(packet::timestamp_t current_latency);
58
59private:
60 bool run_decimators_(packet::timestamp_t current, float& filtered);
61 float run_controller_(float current);
62
63 const FreqEstimatorConfig config_;
64 const float target_; // Target latency.
65
66 float dec1_casc_buff_[fe_decim_len];
67 size_t dec1_ind_;
68
69 float dec2_casc_buff_[fe_decim_len];
70 size_t dec2_ind_;
71
72 size_t samples_counter_; // Input samples counter.
73 float accum_; // Integrator value.
74
75 float coeff_; // Current frequency coefficient value.
76};
77
78} // namespace audio
79} // namespace roc
80
81#endif // ROC_AUDIO_FREQ_ESTIMATOR_H_
Evaluates sender's frequency to receivers's frequency ratio.
void update(packet::timestamp_t current_latency)
Compute new value of frequency coefficient.
FreqEstimator(FreqEstimatorConfig config, packet::timestamp_t target_latency)
Initialize.
float freq_coeff() const
Get current frequecy coefficient.
Base class for non-copyable objects.
Definition: noncopyable.h:23
Frequency estimator config.
uint32_t timestamp_t
Audio packet timestamp.
Definition: units.h:25
Root namespace.
Non-copyable object.
Audio sample.
FreqEstimator tunable parameters.
size_t decimation_factor1
How much downsample input value (latency buffer size) on the first stage. Must be less or equal to fe...
float I
Integral gain of PI-controller.
size_t decimation_factor2
How much downsample input value on the second stage. Must be less or equal to fe_decim_factor_max....
float P
Proportional gain of PI-controller.
Various units used in packets.