comparison data/fileio/CodedAudioFileReader.cpp @ 1305:9f9f55a8af92 mp3-gapless

Add gapless flag to MP3FileReader, and implement trimming the delay samples from the start (padding is not yet trimmed from end)
author Chris Cannam
date Tue, 29 Nov 2016 11:35:56 +0000
parents 5cc969b236b0
children b325e91505b5
comparison
equal deleted inserted replaced
1304:7cff8367d9b1 1305:9f9f55a8af92
46 m_resampleBuffer(0), 46 m_resampleBuffer(0),
47 m_fileFrameCount(0), 47 m_fileFrameCount(0),
48 m_normalised(normalised), 48 m_normalised(normalised),
49 m_max(0.f), 49 m_max(0.f),
50 m_gain(1.f), 50 m_gain(1.f),
51 m_trimFromStart(0),
52 m_trimFromEnd(0),
51 m_clippedCount(0), 53 m_clippedCount(0),
52 m_firstNonzero(0), 54 m_firstNonzero(0),
53 m_lastNonzero(0) 55 m_lastNonzero(0)
54 { 56 {
55 SVDEBUG << "CodedAudioFileReader:: cache mode: " << cacheMode 57 SVDEBUG << "CodedAudioFileReader:: cache mode: " << cacheMode
89 if (!m_data.empty()) { 91 if (!m_data.empty()) {
90 StorageAdviser::notifyDoneAllocation 92 StorageAdviser::notifyDoneAllocation
91 (StorageAdviser::MemoryAllocation, 93 (StorageAdviser::MemoryAllocation,
92 (m_data.size() * sizeof(float)) / 1024); 94 (m_data.size() * sizeof(float)) / 1024);
93 } 95 }
96 }
97
98 void
99 CodedAudioFileReader::setSamplesToTrim(sv_frame_t fromStart, sv_frame_t fromEnd)
100 {
101 m_trimFromStart = fromStart;
102 m_trimFromEnd = fromEnd;
94 } 103 }
95 104
96 void 105 void
97 CodedAudioFileReader::startSerialised(QString id) 106 CodedAudioFileReader::startSerialised(QString id)
98 { 107 {
221 QMutexLocker locker(&m_cacheMutex); 230 QMutexLocker locker(&m_cacheMutex);
222 231
223 if (!m_initialised) return; 232 if (!m_initialised) return;
224 233
225 for (sv_frame_t i = 0; i < nframes; ++i) { 234 for (sv_frame_t i = 0; i < nframes; ++i) {
235
236 if (m_trimFromStart > 0) {
237 --m_trimFromStart;
238 continue;
239 }
226 240
227 for (int c = 0; c < m_channelCount; ++c) { 241 for (int c = 0; c < m_channelCount; ++c) {
228 242
229 float sample = samples[c][i]; 243 float sample = samples[c][i];
230 244
251 QMutexLocker locker(&m_cacheMutex); 265 QMutexLocker locker(&m_cacheMutex);
252 266
253 if (!m_initialised) return; 267 if (!m_initialised) return;
254 268
255 for (sv_frame_t i = 0; i < nframes; ++i) { 269 for (sv_frame_t i = 0; i < nframes; ++i) {
270
271 if (m_trimFromStart > 0) {
272 --m_trimFromStart;
273 continue;
274 }
256 275
257 for (int c = 0; c < m_channelCount; ++c) { 276 for (int c = 0; c < m_channelCount; ++c) {
258 277
259 float sample = samples[i * m_channelCount + c]; 278 float sample = samples[i * m_channelCount + c];
260 279
281 QMutexLocker locker(&m_cacheMutex); 300 QMutexLocker locker(&m_cacheMutex);
282 301
283 if (!m_initialised) return; 302 if (!m_initialised) return;
284 303
285 for (float sample: samples) { 304 for (float sample: samples) {
305
306 if (m_trimFromStart > 0) {
307 --m_trimFromStart;
308 continue;
309 }
286 310
287 m_cacheWriteBuffer[m_cacheWriteBufferIndex++] = sample; 311 m_cacheWriteBuffer[m_cacheWriteBufferIndex++] = sample;
288 312
289 if (m_cacheWriteBufferIndex == 313 if (m_cacheWriteBufferIndex ==
290 m_cacheWriteBufferSize * m_channelCount) { 314 m_cacheWriteBufferSize * m_channelCount) {
374 CodedAudioFileReader::pushBufferNonResampling(float *buffer, sv_frame_t sz) 398 CodedAudioFileReader::pushBufferNonResampling(float *buffer, sv_frame_t sz)
375 { 399 {
376 float clip = 1.0; 400 float clip = 1.0;
377 sv_frame_t count = sz * m_channelCount; 401 sv_frame_t count = sz * m_channelCount;
378 402
403 // statistics
379 for (sv_frame_t j = 0; j < sz; ++j) { 404 for (sv_frame_t j = 0; j < sz; ++j) {
380 for (int c = 0; c < m_channelCount; ++c) { 405 for (int c = 0; c < m_channelCount; ++c) {
381 sv_frame_t i = j * m_channelCount + c; 406 sv_frame_t i = j * m_channelCount + c;
382 float v = buffer[i]; 407 float v = buffer[i];
383 if (!m_normalised) { 408 if (!m_normalised) {