diff 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
line wrap: on
line diff
--- a/data/fileio/CodedAudioFileReader.cpp	Tue Nov 29 08:58:50 2016 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Tue Nov 29 11:35:56 2016 +0000
@@ -48,6 +48,8 @@
     m_normalised(normalised),
     m_max(0.f),
     m_gain(1.f),
+    m_trimFromStart(0),
+    m_trimFromEnd(0),
     m_clippedCount(0),
     m_firstNonzero(0),
     m_lastNonzero(0)
@@ -94,6 +96,13 @@
 }
 
 void
+CodedAudioFileReader::setSamplesToTrim(sv_frame_t fromStart, sv_frame_t fromEnd)
+{
+    m_trimFromStart = fromStart;
+    m_trimFromEnd = fromEnd;
+}
+
+void
 CodedAudioFileReader::startSerialised(QString id)
 {
     SVDEBUG << "CodedAudioFileReader(" << this << ")::startSerialised: id = " << id << endl;
@@ -223,6 +232,11 @@
     if (!m_initialised) return;
 
     for (sv_frame_t i = 0; i < nframes; ++i) {
+
+        if (m_trimFromStart > 0) {
+            --m_trimFromStart;
+            continue;
+        }
         
         for (int c = 0; c < m_channelCount; ++c) {
 
@@ -253,6 +267,11 @@
     if (!m_initialised) return;
 
     for (sv_frame_t i = 0; i < nframes; ++i) {
+
+        if (m_trimFromStart > 0) {
+            --m_trimFromStart;
+            continue;
+        }
         
         for (int c = 0; c < m_channelCount; ++c) {
 
@@ -283,6 +302,11 @@
     if (!m_initialised) return;
 
     for (float sample: samples) {
+
+        if (m_trimFromStart > 0) {
+            --m_trimFromStart;
+            continue;
+        }
         
         m_cacheWriteBuffer[m_cacheWriteBufferIndex++] = sample;
 
@@ -376,6 +400,7 @@
     float clip = 1.0;
     sv_frame_t count = sz * m_channelCount;
 
+    // statistics
     for (sv_frame_t j = 0; j < sz; ++j) {
         for (int c = 0; c < m_channelCount; ++c) {
             sv_frame_t i = j * m_channelCount + c;