-
Notifications
You must be signed in to change notification settings - Fork 0
/
dll.hh
139 lines (110 loc) · 4.94 KB
/
dll.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <mha_plugin.hh>
namespace t::plugins::dll {
/** Runtime configuration class of MHA plugin which implements the time
smoothing filter described in
Fons Adriensen: Using a DLL to filter time. 2005.
http://kokkinizita.linuxaudio.org/papers/usingdll.pdf */
class cfg_t {
public:
cfg_t(const mhaconfig_t & signal_dimensions,
const double bandwidth,
const std::string & clock_source_name,
const double adjustment = 0);
virtual ~cfg_t() = default;
/** Block update rate / Hz */
const double F;
/** Bandwidth of block update rate */
const double B;
/** 0th order parameter, always 0 */
static constexpr double a = 0.0f;
/** 1st order parameter, sqrt(2)2piB/F */
const double b;
/** 2nd order parameter, (2piB/F)^2 */
const double c;
/** number of samples per block */
const uint64_t nper;
/** nominal duration of 1 block in seconds */
const double tper;
/** Adjustment added to the filtered time stamps (in seconds) */
const double adjustment;
/** which clock clock_gettime should use */
clockid_t clock_source;
/** actual duration of 1 block of audio, in seconds.
* Initialized to nominal block duration at startup and after
* dropouts, then adapted to measured duration by the dll. */
double e2;
/** start time of the current block as predicted by the dll. */
double t0;
/** start time of the next block as predicted by the dll. */
double t1;
/** Total sample index of first sample in current block.
* Reset to zero for every dropout. */
uint64_t n0 = {0U};
/** Total sample index of first sample in next block.
* Reset to zero for every dropout. */
uint64_t n1 = {0U};
/** Difference between measured and predicted time. Adapts loop.*/
double e;
/** Queries the clock. Invokes filter_time.
* @return the filtered start times of this and the next buffer
* in seconds */
virtual std::pair<double,double> process();
/** Filters the input time */
virtual double filter_time(double unfiltered_time);
/** Filter the time for the first time: Initialize the loop state.
* @return unmodified input time */
virtual double dll_init(double unfiltered_time);
/** Filter the time regularly: Update the loop state.
* @return the prediction from last invocation. */
virtual double dll_update(double unfiltered_time);
};
/** Interface class of MHA plugin which implements the time smoothing filter
described in
Fons Adriensen: Using a DLL to filter time. 2005.
http://kokkinizita.linuxaudio.org/papers/usingdll.pdf */
class if_t : public MHAPlugin::plugin_t<cfg_t>
{
public:
/** Constructor publishes the result AC variable.
* @param algo_comm AC variable space
* @param configured_name Loaded name of plugin, used as AC variable name */
if_t(algo_comm_t & algo_comm,
const std::string & configured_name);
/** Process callback for processing time domain or STFT signal.
* Input signal is not used.
* @return unmodified pointer to input signal */
template<class mha_xxxx_t> mha_xxxx_t* process(mha_xxxx_t*);
/** Prepare for signal processing.
* @param signal_dimensions Signal metadata:
* srate and fragsize are used. */
void prepare(mhaconfig_t & signal_dimensions);
/** Empty implementation of release. */
void release();
/** Connects configuration events to actions. */
MHAEvents::patchbay_t<if_t> patchbay;
/** Start time of current buffer filtered with a delay locked loop
* published as AC variable */
MHA_AC::double_t filtered_time_t0;
/** Start time of next buffer filtered with a delay locked loop
* published as AC variable */
MHA_AC::double_t filtered_time_t1;
MHAParser::float_t bandwidth =
{"Bandwidth of the delay-locked-loop in Hz." ,"NaN", "]0,]"};
MHAParser::kw_t clock_source =
{"Clock source for unfiltered times, see man clock_gettime",
"CLOCK_REALTIME","[CLOCK_REALTIME CLOCK_REALTIME_COARSE"
" CLOCK_MONOTONIC CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_RAW"
" CLOCK_BOOTTIME CLOCK_PROCESS_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID]"
};
MHAParser::float_t adjustment =
{"Additive adjustment for the filtered times, can e.g. be used to\n"
"account for either input or output latency", "0", "[,]"};
virtual void update(void);
};
}
// Local variables:
// compile-command: "make"
// c-basic-offset: 4
// indent-tabs-mode: nil
// coding: utf-8-unix
// End: