comparison dsp/signalconditioning/DFProcess.cpp @ 74:769da847732b

* A few fixes prompted by vamp-plugin-tester
author cannam
date Mon, 08 Jun 2009 12:30:20 +0000
parents d72fcd34d9a7
children a5eae96a357c
comparison
equal deleted inserted replaced
73:dcb555b90924 74:769da847732b
80 } 80 }
81 81
82 82
83 void DFProcess::medianFilter(double *src, double *dst) 83 void DFProcess::medianFilter(double *src, double *dst)
84 { 84 {
85 unsigned int i,k,j,l; 85 int i,k,j,l;
86 unsigned int index = 0; 86 int index = 0;
87 87
88 double val = 0; 88 double val = 0;
89 89
90 double* y = new double[ m_winPost + m_winPre + 1]; 90 double* y = new double[ m_winPost + m_winPre + 1];
91 memset( y, 0, sizeof( double ) * ( m_winPost + m_winPre + 1) ); 91 memset( y, 0, sizeof( double ) * ( m_winPost + m_winPre + 1) );
92 92
93 double* scratch = new double[ m_length ]; 93 double* scratch = new double[ m_length ];
94 94
95 for( i = 0; i < m_winPre; i++) 95 for( i = 0; i < m_winPre && index; i++)
96 { 96 {
97 if (index >= m_length) break;
98
97 k = i + m_winPost + 1; 99 k = i + m_winPost + 1;
98 100
99 for( j = 0; j < k; j++) 101 for( j = 0; j < k; j++)
100 { 102 {
101 y[ j ] = src[ j ]; 103 y[ j ] = src[ j ];
102 } 104 }
103 scratch[ index ] = MathUtilities::median( y, k ); 105 scratch[ index ] = MathUtilities::median( y, k );
104 index++; 106 index++;
105 } 107 }
106 108
107 for( i = 0; i < ( m_length - ( m_winPost + m_winPre ) ); i ++) 109 for( i = 0; i + m_winPost + m_winPre < m_length; i ++)
108 { 110 {
111 if (index >= m_length) break;
112
109 113
110 l = 0; 114 l = 0;
111 for( j = i; j < ( i + m_winPost + m_winPre + 1); j++) 115 for( j = i; j < ( i + m_winPost + m_winPre + 1); j++)
112 { 116 {
113 y[ l ] = src[ j ]; 117 y[ l ] = src[ j ];
115 } 119 }
116 120
117 scratch[ index++ ] = MathUtilities::median( y, (m_winPost + m_winPre + 1 )); 121 scratch[ index++ ] = MathUtilities::median( y, (m_winPost + m_winPre + 1 ));
118 } 122 }
119 123
120 for( i = std::max( m_length - m_winPost, (unsigned)1); i < m_length; i++) 124 for( i = std::max( m_length - m_winPost, 1); i < m_length; i++)
121 { 125 {
122 k = std::max( i - m_winPre, (unsigned)1); 126 if (index >= m_length) break;
127
128 k = std::max( i - m_winPre, 1);
123 129
124 l = 0; 130 l = 0;
125 for( j = k; j < m_length; j++) 131 for( j = k; j < m_length; j++)
126 { 132 {
127 y[ l ] = src[ j ]; 133 y[ l ] = src[ j ];