VISR  0.11.8
Versatile Interactive Scene Renderer
fir.hpp
Go to the documentation of this file.
1 //
2 // fir.hpp
3 //
4 // Created by Dylan Menzies on 09/03/2015.
5 // Copyright (c) ISVR, University of Southampton. All rights reserved.
6 //
7 // Multichannel FIR with one input, multiple outputs.
8 // includes:
9 // - impulse response load
10 // - upsample - makes impulse longer with same number of multiplies, spectrum is shrunk and repeated.
11 // - create/run sparse white noise tristate FIR - efficient addition-only filters for fast spatial spreading with spectral variation. Suitable for per-object spreading with spectral variation.
12 
13 
14 
15 #ifndef __VISR__FIR__
16 #define __VISR__FIR__
17 
18 #include "export_symbols.hpp"
19 
20 #include <libefl/basic_matrix.hpp>
21 
22 #include <cstdio>
23 
24 // uncomment to include the tristate FIR stuff again which is not currently used in the filtering.
25 #define USE_TRISTATE_FIR
26 
27 namespace visr
28 {
29 // forward declarations
30 namespace efl
31 {
32 template<typename ElementType > class BasicMatrix;
33 }
34 
35 namespace rbbl
36 {
37 
38 class VISR_RBBL_LIBRARY_SYMBOL FIR
39 {
40 public:
44  using Afloat = float;
45 
49  static const int nBlockSamples = 64; //128 //2 test
50 
51  static const int maxnFIRs = 64;
56  static const int maxnFIRblocks = 32; //32
57  static const int maxnFIRsamples = nBlockSamples*maxnFIRblocks;
58  static const int nBufferSamples = nBlockSamples*(maxnFIRblocks+1);
59 
60  FIR();
61 
62  int setNumFIRs(int n) {
63  m_nFIRs = n;
64  m_B.resize( n, m_nFIRsamples );
65  return 0;
66  };
67  int setNumFIRsamples(int n) {
68  m_nFIRsamples = n;
69  m_B.resize( m_nFIRs, m_nFIRsamples );
70  m_nFIRsamples = n; return 0;
71  };
72  int setUpsampleRatio(int n) {
73  // <af> Is this correct? m_B is never accesses past m_nFIRsamples ?
74  if (n * m_nFIRsamples > maxnFIRsamples) return -1;
75  m_nUpsample = n; return 0; };
76 
82  void loadFIRs( efl::BasicMatrix<Afloat> const & filterCoeffs );
83 
84 #ifdef USE_TRISTATE_FIR
85  int createWhiteTristateFIRs(Afloat density);
86 #endif
87 
88  int process( Afloat const * in, Afloat * const * out);
89 
90 
91 private:
92 
93  int m_nFIRs = 0;
94  int m_nFIRsamples = 0;
95 
96  // general FIR
98  // Afloat m_B[maxnFIRs][maxnFIRsamples]; // FIR coefficients for each FIR
100 
101  int m_nUpsample = 1;
102 
103 #ifdef USE_TRISTATE_FIR
104  // tristate FIR
105  int m_iBplus[maxnFIRs][maxnFIRsamples]; // index list
106  int m_iBminus[maxnFIRs][maxnFIRsamples];
107  int m_nBplus[maxnFIRs];
108  int m_nBminus[maxnFIRs];
109 #endif
110 
111  Afloat m_gain[maxnFIRs]; // for normalization etc.
112 
113  Afloat m_inBuffer[nBufferSamples]; // circular input buffer
114  int m_iBuf = 0; // buffer index to current block.
115 };
116 
117 } // namespace rbbl
118 } // namespace visr
119 
120 #endif /* defined(__VISR__FIR__) */
int setUpsampleRatio(int n)
Definition: fir.hpp:72
float Afloat
Definition: fir.hpp:44
int setNumFIRs(int n)
Definition: fir.hpp:62
Definition: options.cpp:10
int setNumFIRsamples(int n)
Definition: fir.hpp:67
Definition: fir.hpp:38