comparison data/fileio/CodedAudioFileReader.cpp @ 933:d03b3d956358 warnfix_no_size_t

Merge from branch tony_integration
author Chris Cannam
date Wed, 18 Jun 2014 08:34:46 +0100
parents 59e7fe1b1003 9911b8cb53bc
children cc27f35aa75c
comparison
equal deleted inserted replaced
932:e06f03013f46 933:d03b3d956358
26 #include <iostream> 26 #include <iostream>
27 #include <QDir> 27 #include <QDir>
28 #include <QMutexLocker> 28 #include <QMutexLocker>
29 29
30 CodedAudioFileReader::CodedAudioFileReader(CacheMode cacheMode, 30 CodedAudioFileReader::CodedAudioFileReader(CacheMode cacheMode,
31 int targetRate) : 31 int targetRate,
32 bool normalised) :
32 m_cacheMode(cacheMode), 33 m_cacheMode(cacheMode),
33 m_initialised(false), 34 m_initialised(false),
34 m_serialiser(0), 35 m_serialiser(0),
35 m_fileRate(0), 36 m_fileRate(0),
36 m_cacheFileWritePtr(0), 37 m_cacheFileWritePtr(0),
38 m_cacheWriteBuffer(0), 39 m_cacheWriteBuffer(0),
39 m_cacheWriteBufferIndex(0), 40 m_cacheWriteBufferIndex(0),
40 m_cacheWriteBufferSize(16384), 41 m_cacheWriteBufferSize(16384),
41 m_resampler(0), 42 m_resampler(0),
42 m_resampleBuffer(0), 43 m_resampleBuffer(0),
43 m_fileFrameCount(0) 44 m_fileFrameCount(0),
44 { 45 m_normalised(normalised),
45 SVDEBUG << "CodedAudioFileReader::CodedAudioFileReader: rate " << targetRate << endl; 46 m_max(0.f),
47 m_gain(1.f)
48 {
49 SVDEBUG << "CodedAudioFileReader::CodedAudioFileReader: rate " << targetRate << ", normalised = " << normalised << endl;
46 50
47 m_frameCount = 0; 51 m_frameCount = 0;
48 m_sampleRate = targetRate; 52 m_sampleRate = targetRate;
49 } 53 }
50 54
268 if (!m_initialised) { 272 if (!m_initialised) {
269 cerr << "WARNING: CodedAudioFileReader::finishDecodeCache: Cache was never initialised!" << endl; 273 cerr << "WARNING: CodedAudioFileReader::finishDecodeCache: Cache was never initialised!" << endl;
270 return; 274 return;
271 } 275 }
272 276
273 // if (m_cacheWriteBufferIndex > 0) { 277 pushBuffer(m_cacheWriteBuffer,
274 pushBuffer(m_cacheWriteBuffer, 278 m_cacheWriteBufferIndex / m_channelCount,
275 m_cacheWriteBufferIndex / m_channelCount, 279 true);
276 true);
277 // }
278 280
279 delete[] m_cacheWriteBuffer; 281 delete[] m_cacheWriteBuffer;
280 m_cacheWriteBuffer = 0; 282 m_cacheWriteBuffer = 0;
281 283
282 delete[] m_resampleBuffer; 284 delete[] m_resampleBuffer;
310 } 312 }
311 313
312 void 314 void
313 CodedAudioFileReader::pushBufferNonResampling(float *buffer, int sz) 315 CodedAudioFileReader::pushBufferNonResampling(float *buffer, int sz)
314 { 316 {
315 float max = 1.0; 317 float clip = 1.0;
316 int count = sz * m_channelCount; 318 int count = sz * m_channelCount;
317 319
318 for (int i = 0; i < count; ++i) { 320 if (m_normalised) {
319 if (buffer[i] > max) buffer[i] = max; 321 for (int i = 0; i < count; ++i) {
320 } 322 float v = fabsf(buffer[i]);
321 for (int i = 0; i < count; ++i) { 323 if (v > m_max) {
322 if (buffer[i] < -max) buffer[i] = -max; 324 m_max = v;
325 m_gain = 1.f / m_max;
326 }
327 }
328 } else {
329 for (int i = 0; i < count; ++i) {
330 if (buffer[i] > clip) buffer[i] = clip;
331 }
332 for (int i = 0; i < count; ++i) {
333 if (buffer[i] < -clip) buffer[i] = -clip;
334 }
323 } 335 }
324 336
325 m_frameCount += sz; 337 m_frameCount += sz;
326 338
327 switch (m_cacheMode) { 339 switch (m_cacheMode) {
430 ++idx; 442 ++idx;
431 } 443 }
432 m_dataLock.unlock(); 444 m_dataLock.unlock();
433 } 445 }
434 } 446 }
435 } 447
436 448 if (m_normalised) {
449 for (int i = 0; i < (int)(count * m_channelCount); ++i) {
450 frames[i] *= m_gain;
451 }
452 }
453 }
454