diff audioio/AudioGenerator.cpp @ 436:72c662fe7ea3 cxx11

Further dedicated-types fixes
author Chris Cannam
date Tue, 10 Mar 2015 17:02:52 +0000
parents f747be6743ab
children aa6fb3516e28
line wrap: on
line diff
--- a/audioio/AudioGenerator.cpp	Tue Mar 10 13:22:10 2015 +0000
+++ b/audioio/AudioGenerator.cpp	Tue Mar 10 17:02:52 2015 +0000
@@ -37,7 +37,7 @@
 #include <QDir>
 #include <QFile>
 
-const int
+const sv_frame_t
 AudioGenerator::m_processingBlockSize = 1024;
 
 QString
@@ -220,11 +220,11 @@
                                      m_sourceSampleRate,
                                      m_processingBlockSize);
 
-    float clipF0 = Pitch::getFrequencyForPitch(60, 0, 440.0f); // required
+    double clipF0 = Pitch::getFrequencyForPitch(60, 0, 440.0); // required
 
     QString clipPath = QString("%1/%2.wav").arg(m_sampleDir).arg(clipId);
 
-    float level = wantsQuieterClips(model) ? 0.5 : 1.0;
+    double level = wantsQuieterClips(model) ? 0.5 : 1.0;
     if (!mixer->loadClipData(clipPath, clipF0, level)) {
         delete mixer;
         return 0;
@@ -310,7 +310,7 @@
     }
 }
 
-int
+sv_frame_t
 AudioGenerator::getBlockSize() const
 {
     return m_processingBlockSize;
@@ -334,9 +334,9 @@
     m_soloing = false;
 }
 
-int
-AudioGenerator::mixModel(Model *model, int startFrame, int frameCount,
-			 float **buffer, int fadeIn, int fadeOut)
+sv_frame_t
+AudioGenerator::mixModel(Model *model, sv_frame_t startFrame, sv_frame_t frameCount,
+			 float **buffer, sv_frame_t fadeIn, sv_frame_t fadeOut)
 {
     if (m_sourceSampleRate == 0) {
 	cerr << "WARNING: AudioGenerator::mixModel: No base source sample rate available" << endl;
@@ -393,13 +393,13 @@
     return frameCount;
 }
 
-int
+sv_frame_t
 AudioGenerator::mixDenseTimeValueModel(DenseTimeValueModel *dtvm,
-				       int startFrame, int frames,
+				       sv_frame_t startFrame, sv_frame_t frames,
 				       float **buffer, float gain, float pan,
-				       int fadeIn, int fadeOut)
+				       sv_frame_t fadeIn, sv_frame_t fadeOut)
 {
-    int maxFrames = frames + std::max(fadeIn, fadeOut);
+    sv_frame_t maxFrames = frames + std::max(fadeIn, fadeOut);
 
     int modelChannels = dtvm->getChannelCount();
 
@@ -420,7 +420,7 @@
 	m_channelBufSiz = maxFrames;
     }
 
-    int got = 0;
+    sv_frame_t got = 0;
 
     if (startFrame >= fadeIn/2) {
         got = dtvm->getData(0, modelChannels - 1,
@@ -428,7 +428,7 @@
                             frames + fadeOut/2 + fadeIn/2,
                             m_channelBuffer);
     } else {
-        int missing = fadeIn/2 - startFrame;
+        sv_frame_t missing = fadeIn/2 - startFrame;
 
         for (int c = 0; c < modelChannels; ++c) {
             m_channelBuffer[c] += missing;
@@ -462,25 +462,27 @@
 	float channelGain = gain;
 	if (pan != 0.0) {
 	    if (c == 0) {
-		if (pan > 0.0) channelGain *= 1.0 - pan;
+		if (pan > 0.0) channelGain *= 1.0f - pan;
 	    } else {
-		if (pan < 0.0) channelGain *= pan + 1.0;
+		if (pan < 0.0) channelGain *= pan + 1.0f;
 	    }
 	}
 
-	for (int i = 0; i < fadeIn/2; ++i) {
+	for (sv_frame_t i = 0; i < fadeIn/2; ++i) {
 	    float *back = buffer[c];
 	    back -= fadeIn/2;
-	    back[i] += (channelGain * m_channelBuffer[sourceChannel][i] * i) / fadeIn;
+	    back[i] +=
+                (channelGain * m_channelBuffer[sourceChannel][i] * float(i))
+                / float(fadeIn);
 	}
 
-	for (int i = 0; i < frames + fadeOut/2; ++i) {
+	for (sv_frame_t i = 0; i < frames + fadeOut/2; ++i) {
 	    float mult = channelGain;
 	    if (i < fadeIn/2) {
-		mult = (mult * i) / fadeIn;
+		mult = (mult * float(i)) / float(fadeIn);
 	    }
 	    if (i > frames - fadeOut/2) {
-		mult = (mult * ((frames + fadeOut/2) - i)) / fadeOut;
+		mult = (mult * float((frames + fadeOut/2) - i)) / float(fadeOut);
 	    }
             float val = m_channelBuffer[sourceChannel][i];
             if (i >= got) val = 0.f;
@@ -491,15 +493,15 @@
     return got;
 }
   
-int
+sv_frame_t
 AudioGenerator::mixClipModel(Model *model,
-                             int startFrame, int frames,
+                             sv_frame_t startFrame, sv_frame_t frames,
                              float **buffer, float gain, float pan)
 {
     ClipMixer *clipMixer = m_clipMixerMap[model];
     if (!clipMixer) return 0;
 
-    int blocks = frames / m_processingBlockSize;
+    int blocks = int(frames / m_processingBlockSize);
     
     //!!! todo: the below -- it matters
 
@@ -513,7 +515,7 @@
     //callback play source has to use that as a multiple for all the
     //calls to mixModel
 
-    int got = blocks * m_processingBlockSize;
+    sv_frame_t got = blocks * m_processingBlockSize;
 
 #ifdef DEBUG_AUDIO_GENERATOR
     cout << "mixModel [clip]: frames " << frames
@@ -529,7 +531,7 @@
 
     for (int i = 0; i < blocks; ++i) {
 
-	int reqStart = startFrame + i * m_processingBlockSize;
+	sv_frame_t reqStart = startFrame + i * m_processingBlockSize;
 
         NoteList notes;
         NoteExportable *exportable = dynamic_cast<NoteExportable *>(model);
@@ -544,7 +546,7 @@
 	for (NoteList::const_iterator ni = notes.begin();
              ni != notes.end(); ++ni) {
 
-	    int noteFrame = ni->start;
+	    sv_frame_t noteFrame = ni->start;
 
 	    if (noteFrame < reqStart ||
 		noteFrame >= reqStart + m_processingBlockSize) continue;
@@ -552,7 +554,7 @@
 	    while (noteOffs.begin() != noteOffs.end() &&
 		   noteOffs.begin()->frame <= noteFrame) {
 
-                int eventFrame = noteOffs.begin()->frame;
+                sv_frame_t eventFrame = noteOffs.begin()->frame;
                 if (eventFrame < reqStart) eventFrame = reqStart;
 
                 off.frameOffset = eventFrame - reqStart;
@@ -568,7 +570,7 @@
 
             on.frameOffset = noteFrame - reqStart;
             on.frequency = ni->getFrequency();
-            on.level = float(ni->velocity) / 127.0;
+            on.level = float(ni->velocity) / 127.0f;
             on.pan = pan;
 
 #ifdef DEBUG_AUDIO_GENERATOR
@@ -583,7 +585,7 @@
 	while (noteOffs.begin() != noteOffs.end() &&
 	       noteOffs.begin()->frame <= reqStart + m_processingBlockSize) {
 
-            int eventFrame = noteOffs.begin()->frame;
+            sv_frame_t eventFrame = noteOffs.begin()->frame;
             if (eventFrame < reqStart) eventFrame = reqStart;
 
             off.frameOffset = eventFrame - reqStart;
@@ -609,10 +611,10 @@
     return got;
 }
 
-int
+sv_frame_t
 AudioGenerator::mixContinuousSynthModel(Model *model,
-                                        int startFrame,
-                                        int frames,
+                                        sv_frame_t startFrame,
+                                        sv_frame_t frames,
                                         float **buffer,
                                         float gain, 
                                         float pan)
@@ -624,11 +626,11 @@
     SparseTimeValueModel *stvm = qobject_cast<SparseTimeValueModel *>(model);
     if (stvm->getScaleUnits() != "Hz") return 0;
 
-    int blocks = frames / m_processingBlockSize;
+    int blocks = int(frames / m_processingBlockSize);
 
     //!!! todo: see comment in mixClipModel
 
-    int got = blocks * m_processingBlockSize;
+    sv_frame_t got = blocks * m_processingBlockSize;
 
 #ifdef DEBUG_AUDIO_GENERATOR
     cout << "mixModel [synth]: frames " << frames
@@ -639,7 +641,7 @@
 
     for (int i = 0; i < blocks; ++i) {
 
-	int reqStart = startFrame + i * m_processingBlockSize;
+	sv_frame_t reqStart = startFrame + i * m_processingBlockSize;
 
 	for (int c = 0; c < m_targetChannelCount; ++c) {
             bufferIndexes[c] = buffer[c] + i * m_processingBlockSize;