comparison dsp/rateconversion/Decimator.cpp @ 22:f7edcd9138bd

* Add decimation filter for 8x decimation
author cannam
date Thu, 10 Jan 2008 15:14:11 +0000
parents d7116e3183f8
children 7fe29d8a7eaf
comparison
equal deleted inserted replaced
21:34808d582f47 22:f7edcd9138bd
7 This file copyright 2005-2006 Christian Landone. 7 This file copyright 2005-2006 Christian Landone.
8 All rights reserved. 8 All rights reserved.
9 */ 9 */
10 10
11 #include "Decimator.h" 11 #include "Decimator.h"
12
13 #include <iostream>
12 14
13 ////////////////////////////////////////////////////////////////////// 15 //////////////////////////////////////////////////////////////////////
14 // Construction/Destruction 16 // Construction/Destruction
15 ////////////////////////////////////////////////////////////////////// 17 //////////////////////////////////////////////////////////////////////
16 18
35 m_decFactor = decFactor; 37 m_decFactor = decFactor;
36 m_outputLength = m_inputLength / m_decFactor; 38 m_outputLength = m_inputLength / m_decFactor;
37 39
38 decBuffer = new double[ m_inputLength ]; 40 decBuffer = new double[ m_inputLength ];
39 41
40 if( m_decFactor == 4 ) 42 // If adding new factors here, add them to
43 // getHighestSupportedFactor in the header as well
44
45 if(m_decFactor == 8)
46 {
47 //////////////////////////////////////////////////
48 b[0] = 0.060111378492136;
49 b[1] = -0.257323420830598;
50 b[2] = 0.420583503165928;
51 b[3] = -0.222750785197418;
52 b[4] = -0.222750785197418;
53 b[5] = 0.420583503165928;
54 b[6] = -0.257323420830598;
55 b[7] = 0.060111378492136;
56
57 a[0] = 1;
58 a[1] = -5.667654878577432;
59 a[2] = 14.062452278088417;
60 a[3] = -19.737303840697738;
61 a[4] = 16.889698874608641;
62 a[5] = -8.796600612325928;
63 a[6] = 2.577553446979888;
64 a[7] = -0.326903916815751;
65 //////////////////////////////////////////////////
66 }
67 else if( m_decFactor == 4 )
41 { 68 {
42 ////////////////////////////////////////////////// 69 //////////////////////////////////////////////////
43 b[ 0 ] = 0.10133306904918619; 70 b[ 0 ] = 0.10133306904918619;
44 b[ 1 ] = -0.2447523353702363; 71 b[ 1 ] = -0.2447523353702363;
45 b[ 2 ] = 0.33622528590120965; 72 b[ 2 ] = 0.33622528590120965;
80 a[ 6 ] = 0.23659265908013868; 107 a[ 6 ] = 0.23659265908013868;
81 a[ 7 ] = 0.032352924250533946; 108 a[ 7 ] = 0.032352924250533946;
82 } 109 }
83 else 110 else
84 { 111 {
112 if ( m_decFactor != 1 ) {
113 std::cerr << "WARNING: Decimator::initialise: unsupported decimation factor " << m_decFactor << ", no antialiasing filter will be used" << std::endl;
114 }
115
85 ////////////////////////////////////////////////// 116 //////////////////////////////////////////////////
86 b[ 0 ] = 1; 117 b[ 0 ] = 1;
87 b[ 1 ] = 0; 118 b[ 1 ] = 0;
88 b[ 2 ] = 0; 119 b[ 2 ] = 0;
89 b[ 3 ] = 0; 120 b[ 3 ] = 0;
115 Input = Output = 0; 146 Input = Output = 0;
116 147
117 o1=o2=o3=o4=o5=o6=o7=0; 148 o1=o2=o3=o4=o5=o6=o7=0;
118 } 149 }
119 150
120 void Decimator::doAntiAlias(double *src, double *dst, unsigned int length) 151 void Decimator::doAntiAlias(const double *src, double *dst, unsigned int length)
121 { 152 {
122 153
123 for( unsigned int i = 0; i < length; i++ ) 154 for( unsigned int i = 0; i < length; i++ )
124 { 155 {
125 Input = (double)src[ i ]; 156 Input = (double)src[ i ];
137 dst[ i ] = Output; 168 dst[ i ] = Output;
138 } 169 }
139 170
140 } 171 }
141 172
142 void Decimator::process(double *src, double *dst) 173 void Decimator::process(const double *src, double *dst)
143 { 174 {
144 if( m_decFactor != 1 ) 175 if( m_decFactor != 1 )
145 { 176 {
146 doAntiAlias( src, decBuffer, m_inputLength ); 177 doAntiAlias( src, decBuffer, m_inputLength );
147 } 178 }