diff audioio/AudioGenerator.cpp @ 460:49c89950b06d simple-fft-model

Rework audio file reader API to prefer using std containers
author Chris Cannam
date Mon, 15 Jun 2015 12:19:47 +0100
parents 3485d324c172
children 1020db1698c0
line wrap: on
line diff
--- a/audioio/AudioGenerator.cpp	Fri Jun 12 14:51:46 2015 +0100
+++ b/audioio/AudioGenerator.cpp	Mon Jun 15 12:19:47 2015 +0100
@@ -439,17 +439,20 @@
     sv_frame_t got = 0;
 
     if (startFrame >= fadeIn/2) {
-        got = dtvm->getMultiChannelData(0, modelChannels - 1,
-                                        startFrame - fadeIn/2,
-                                        frames + fadeOut/2 + fadeIn/2,
-                                        m_channelBuffer);
+
+        auto data = dtvm->getMultiChannelData(0, modelChannels - 1,
+                                              startFrame - fadeIn/2,
+                                              frames + fadeOut/2 + fadeIn/2);
+
+        for (int c = 0; c < modelChannels; ++c) {
+            copy(data[c].begin(), data[c].end(), m_channelBuffer[c]);
+        }
+
+        got = data.size();
+
     } else {
         sv_frame_t missing = fadeIn/2 - startFrame;
 
-        for (int c = 0; c < modelChannels; ++c) {
-            m_channelBuffer[c] += missing;
-        }
-
         if (missing > 0) {
             cerr << "note: channelBufSiz = " << m_channelBufSiz
                  << ", frames + fadeOut/2 = " << frames + fadeOut/2 
@@ -457,16 +460,14 @@
                  << ", missing = " << missing << endl;
         }
 
-        got = dtvm->getMultiChannelData(0, modelChannels - 1,
-                                        startFrame,
-                                        frames + fadeOut/2,
-                                        m_channelBuffer);
-
+        auto data = dtvm->getMultiChannelData(0, modelChannels - 1,
+                                              startFrame,
+                                              frames + fadeOut/2);
         for (int c = 0; c < modelChannels; ++c) {
-            m_channelBuffer[c] -= missing;
+            copy(data[c].begin(), data[c].end(), m_channelBuffer[c] + missing);
         }
 
-        got += missing;
+        got = data.size() + missing;
     }	    
 
     for (int c = 0; c < m_targetChannelCount; ++c) {