comparison data/fileio/CodedAudioFileReader.cpp @ 318:7a4bd2c8585c

* Some export fixes, and avoid clipping on resampling on import
author Chris Cannam
date Mon, 22 Oct 2007 09:45:35 +0000
parents 4fc6f49436b3
children 7623ecfd5891
comparison
equal deleted inserted replaced
317:c324d410b096 318:7a4bd2c8585c
289 } 289 }
290 290
291 void 291 void
292 CodedAudioFileReader::pushBuffer(float *buffer, size_t sz, bool final) 292 CodedAudioFileReader::pushBuffer(float *buffer, size_t sz, bool final)
293 { 293 {
294 for (size_t i = 0; i < sz; ++i) {
295 if (buffer[i] > 1.f) buffer[i] = 1.f;
296 }
297 for (size_t i = 0; i < sz; ++i) {
298 if (buffer[i] < -1.f) buffer[i] = -1.f;
299 }
300
294 if (m_resampler) { 301 if (m_resampler) {
295 302
296 float ratio = float(m_sampleRate) / float(m_fileRate); 303 float ratio = float(m_sampleRate) / float(m_fileRate);
297 304
298 if (ratio != 1.f) { 305 if (ratio != 1.f) {
301 m_resampleBuffer, 308 m_resampleBuffer,
302 sz, 309 sz,
303 ratio, 310 ratio,
304 final); 311 final);
305 312
306 for (size_t i = 0; i < out; ++i) {
307 if (m_resampleBuffer[i] > 1.f) m_resampleBuffer[i] = 1.f;
308 if (m_resampleBuffer[i] < -1.f) m_resampleBuffer[i] = -1.f;
309 }
310
311 buffer = m_resampleBuffer; 313 buffer = m_resampleBuffer;
312 sz = out; 314 sz = out;
315 }
316
317 for (size_t i = 0; i < sz; ++i) {
318 if (buffer[i] > 1.f) buffer[i] = 1.f;
319 }
320 for (size_t i = 0; i < sz; ++i) {
321 if (buffer[i] < -1.f) buffer[i] = -1.f;
313 } 322 }
314 } 323 }
315 324
316 m_frameCount += sz; 325 m_frameCount += sz;
317 326