Debian Codegraph @

source/convolve.h

raw
1 // ----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2003-2013 Fons Adriaensen <[email protected]>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // ----------------------------------------------------------------------------
19
20
21 #ifndef __CONVOLVE_H
22 #define __CONVOLVE_H
23
24
25 //#define USE_SSE_AND_3DN
26
27
28 #include <fftw3.h>
29
30
31 enum { CONV_OPT_SSE = 1, CONV_OPT_3DN = 2 };
32
33
34 class Convdata
35 {
36 public:
37
38 Convdata (size_t part, size_t lmax, unsigned int opts);
39 ~Convdata (void);
40
41 size_t part (void) const { return _part; }
42 unsigned int npar (void) const { return _npar; }
43 unsigned int opts (void) const { return _opts; }
44
45 void prepare_part (unsigned int ipar, float gain, float *data, int step = 1);
46 void prepare_done (void);
47
48 int get_refc (void) const { return _refc; }
49 int inc_refc (void) { return ++_refc; }
50 int dec_refc (void) { return --_refc; }
51
52 private:
53
54 static void swap (fftwf_complex *p, size_t n);
55
56 friend class Convolver;
57
58 int _refc; // reference counter
59 size_t _part; // partition size in frames
60 unsigned int _opts; // optimization flags
61 unsigned int _npar; // number of partitions
62 unsigned int _nact; // number of active partitions
63 float _norm; // gain normalization
64 float *_buff; // input buffer
65 fftwf_complex **_fftd; // transformed partitions
66 fftwf_plan _plan; // fftw plan
67 };
68
69
70
71 class Convolver
72 {
73 public:
74
75 Convolver (size_t part, size_t size, unsigned int opts, unsigned int nip, unsigned int nop);
76 ~Convolver (void);
77
78 float *wr_ptr (unsigned int i) const { return _ip_buff + i * _part; }
79 float *rd_ptr (unsigned int i) const { return _op_buff + 2 * i * _part; }
80
81 int set_conv (unsigned int ip, unsigned int op, Convdata *C);
82 Convdata *get_conv (unsigned int ip, unsigned int op) const { return _conv [ip + _nip * op]; }
83
84 void reset (void);
85 void process (void);
86
87 size_t part (void) const { return _part; }
88 unsigned int npar (void) const { return _npar; }
89 unsigned int opts (void) const { return _opts; }
90 unsigned int nip (void) const { return _nip; }
91 unsigned int nop (void) const { return _nop; }
92
93 private:
94
95 // configuration
96 //
97 size_t _part; // partition size in frames
98 unsigned int _opts; // optimization flags
99 unsigned int _npar; // number of partitions
100 unsigned int _nip; // number of inputs
101 unsigned int _nop; // number of outputs
102 Convdata **_conv; // array of Convdata pointers
103 fftwf_plan _fwd_plan; // fftw plans
104 fftwf_plan _rev_plan; //
105
106 // data buffers
107 //
108 float *_ip_buff; // input buffer
109 float *_op_buff; // output buffer
110 float *_oA_buff; // alternating output buffers
111 float *_oB_buff; //
112 fftwf_complex **_fwd_data; // circular array of input parts
113 fftwf_complex *_mac_data; // multiplied data accumulator
114
115 // interface
116 //
117 float *_wr_buff; // input pointer for input 0
118 float *_rd_buff; // output pointer for output 0
119
120 // processing
121 //
122 unsigned int _iter;
123 unsigned int _offs;
124 };
125
126
127 #endif
128