Mercurial > hg > svcore
comparison data/fileio/CodedAudioFileReader.cpp @ 322:7623ecfd5891
* correct frame count in cache-in-memory
* fix clipping avoidance code (was only working for 1/channelCount of the samples)
author | Chris Cannam |
---|---|
date | Thu, 25 Oct 2007 14:30:32 +0000 |
parents | 7a4bd2c8585c |
children | 1d656dcda8ef |
comparison
equal
deleted
inserted
replaced
321:1dc99b430d2a | 322:7623ecfd5891 |
---|---|
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) { | 294 float max = 1.0; |
295 if (buffer[i] > 1.f) buffer[i] = 1.f; | 295 size_t count = sz * m_channelCount; |
296 } | |
297 for (size_t i = 0; i < sz; ++i) { | |
298 if (buffer[i] < -1.f) buffer[i] = -1.f; | |
299 } | |
300 | 296 |
301 if (m_resampler) { | 297 if (m_resampler) { |
302 | 298 |
303 float ratio = float(m_sampleRate) / float(m_fileRate); | 299 float ratio = float(m_sampleRate) / float(m_fileRate); |
304 | 300 |
305 if (ratio != 1.f) { | 301 if (ratio != 1.f) { |
302 | |
306 size_t out = m_resampler->resampleInterleaved | 303 size_t out = m_resampler->resampleInterleaved |
307 (buffer, | 304 (buffer, |
308 m_resampleBuffer, | 305 m_resampleBuffer, |
309 sz, | 306 sz, |
310 ratio, | 307 ratio, |
311 final); | 308 final); |
312 | 309 |
313 buffer = m_resampleBuffer; | 310 buffer = m_resampleBuffer; |
314 sz = out; | 311 sz = out; |
315 } | 312 count = sz * m_channelCount; |
316 | 313 } |
317 for (size_t i = 0; i < sz; ++i) { | 314 } |
318 if (buffer[i] > 1.f) buffer[i] = 1.f; | 315 |
319 } | 316 for (size_t i = 0; i < count; ++i) { |
320 for (size_t i = 0; i < sz; ++i) { | 317 if (buffer[i] > max) buffer[i] = max; |
321 if (buffer[i] < -1.f) buffer[i] = -1.f; | 318 } |
322 } | 319 for (size_t i = 0; i < count; ++i) { |
320 if (buffer[i] < -max) buffer[i] = -max; | |
323 } | 321 } |
324 | 322 |
325 m_frameCount += sz; | 323 m_frameCount += sz; |
326 | 324 |
327 switch (m_cacheMode) { | 325 switch (m_cacheMode) { |
330 //!!! check for return value! out of disk space, etc! | 328 //!!! check for return value! out of disk space, etc! |
331 sf_writef_float(m_cacheFileWritePtr, buffer, sz); | 329 sf_writef_float(m_cacheFileWritePtr, buffer, sz); |
332 break; | 330 break; |
333 | 331 |
334 case CacheInMemory: | 332 case CacheInMemory: |
335 for (size_t s = 0; s < sz; ++s) { | 333 for (size_t s = 0; s < count; ++s) { |
336 m_data.push_back(buffer[sz]); | 334 m_data.push_back(buffer[count]); |
337 } | 335 } |
338 MUNLOCK_SAMPLEBLOCK(m_data); | 336 MUNLOCK_SAMPLEBLOCK(m_data); |
339 break; | 337 break; |
340 } | 338 } |
341 } | 339 } |