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
|
// ----------------------------------------------------------------------------
//
// Copyright (C) 2003-2013 Fons Adriaensen <fons@linuxaudio.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
#ifndef __CONVOLVE_H
#define __CONVOLVE_H
//#define USE_SSE_AND_3DN
#include <fftw3.h>
enum { CONV_OPT_SSE = 1, CONV_OPT_3DN = 2 };
class Convdata
{
public:
Convdata (size_t part, size_t lmax, unsigned int opts);
~Convdata (void);
size_t part (void) const { return _part; }
unsigned int npar (void) const { return _npar; }
unsigned int opts (void) const { return _opts; }
void prepare_part (unsigned int ipar, float gain, float *data, int step = 1);
void prepare_done (void);
int get_refc (void) const { return _refc; }
int inc_refc (void) { return ++_refc; }
int dec_refc (void) { return --_refc; }
private:
static void swap (fftwf_complex *p, size_t n);
friend class Convolver;
int _refc; // reference counter
size_t _part; // partition size in frames
unsigned int _opts; // optimization flags
unsigned int _npar; // number of partitions
unsigned int _nact; // number of active partitions
float _norm; // gain normalization
float *_buff; // input buffer
fftwf_complex **_fftd; // transformed partitions
fftwf_plan _plan; // fftw plan
};
class Convolver
{
public:
Convolver (size_t part, size_t size, unsigned int opts, unsigned int nip, unsigned int nop);
~Convolver (void);
float *wr_ptr (unsigned int i) const { return _ip_buff + i * _part; }
float *rd_ptr (unsigned int i) const { return _op_buff + 2 * i * _part; }
int set_conv (unsigned int ip, unsigned int op, Convdata *C);
Convdata *get_conv (unsigned int ip, unsigned int op) const { return _conv [ip + _nip * op]; }
void reset (void);
void process (void);
size_t part (void) const { return _part; }
unsigned int npar (void) const { return _npar; }
unsigned int opts (void) const { return _opts; }
unsigned int nip (void) const { return _nip; }
unsigned int nop (void) const { return _nop; }
private:
// configuration
//
size_t _part; // partition size in frames
unsigned int _opts; // optimization flags
unsigned int _npar; // number of partitions
unsigned int _nip; // number of inputs
unsigned int _nop; // number of outputs
Convdata **_conv; // array of Convdata pointers
fftwf_plan _fwd_plan; // fftw plans
fftwf_plan _rev_plan; //
// data buffers
//
float *_ip_buff; // input buffer
float *_op_buff; // output buffer
float *_oA_buff; // alternating output buffers
float *_oB_buff; //
fftwf_complex **_fwd_data; // circular array of input parts
fftwf_complex *_mac_data; // multiplied data accumulator
// interface
//
float *_wr_buff; // input pointer for input 0
float *_rd_buff; // output pointer for output 0
// processing
//
unsigned int _iter;
unsigned int _offs;
};
#endif
|