Mercurial > hg > sonic-visualiser
comparison audioio/AudioPortAudioTarget.cpp @ 106:f8e362511b2f
* Probable fix to occasional channel misalignment during playback
author | Chris Cannam |
---|---|
date | Mon, 26 Feb 2007 16:32:37 +0000 |
parents | 0581d552481d |
children | 006c90387f40 |
comparison
equal
deleted
inserted
replaced
105:0581d552481d | 106:f8e362511b2f |
---|---|
200 for (size_t i = 0; i < tmpbufch; ++i) { | 200 for (size_t i = 0; i < tmpbufch; ++i) { |
201 tmpbuf[i] = new float[tmpbufsz]; | 201 tmpbuf[i] = new float[tmpbufsz]; |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 m_source->getSourceSamples(nframes, tmpbuf); | 205 size_t received = m_source->getSourceSamples(nframes, tmpbuf); |
206 | 206 |
207 float peakLeft = 0.0, peakRight = 0.0; | 207 float peakLeft = 0.0, peakRight = 0.0; |
208 | 208 |
209 for (size_t ch = 0; ch < 2; ++ch) { | 209 for (size_t ch = 0; ch < 2; ++ch) { |
210 | 210 |
212 | 212 |
213 if (ch < sourceChannels) { | 213 if (ch < sourceChannels) { |
214 | 214 |
215 // PortAudio samples are interleaved | 215 // PortAudio samples are interleaved |
216 for (size_t i = 0; i < nframes; ++i) { | 216 for (size_t i = 0; i < nframes; ++i) { |
217 output[i * 2 + ch] = tmpbuf[ch][i] * m_outputGain; | 217 if (i < received) { |
218 float sample = fabsf(output[i * 2 + ch]); | 218 output[i * 2 + ch] = tmpbuf[ch][i] * m_outputGain; |
219 if (sample > peak) peak = sample; | 219 float sample = fabsf(output[i * 2 + ch]); |
220 if (sample > peak) peak = sample; | |
221 } else { | |
222 output[i * 2 + ch] = 0; | |
223 } | |
220 } | 224 } |
221 | 225 |
222 } else if (ch == 1 && sourceChannels == 1) { | 226 } else if (ch == 1 && sourceChannels == 1) { |
223 | 227 |
224 for (size_t i = 0; i < nframes; ++i) { | 228 for (size_t i = 0; i < nframes; ++i) { |
225 output[i * 2 + ch] = tmpbuf[0][i] * m_outputGain; | 229 if (i < received) { |
226 float sample = fabsf(output[i * 2 + ch]); | 230 output[i * 2 + ch] = tmpbuf[0][i] * m_outputGain; |
227 if (sample > peak) peak = sample; | 231 float sample = fabsf(output[i * 2 + ch]); |
232 if (sample > peak) peak = sample; | |
233 } else { | |
234 output[i * 2 + ch] = 0; | |
235 } | |
228 } | 236 } |
229 | 237 |
230 } else { | 238 } else { |
231 for (size_t i = 0; i < nframes; ++i) { | 239 for (size_t i = 0; i < nframes; ++i) { |
232 output[i * 2 + ch] = 0; | 240 output[i * 2 + ch] = 0; |