Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
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
15
#include "
roc_audio/freq_estimator_decim.h
"
16
#include "
roc_audio/sample.h
"
17
#include "
roc_core/noncopyable.h
"
18
#include "
roc_packet/units.h
"
19
20
namespace
roc
{
21
namespace
audio
{
22
23
//! FreqEstimator paremeter preset.
24
enum
FreqEstimatorProfile
{
25
//! Fast and responsive tuning.
26
//! Good for lower network latency and jitter.
27
FreqEstimatorProfile_Responsive
,
28
29
//! Slow and smooth tuning.
30
//! Good for higher network latency and jitter.
31
FreqEstimatorProfile_Gradual
32
};
33
34
//! FreqEstimator tunable parameters.
35
struct
FreqEstimatorConfig {
36
double
P
;
//!< Proportional gain of PI-controller.
37
double
I
;
//!< Integral gain of PI-controller.
38
39
//! How much downsample input value (latency buffer size) on the first stage.
40
//! Must be less or equal to fe_decim_factor_max and must be greater than zero.
41
size_t
decimation_factor1
;
42
43
//! How much downsample input value on the second stage. Must be less or equal
44
//! to fe_decim_factor_max. Could be zero to disable the second decimation stage.
45
size_t
decimation_factor2
;
46
47
FreqEstimatorConfig()
48
:
P
(0)
49
,
I
(0)
50
,
decimation_factor1
(0)
51
,
decimation_factor2
(0) {
52
}
53
};
54
55
//! Evaluates sender's frequency to receivers's frequency ratio.
56
//! @remarks
57
//! We provide FreqEstimator with traget latency and periodically update it with
58
//! the actual latency. In response, FreqEstimator computes frequency coefficient,
59
//! the ratio of sender to receiver frequency. This coefficient is then set as
60
//! the scaling factor of the resampler, which in result compensates the frequency
61
//! difference and moves the latency closer to its target value.
62
class
FreqEstimator
:
public
core::NonCopyable
<> {
63
public
:
64
//! Initialize.
65
//!
66
//! @b Parameters
67
//! - @p profile defines configuration preset.
68
//! - @p target_latency defines latency we want to archive.
69
FreqEstimator
(
FreqEstimatorProfile
profile,
70
packet::stream_timestamp_t
target_latency);
71
72
//! Get current frequecy coefficient.
73
float
freq_coeff
()
const
;
74
75
//! Compute new value of frequency coefficient.
76
void
update
(
packet::stream_timestamp_t
current_latency);
77
78
private
:
79
bool
run_decimators_(
packet::stream_timestamp_t
current,
double
& filtered);
80
double
run_controller_(
double
current);
81
82
const
FreqEstimatorConfig
config_;
83
const
double
target_;
// Target latency.
84
85
double
dec1_casc_buff_[fe_decim_len];
86
size_t
dec1_ind_;
87
88
double
dec2_casc_buff_[fe_decim_len];
89
size_t
dec2_ind_;
90
91
size_t
samples_counter_;
// Input samples counter.
92
double
accum_;
// Integrator value.
93
94
double
coeff_;
// Current frequency coefficient value.
95
};
96
97
}
// namespace audio
98
}
// namespace roc
99
100
#endif
// ROC_AUDIO_FREQ_ESTIMATOR_H_
roc::audio::FreqEstimator::update
void update(packet::stream_timestamp_t current_latency)
Compute new value of frequency coefficient.
roc::audio::FreqEstimator::FreqEstimator
FreqEstimator(FreqEstimatorProfile profile, packet::stream_timestamp_t target_latency)
Initialize.
roc::audio::FreqEstimator::freq_coeff
float freq_coeff() const
Get current frequecy coefficient.
roc::core::NonCopyable
Base class for non-copyable objects.
Definition
noncopyable.h:23
freq_estimator_decim.h
Frequency estimator config.
roc::audio
Audio frames and audio processing.
roc::audio::FreqEstimatorProfile
FreqEstimatorProfile
FreqEstimator paremeter preset.
Definition
freq_estimator.h:24
roc::audio::FreqEstimatorProfile_Gradual
@ FreqEstimatorProfile_Gradual
Slow and smooth tuning. Good for higher network latency and jitter.
Definition
freq_estimator.h:31
roc::audio::FreqEstimatorProfile_Responsive
@ FreqEstimatorProfile_Responsive
Fast and responsive tuning. Good for lower network latency and jitter.
Definition
freq_estimator.h:27
roc::packet::stream_timestamp_t
uint32_t stream_timestamp_t
Packet stream timestamp.
Definition
units.h:36
roc
Root namespace.
noncopyable.h
Non-copyable object.
sample.h
Audio sample.
roc::audio::FreqEstimatorConfig
FreqEstimator tunable parameters.
Definition
freq_estimator.h:35
roc::audio::FreqEstimatorConfig::I
double I
Integral gain of PI-controller.
Definition
freq_estimator.h:37
roc::audio::FreqEstimatorConfig::decimation_factor1
size_t decimation_factor1
How much downsample input value (latency buffer size) on the first stage. Must be less or equal to fe...
Definition
freq_estimator.h:41
roc::audio::FreqEstimatorConfig::decimation_factor2
size_t decimation_factor2
How much downsample input value on the second stage. Must be less or equal to fe_decim_factor_max....
Definition
freq_estimator.h:45
roc::audio::FreqEstimatorConfig::P
double P
Proportional gain of PI-controller.
Definition
freq_estimator.h:36
units.h
Various units used in packets.
roc_audio
freq_estimator.h
Generated by
1.17.0