comparison data/model/AggregateWaveModel.cpp @ 1008:d9e0e59a1581

When using an aggregate model to pass data to a transform, zero-pad the shorter input to the duration of the longer rather than truncating the longer. (This is better behaviour for e.g. MATCH, and in any case the code was previously truncating incorrectly and ending up with garbage data at the end.)
author Chris Cannam
date Fri, 14 Nov 2014 13:51:33 +0000
parents cd42620e3f40
children cc27f35aa75c
comparison
equal deleted inserted replaced
1006:d954e03274e8 1008:d9e0e59a1581
116 for (int i = 0; i < count; ++i) { 116 for (int i = 0; i < count; ++i) {
117 buffer[i] = 0.f; 117 buffer[i] = 0.f;
118 } 118 }
119 } 119 }
120 120
121 int sz = count; 121 int longest = 0;
122 122
123 for (int c = ch0; c <= ch1; ++c) { 123 for (int c = ch0; c <= ch1; ++c) {
124 int szHere = 124 int here =
125 m_components[c].model->getData(m_components[c].channel, 125 m_components[c].model->getData(m_components[c].channel,
126 start, count, 126 start, count,
127 readbuf); 127 readbuf);
128 if (szHere < sz) sz = szHere; 128 if (here > longest) {
129 longest = here;
130 }
131 if (here < count) {
132 for (int i = here; i < count; ++i) {
133 readbuf[i] = 0.f;
134 }
135 }
129 if (mixing) { 136 if (mixing) {
130 for (int i = 0; i < count; ++i) { 137 for (int i = 0; i < count; ++i) {
131 buffer[i] += readbuf[i]; 138 buffer[i] += readbuf[i];
132 } 139 }
133 } 140 }
134 } 141 }
135 142
136 if (mixing) delete[] readbuf; 143 if (mixing) delete[] readbuf;
137 return sz; 144 return longest;
138 } 145 }
139 146
140 int 147 int
141 AggregateWaveModel::getData(int channel, int start, int count, 148 AggregateWaveModel::getData(int channel, int start, int count,
142 double *buffer) const 149 double *buffer) const
155 for (int i = 0; i < count; ++i) { 162 for (int i = 0; i < count; ++i) {
156 buffer[i] = 0.0; 163 buffer[i] = 0.0;
157 } 164 }
158 } 165 }
159 166
160 int sz = count; 167 int longest = 0;
161 168
162 for (int c = ch0; c <= ch1; ++c) { 169 for (int c = ch0; c <= ch1; ++c) {
163 int szHere = 170 int here =
164 m_components[c].model->getData(m_components[c].channel, 171 m_components[c].model->getData(m_components[c].channel,
165 start, count, 172 start, count,
166 readbuf); 173 readbuf);
167 if (szHere < sz) sz = szHere; 174 if (here > longest) {
175 longest = here;
176 }
177 if (here < count) {
178 for (int i = here; i < count; ++i) {
179 readbuf[i] = 0.;
180 }
181 }
168 if (mixing) { 182 if (mixing) {
169 for (int i = 0; i < count; ++i) { 183 for (int i = 0; i < count; ++i) {
170 buffer[i] += readbuf[i]; 184 buffer[i] += readbuf[i];
171 } 185 }
172 } 186 }
173 } 187 }
174 188
175 if (mixing) delete[] readbuf; 189 if (mixing) delete[] readbuf;
176 return sz; 190 return longest;
177 } 191 }
178 192
179 int 193 int
180 AggregateWaveModel::getData(int fromchannel, int tochannel, 194 AggregateWaveModel::getData(int fromchannel, int tochannel,
181 int start, int count, 195 int start, int count,