~ubuntu-branches/ubuntu/wily/aliki/wily

« back to all changes in this revision

Viewing changes to source/convolve.h

  • Committer: Bazaar Package Importer
  • Author(s): Jaromír Mikeš
  • Date: 2011-07-26 21:12:17 UTC
  • Revision ID: james.westby@ubuntu.com-20110726211217-v948cgyyjokiq3sl
Tags: upstream-0.1.0
Import upstream version 0.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -------------------------------------------------------------------------
 
2
//
 
3
//    Copyright (C) 2005-2007 Fons Adriaensen <fons@kokkinizita.net>
 
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 2 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, write to the Free Software
 
17
//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
//
 
19
// -------------------------------------------------------------------------
 
20
 
 
21
 
 
22
#ifndef __CONVOLVE_H
 
23
#define __CONVOLVE_H
 
24
 
 
25
 
 
26
//#define USE_SSE_AND_3DN
 
27
 
 
28
 
 
29
#include <fftw3.h>
 
30
 
 
31
 
 
32
enum { CONV_OPT_SSE = 1, CONV_OPT_3DN = 2 };
 
33
 
 
34
 
 
35
class Convdata
 
36
{
 
37
public:
 
38
 
 
39
    Convdata (size_t part, size_t lmax, unsigned int opts);
 
40
    ~Convdata (void);
 
41
 
 
42
    size_t       part (void) const { return _part; }
 
43
    unsigned int npar (void) const { return _npar; }
 
44
    unsigned int opts (void) const { return _opts; }
 
45
 
 
46
    void prepare_part (unsigned int ipar, float gain, float *data, int step = 1);
 
47
    void prepare_done (void);
 
48
 
 
49
    int get_refc (void) const { return _refc; }
 
50
    int inc_refc (void) { return ++_refc; }
 
51
    int dec_refc (void) { return --_refc; }
 
52
 
 
53
private:
 
54
 
 
55
    static void swap (fftwf_complex *p, size_t n);
 
56
 
 
57
    friend class Convolver;
 
58
 
 
59
    int                _refc;      // reference counter
 
60
    size_t             _part;      // partition size in frames
 
61
    unsigned int       _opts;      // optimization flags
 
62
    unsigned int       _npar;      // number of partitions
 
63
    unsigned int       _nact;      // number of active partitions
 
64
    float              _norm;      // gain normalization
 
65
    float             *_buff;      // input buffer
 
66
    fftwf_complex    **_fftd;      // transformed partitions
 
67
    fftwf_plan         _plan;      // fftw plan
 
68
};
 
69
 
 
70
 
 
71
 
 
72
class Convolver
 
73
{
 
74
public:
 
75
 
 
76
    Convolver (size_t part, size_t size, unsigned int opts, unsigned int nip, unsigned int nop);
 
77
    ~Convolver (void);
 
78
 
 
79
    float *wr_ptr (unsigned int i) const { return _ip_buff +     i * _part; }
 
80
    float *rd_ptr (unsigned int i) const { return _op_buff + 2 * i * _part; }
 
81
 
 
82
    int       set_conv (unsigned int ip, unsigned int op, Convdata *C);
 
83
    Convdata *get_conv (unsigned int ip, unsigned int op) const { return _conv [ip + _nip * op]; }
 
84
 
 
85
    void reset (void);
 
86
    void process (void);
 
87
 
 
88
    size_t       part (void) const { return _part; }
 
89
    unsigned int npar (void) const { return _npar; }
 
90
    unsigned int opts (void) const { return _opts; }
 
91
    unsigned int nip  (void) const { return _nip; }
 
92
    unsigned int nop  (void) const { return _nop; }
 
93
 
 
94
private:
 
95
 
 
96
    // configuration
 
97
    //
 
98
    size_t             _part;      // partition size in frames
 
99
    unsigned int       _opts;      // optimization flags
 
100
    unsigned int       _npar;      // number of partitions
 
101
    unsigned int       _nip;       // number of inputs
 
102
    unsigned int       _nop;       // number of outputs
 
103
    Convdata         **_conv;      // array of Convdata pointers
 
104
    fftwf_plan         _fwd_plan;  // fftw plans
 
105
    fftwf_plan         _rev_plan;  //
 
106
 
 
107
    // data buffers
 
108
    //
 
109
    float             *_ip_buff;   // input buffer
 
110
    float             *_op_buff;   // output buffer
 
111
    float             *_oA_buff;   // alternating output buffers
 
112
    float             *_oB_buff;   //
 
113
    fftwf_complex    **_fwd_data;  // circular array of input parts  
 
114
    fftwf_complex     *_mac_data;  // multiplied data accumulator  
 
115
 
 
116
    // interface 
 
117
    //
 
118
    float             *_wr_buff;   // input pointer for input 0
 
119
    float             *_rd_buff;   // output pointer for output 0
 
120
 
 
121
    // processing
 
122
    //
 
123
    unsigned int       _iter;
 
124
    unsigned int       _offs;
 
125
};
 
126
 
 
127
 
 
128
#endif
 
129