File: ResponseTaker.h

package info (click to toggle)
lsp-plugins 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 91,856 kB
  • sloc: cpp: 427,831; xml: 57,779; makefile: 9,961; php: 1,005; sh: 18
file content (290 lines) | stat: -rw-r--r-- 10,946 bytes parent folder | download
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
 *           (C) 2020 Stefano Tronci <stefano.tronci@protonmail.com>
 *
 * This file is part of lsp-dsp-units
 * Created on: 30 Jul 2017
 *
 * lsp-dsp-units is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * lsp-dsp-units is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with lsp-dsp-units. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef LSP_PLUG_IN_DSP_UNITS_UTIL_RESPONSETAKER_H_
#define LSP_PLUG_IN_DSP_UNITS_UTIL_RESPONSETAKER_H_

#include <lsp-plug.in/dsp-units/version.h>
#include <lsp-plug.in/dsp-units/iface/IStateDumper.h>
#include <lsp-plug.in/dsp-units/sampling/Sample.h>
#include <lsp-plug.in/common/status.h>

namespace lsp
{
    namespace dspu
    {
        class LSP_DSP_UNITS_PUBLIC ResponseTaker
        {
            private:
                ResponseTaker & operator = (const ResponseTaker &);
                ResponseTaker(const ResponseTaker &);

            protected:
                // Input processor state enumerator
                enum ip_state_t
                {
                    IP_BYPASS,                  // Bypassing the signal
                    IP_WAIT,                    // Bypassing while the Output Processor fades out and emits zeros
                    IP_ACQUIRE                  // Receiving input samples and recording input
                };

                // Output processor state enumerator
                enum op_state_t
                {
                    OP_BYPASS,                  // Bypassing the signal
                    OP_FADEOUT,                 // Fading out the signal
                    OP_PAUSE,                   // Emitting zeros
                    OP_TEST_SIG_EMIT,           // Emitting the chirp samples
                    OP_TAIL_EMIT,               // Emitting the chirp zeros tail (to allow both latency shift and acquisition of reverberant tail into the capture buffer)
                    OP_FADEIN                   // Fading in the signal
                };

                // Input Processor parameters
                typedef struct ip_t
                {
                    ip_state_t  nState;         // State
                    size_t      ig_time;        // Global Time counter
                    size_t      ig_start;       // Fix instant at which acquisition starts
                    size_t      ig_stop;        // Fix instant at which acquisition ends

                    float       fAcquire;       // Acquisition duration (chirp + tail)
                    size_t      nAcquire;       // Acquisition length (chirp + tail)
                    size_t      nAcquireTime;   // Count samples in input when in IP_ACQUIRE state
                } ip_t;

                // Output Processor parameters
                typedef struct op_t
                {
                    op_state_t  nState;         // State
                    size_t      og_time;        // Global Time counter
                    size_t      og_start;       // Fix instant at which emission starts

                    float       fGain;          // Fading gain
                    float       fGainDelta;     // Fading gain delta

                    float       fFade;          // Fade time [s]
                    size_t      nFade;          // Fade time [samples]

                    float       fPause;         // Pause duration [s]
                    size_t      nPause;         // Pause duration [samples]
                    size_t      nPauseTime;     // Count samples in output when in OP_PAUSE state

                    float       fTail;          // Tail duration [s].
                    size_t      nTail;          // Tail duration [samples]
                    size_t      nTailTime;      // Count samples when in OP_TAIL_EMIT state

                    float       fTestSig;       // Test signal duration [s]
                    size_t      nTestSig;       // Test signal duration [samples]
                    size_t      nTestSigTime;   // Count samples in output when in OP_TEST_SIG_EMIT state
                } op_t;

            private:
                size_t      nSampleRate;

                ip_t        sInputProcessor;
                op_t        sOutputProcessor;

                Sample     *pTestSig;
                Sample     *pCapture;

                size_t      nLatency;           // Latency of the transmission line under test [samples]. LatencyDetector will supply this.
                size_t      nTimeWarp;          // Entity of the warp between processors at OP_CHIRP_EMIT trigger
                size_t      nCaptureStart;      // Sample in capture buffer at which the recorded chirp actually starts

                bool        bCycleComplete;     // True if the machine operated a whole measurement cycle

                bool        bSync;

            public:

                explicit ResponseTaker();
                ~ResponseTaker();

                /** Construct the ResponseTaker
                 *
                 */
                void construct();

                /** Initialise ResponseTaker
                 *
                 */
                void init();

                /** Destroy ResponseTaker
                 *
                 */
                void destroy();

            public:
                status_t reconfigure(Sample *testsig);

                /** Check that ResponseTaker needs settings update
                 *
                 * @return true if ResponseTaker needs setting update
                 */
                inline bool needs_update() const
                {
                    return bSync;
                }

                /** Update ResponseTaker stateful settings
                 *
                 */
                void update_settings();

                /** Set sample rate for ResponseTaker
                 *
                 * @param sr sample rate
                 */
                inline void set_sample_rate(size_t sr)
                {
                    if (nSampleRate == sr)
                        return;

                    nSampleRate                     = sr;
                    bSync                           = true;
                }

                /** Set output processor fading in seconds
                 *
                 * @param fading fading duration in seconds
                 */
                inline void set_op_fading(float fading)
                {
                    if (sOutputProcessor.fFade == fading)
                        return;

                    sOutputProcessor.fFade          = fading;
                    bSync                           = true;
                }

                /** Set output processor pause in seconds
                 *
                 * @param pause pause duration in seconds
                 */
                inline void set_op_pause(float pause)
                {
                    if (sOutputProcessor.fPause == pause)
                        return;

                    sOutputProcessor.fPause         = pause;
                    bSync                           = true;
                }

                /** Set output processor tail in seconds
                 *
                 * @param tail tail duration in seconds
                 */
                inline void set_op_tail(float tail)
                {
                    if (sOutputProcessor.fTail == tail)
                        return;

                    sOutputProcessor.fTail          = tail;
                    bSync                           = true;
                }

                /** Set the latency of the transmission line
                 *
                 * @param latency latency in samples
                 */
                inline void set_latency_samples(ssize_t latency)
                {
                    if (nLatency == size_t(latency))
                        return;

                    nLatency                        = (latency > 0) ? size_t(latency) : 0;
                    bSync                           = true;
                }

                /** Start latency detection process
                 *
                 */
                void start_capture();

                /** Force the chirp system to reset it's state
                 *
                 */
                void reset_capture();

                /** Return true if the measurement cycle was completed
                 *
                 * @return bCycleComplete value
                 */
                inline bool cycle_complete() const
                {
                    return bCycleComplete;
                }

                /** Get the captured data
                 *
                 * @return pointer to captured Sample object
                 */
                inline Sample * get_capture()
                {
                    return pCapture;
                }

                /** Get sample at which the capture buffer contains data
                 *
                 * @return capture start sample
                 */
                inline size_t get_capture_start()
                {
                    return nCaptureStart;
                }

            public:

                /** Collect input samples:
                 *
                 * @param dst samples destination
                 * @param src input source, allowed to be NULL
                 * @param count number of samples to process
                 */
                void process_in(float *dst, const float *src, size_t count);

                /** Stream output samples:
                 *
                 * @param dst samples destination
                 * @param src input source, allowed to be NULL
                 * @param count number of samples to process
                 */
                void process_out(float *dst, const float *src, size_t count);

                /** Stream direct chirp while recording response
                 *
                 * @param dst samples destination
                 * @param src input source, allowed to be NULL
                 * @param count number of samples to process
                 */
                void process(float *dst, const float *src, size_t count);

                /**
                 * Dump the state
                 * @param dumper dumper
                 */
                void dump(IStateDumper *v) const;
        };
    }
}

#endif /* LSP_PLUG_IN_DSP_UNITS_UTIL_RESPONSETAKER_H_ */