-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbd_line.h
96 lines (86 loc) · 3.27 KB
/
bbd_line.h
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
#pragma once
#include "bbd_filter.h"
#include <algorithm>
#include <vector>
#include <memory>
#include <complex>
typedef std::complex<double> cdouble;
class BBD_Line {
public:
/**
* Initialize a delay line with the specified parameters. (non-RT)
* @param fs audio sampling rate
* @param ns number of stages / length of the virtual capacitor array
* @param fsin analog specification of the input filter
* @param fsout analog specification of the output filter
*/
void setup(double fs, unsigned ns, const BBD_Filter_Spec &fsin, const BBD_Filter_Spec &fsout);
/**
* Change the number of stages. (RT?)
* @note It guarantees not to reallocate the buffer for \f$ns \leq 8192\f$.
* @param ns number of stages / length of the virtual capacitor array
*/
void set_delay_size(unsigned ns);
/**
* Reinitialize all the internal state to zero. (RT)
*/
void clear();
/**
* Process a block of audio signal. (RT)
* @note The clock input is defined as \f$F_{clk}/F_{s}\f$, where
* \f$F_{clk}\f$ is the desired BBD instantaneous clock rate. It is
* valid to have \f$F_{clk}>F_{s}/2\f$.
* @param n number of frames to process
* @param input input buffer of size @p n
* @param output output buffer of size @p n
* @param clock clock input buffer of size @p n
*/
void process(unsigned n, const float *input, float *output, const float *clock);
/**
* Process a block of audio signal in place. (RT)
* @param n number of frames to process
* @param inout input/output buffer of size @p n
* @param clock clock input buffer of size @p n
*/
void process(unsigned n, float *inout, const float *clock);
/**
* Get the discretization of the input filter. (RT)
* @return digital filter model
*/
const BBD_Filter_Coef &filter_in() const noexcept { return *fin_; }
/**
* Get the discretization of the output filter. (RT)
* @return digital filter model
*/
const BBD_Filter_Coef &filter_out() const noexcept { return *fout_; }
/**
* Determine the BBD clock rate \f$F_{clk}\f$ which obtains a given delay. (RT)
* @param delay delay in seconds
* @param ns number of stages / length of the virtual capacitor array
* @return BBD clock rate in Hz
*/
static inline double hz_rate_for_delay(double delay, unsigned ns)
{ return 2 * ns / delay; }
/**
* Determine the delay obtained for a given BBD clock rate \f$F_{clk}\f$. (RT)
* @param rate BBD clock rate in Hz
* @param ns number of stages / length of the virtual capacitor array
* @return delay in seconds
*/
static inline double delay_for_hz_rate(double rate, unsigned ns)
{ return 2 * ns / rate; }
private:
unsigned ns_; // delay size
std::vector<float> mem_; // delay memory
unsigned imem_; // delay memory index
double pclk_; // clock phase
unsigned ptick_; // clock tick counter
double ybbd_old_;
const BBD_Filter_Coef *fin_;
const BBD_Filter_Coef *fout_;
std::unique_ptr<cdouble[]> Xin_;
std::unique_ptr<cdouble[]> Xout_;
std::unique_ptr<cdouble[]> Xout_mem_; // sample memory of output filter
std::unique_ptr<cdouble[]> Gin_;
std::unique_ptr<cdouble[]> Gout_;
};