comparison data/fileio/CodedAudioFileReader.cpp @ 929:59e7fe1b1003 warnfix_no_size_t

Unsigned removals and warning fixes in data/
author Chris Cannam
date Tue, 17 Jun 2014 14:33:42 +0100
parents f5cd33909744
children d03b3d956358
comparison
equal deleted inserted replaced
928:6a94bb528e9d 929:59e7fe1b1003
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 size_t targetRate) : 31 int targetRate) :
32 m_cacheMode(cacheMode), 32 m_cacheMode(cacheMode),
33 m_initialised(false), 33 m_initialised(false),
34 m_serialiser(0), 34 m_serialiser(0),
35 m_fileRate(0), 35 m_fileRate(0),
36 m_cacheFileWritePtr(0), 36 m_cacheFileWritePtr(0),
170 170
171 m_initialised = true; 171 m_initialised = true;
172 } 172 }
173 173
174 void 174 void
175 CodedAudioFileReader::addSamplesToDecodeCache(float **samples, size_t nframes) 175 CodedAudioFileReader::addSamplesToDecodeCache(float **samples, int nframes)
176 { 176 {
177 QMutexLocker locker(&m_cacheMutex); 177 QMutexLocker locker(&m_cacheMutex);
178 178
179 if (!m_initialised) return; 179 if (!m_initialised) return;
180 180
181 for (size_t i = 0; i < nframes; ++i) { 181 for (int i = 0; i < nframes; ++i) {
182 182
183 for (size_t c = 0; c < m_channelCount; ++c) { 183 for (int c = 0; c < m_channelCount; ++c) {
184 184
185 float sample = samples[c][i]; 185 float sample = samples[c][i];
186 186
187 m_cacheWriteBuffer[m_cacheWriteBufferIndex++] = sample; 187 m_cacheWriteBuffer[m_cacheWriteBufferIndex++] = sample;
188 188
200 } 200 }
201 } 201 }
202 } 202 }
203 203
204 void 204 void
205 CodedAudioFileReader::addSamplesToDecodeCache(float *samples, size_t nframes) 205 CodedAudioFileReader::addSamplesToDecodeCache(float *samples, int nframes)
206 { 206 {
207 QMutexLocker locker(&m_cacheMutex); 207 QMutexLocker locker(&m_cacheMutex);
208 208
209 if (!m_initialised) return; 209 if (!m_initialised) return;
210 210
211 for (size_t i = 0; i < nframes; ++i) { 211 for (int i = 0; i < nframes; ++i) {
212 212
213 for (size_t c = 0; c < m_channelCount; ++c) { 213 for (int c = 0; c < m_channelCount; ++c) {
214 214
215 float sample = samples[i * m_channelCount + c]; 215 float sample = samples[i * m_channelCount + c];
216 216
217 m_cacheWriteBuffer[m_cacheWriteBufferIndex++] = sample; 217 m_cacheWriteBuffer[m_cacheWriteBufferIndex++] = sample;
218 218
236 { 236 {
237 QMutexLocker locker(&m_cacheMutex); 237 QMutexLocker locker(&m_cacheMutex);
238 238
239 if (!m_initialised) return; 239 if (!m_initialised) return;
240 240
241 for (size_t i = 0; i < samples.size(); ++i) { 241 for (int i = 0; i < (int)samples.size(); ++i) {
242 242
243 float sample = samples[i]; 243 float sample = samples[i];
244 244
245 m_cacheWriteBuffer[m_cacheWriteBufferIndex++] = sample; 245 m_cacheWriteBuffer[m_cacheWriteBufferIndex++] = sample;
246 246
291 if (m_cacheFileReader) m_cacheFileReader->updateFrameCount(); 291 if (m_cacheFileReader) m_cacheFileReader->updateFrameCount();
292 } 292 }
293 } 293 }
294 294
295 void 295 void
296 CodedAudioFileReader::pushBuffer(float *buffer, size_t sz, bool final) 296 CodedAudioFileReader::pushBuffer(float *buffer, int sz, bool final)
297 { 297 {
298 m_fileFrameCount += sz; 298 m_fileFrameCount += sz;
299 299
300 float ratio = 1.f; 300 float ratio = 1.f;
301 if (m_resampler && m_fileRate != 0) { 301 if (m_resampler && m_fileRate != 0) {
308 pushBufferNonResampling(buffer, sz); 308 pushBufferNonResampling(buffer, sz);
309 } 309 }
310 } 310 }
311 311
312 void 312 void
313 CodedAudioFileReader::pushBufferNonResampling(float *buffer, size_t sz) 313 CodedAudioFileReader::pushBufferNonResampling(float *buffer, int sz)
314 { 314 {
315 float max = 1.0; 315 float max = 1.0;
316 size_t count = sz * m_channelCount; 316 int count = sz * m_channelCount;
317 317
318 for (size_t i = 0; i < count; ++i) { 318 for (int i = 0; i < count; ++i) {
319 if (buffer[i] > max) buffer[i] = max; 319 if (buffer[i] > max) buffer[i] = max;
320 } 320 }
321 for (size_t i = 0; i < count; ++i) { 321 for (int i = 0; i < count; ++i) {
322 if (buffer[i] < -max) buffer[i] = -max; 322 if (buffer[i] < -max) buffer[i] = -max;
323 } 323 }
324 324
325 m_frameCount += sz; 325 m_frameCount += sz;
326 326
327 switch (m_cacheMode) { 327 switch (m_cacheMode) {
328 328
329 case CacheInTemporaryFile: 329 case CacheInTemporaryFile:
330 if (sf_writef_float(m_cacheFileWritePtr, buffer, sz) < sz) { 330 if (sf_writef_float(m_cacheFileWritePtr, buffer, sz) < (int)sz) {
331 sf_close(m_cacheFileWritePtr); 331 sf_close(m_cacheFileWritePtr);
332 m_cacheFileWritePtr = 0; 332 m_cacheFileWritePtr = 0;
333 throw InsufficientDiscSpace(TempDirectory::getInstance()->getPath()); 333 throw InsufficientDiscSpace(TempDirectory::getInstance()->getPath());
334 } 334 }
335 break; 335 break;
336 336
337 case CacheInMemory: 337 case CacheInMemory:
338 m_dataLock.lockForWrite(); 338 m_dataLock.lockForWrite();
339 for (size_t s = 0; s < count; ++s) { 339 for (int s = 0; s < count; ++s) {
340 m_data.push_back(buffer[s]); 340 m_data.push_back(buffer[s]);
341 } 341 }
342 MUNLOCK_SAMPLEBLOCK(m_data); 342 MUNLOCK_SAMPLEBLOCK(m_data);
343 m_dataLock.unlock(); 343 m_dataLock.unlock();
344 break; 344 break;
345 } 345 }
346 } 346 }
347 347
348 void 348 void
349 CodedAudioFileReader::pushBufferResampling(float *buffer, size_t sz, 349 CodedAudioFileReader::pushBufferResampling(float *buffer, int sz,
350 float ratio, bool final) 350 float ratio, bool final)
351 { 351 {
352 SVDEBUG << "pushBufferResampling: ratio = " << ratio << ", sz = " << sz << ", final = " << final << endl; 352 SVDEBUG << "pushBufferResampling: ratio = " << ratio << ", sz = " << sz << ", final = " << final << endl;
353 353
354 if (sz > 0) { 354 if (sz > 0) {
355 355
356 size_t out = m_resampler->resampleInterleaved 356 int out = m_resampler->resampleInterleaved
357 (buffer, 357 (buffer,
358 m_resampleBuffer, 358 m_resampleBuffer,
359 sz, 359 sz,
360 ratio, 360 ratio,
361 false); 361 false);
363 pushBufferNonResampling(m_resampleBuffer, out); 363 pushBufferNonResampling(m_resampleBuffer, out);
364 } 364 }
365 365
366 if (final) { 366 if (final) {
367 367
368 size_t padFrames = 1; 368 int padFrames = 1;
369 if (m_frameCount / ratio < m_fileFrameCount) { 369 if (m_frameCount / ratio < m_fileFrameCount) {
370 padFrames = m_fileFrameCount - (m_frameCount / ratio) + 1; 370 padFrames = m_fileFrameCount - (m_frameCount / ratio) + 1;
371 } 371 }
372 372
373 size_t padSamples = padFrames * m_channelCount; 373 int padSamples = padFrames * m_channelCount;
374 374
375 SVDEBUG << "frameCount = " << m_frameCount << ", equivFileFrames = " << m_frameCount / ratio << ", m_fileFrameCount = " << m_fileFrameCount << ", padFrames= " << padFrames << ", padSamples = " << padSamples << endl; 375 SVDEBUG << "frameCount = " << m_frameCount << ", equivFileFrames = " << m_frameCount / ratio << ", m_fileFrameCount = " << m_fileFrameCount << ", padFrames= " << padFrames << ", padSamples = " << padSamples << endl;
376 376
377 float *padding = new float[padSamples]; 377 float *padding = new float[padSamples];
378 for (int i = 0; i < padSamples; ++i) padding[i] = 0.f; 378 for (int i = 0; i < padSamples; ++i) padding[i] = 0.f;
379 379
380 size_t out = m_resampler->resampleInterleaved 380 int out = m_resampler->resampleInterleaved
381 (padding, 381 (padding,
382 m_resampleBuffer, 382 m_resampleBuffer,
383 padFrames, 383 padFrames,
384 ratio, 384 ratio,
385 true); 385 true);
386 386
387 if (m_frameCount + out > int(m_fileFrameCount * ratio)) { 387 if (int(m_frameCount + out) > int(m_fileFrameCount * ratio)) {
388 out = int(m_fileFrameCount * ratio) - m_frameCount; 388 out = int(m_fileFrameCount * ratio) - int(m_frameCount);
389 } 389 }
390 390
391 pushBufferNonResampling(m_resampleBuffer, out); 391 pushBufferNonResampling(m_resampleBuffer, out);
392 delete[] padding; 392 delete[] padding;
393 } 393 }
394 } 394 }
395 395
396 void 396 void
397 CodedAudioFileReader::getInterleavedFrames(size_t start, size_t count, 397 CodedAudioFileReader::getInterleavedFrames(int start, int count,
398 SampleBlock &frames) const 398 SampleBlock &frames) const
399 { 399 {
400 // Lock is only required in CacheInMemory mode (the cache file 400 // Lock is only required in CacheInMemory mode (the cache file
401 // reader is expected to be thread safe and manage its own 401 // reader is expected to be thread safe and manage its own
402 // locking) 402 // locking)
419 frames.clear(); 419 frames.clear();
420 if (!isOK()) return; 420 if (!isOK()) return;
421 if (count == 0) return; 421 if (count == 0) return;
422 frames.reserve(count * m_channelCount); 422 frames.reserve(count * m_channelCount);
423 423
424 size_t idx = start * m_channelCount; 424 int idx = start * m_channelCount;
425 size_t i = 0; 425 int i = 0;
426 426
427 m_dataLock.lockForRead(); 427 m_dataLock.lockForRead();
428 while (i < count * m_channelCount && idx < m_data.size()) { 428 while (i < count * m_channelCount && idx < (int)m_data.size()) {
429 frames.push_back(m_data[idx]); 429 frames.push_back(m_data[idx]);
430 ++idx; 430 ++idx;
431 } 431 }
432 m_dataLock.unlock(); 432 m_dataLock.unlock();
433 } 433 }