Update of /cvsroot/audacity/audacity-src/src
In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv17352/src

Modified Files:
        AudioIO.cpp 
Log Message:
Fix for P3: Audacity output slider may affect playback meters


Index: AudioIO.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/AudioIO.cpp,v
retrieving revision 1.236
retrieving revision 1.237
diff -u -d -r1.236 -r1.237
--- AudioIO.cpp 22 Nov 2009 12:46:11 -0000      1.236
+++ AudioIO.cpp 23 Nov 2009 19:51:56 -0000      1.237
@@ -2903,6 +2903,14 @@
                              MAX(numCaptureChannels,numPlaybackChannels));
    float *tempFloats = (float*)tempBuffer;
 
+   // output meter may need samples untouched by volume emulation
+   float *outputMeterFloats;
+   outputMeterFloats =
+      (outputBuffer && gAudioIO->mEmulateMixerOutputVol &&
+                       gAudioIO->mMixerOutputVol != 1.0) ?
+         (float *)alloca(framesPerBuffer*numPlaybackChannels * sizeof(float)) :
+         (float *)outputBuffer;
+
 #ifdef EXPERIMENTAL_MIDI_OUT
    /* GSW: Save timeInfo in case MidiPlayback needs it */
    gAudioIO->mAudioCallbackOutputTime = timeInfo->outputBufferDacTime;
@@ -3002,6 +3010,13 @@
                                   (float *)outputBuffer, (int)framesPerBuffer, 
1.0f);
          }
 
+         // Copy the results to outputMeterFloats if necessary
+         if (outputMeterFloats != outputFloats) {
+            for (i = 0; i < framesPerBuffer*numPlaybackChannels; ++i) {
+               outputMeterFloats[i] = outputFloats[i];
+            }
+         }
+
          if (gAudioIO->mSeek)
          {
             // Pause audio thread and wait for it to finish
@@ -3090,6 +3105,13 @@
                 vt->GetChannel() == Track::MonoChannel)
             {
                float gain = vt->GetChannelGain(0);
+
+               // Output volume emulation: possibly copy meter samples, then
+               // apply volume, then copy to the output buffer
+               if (outputMeterFloats != outputFloats)
+                  for (i = 0; i < len; ++i)
+                     outputMeterFloats[numPlaybackChannels*i] +=
+                        gain*tempFloats[i];
                
                if (gAudioIO->mEmulateMixerOutputVol)
                   gain *= gAudioIO->mMixerOutputVol;
@@ -3103,6 +3125,12 @@
             {
                float gain = vt->GetChannelGain(1);
                
+               // Output volume emulation (as above)
+               if (outputMeterFloats != outputFloats)
+                  for (i = 0; i < len; ++i)
+                     outputMeterFloats[numPlaybackChannels*i+1] +=
+                        gain*tempFloats[i];
+
                if (gAudioIO->mEmulateMixerOutputVol)
                   gain *= gAudioIO->mMixerOutputVol;
                
@@ -3122,6 +3150,19 @@
             else if (f < -1.0)
                outputFloats[i] = -1.0;
          }
+
+         // Same for meter output
+         if (outputMeterFloats != outputFloats)
+         {
+            for (i = 0; i < framesPerBuffer*numPlaybackChannels; ++i)
+            {
+               float f = outputMeterFloats[i];
+               if (f > 1.0)
+                  outputMeterFloats[i] = 1.0;
+               else if (f < -1.0)
+                  outputMeterFloats[i] = -1.0;
+            }
+         }
       }
 
       //
@@ -3252,12 +3293,20 @@
                                   numCaptureChannels,
                                   (float *)outputBuffer, (int)framesPerBuffer, 
1.0f);
          }
+
+         // Copy the results to outputMeterFloats if necessary
+         if (outputMeterFloats != outputFloats) {
+            for (i = 0; i < framesPerBuffer*numPlaybackChannels; ++i) {
+               outputMeterFloats[i] = outputFloats[i];
+            }
+         }
       }
+
    }
    /* Send data to playback VU meter if applicable */
    if (gAudioIO->mOutputMeter && 
       !gAudioIO->mOutputMeter->IsMeterDisabled() &&
-      outputBuffer) {
+      outputMeterFloats) {
       // Get here if playback meter is live 
       /* It's critical that we don't update the meters while StopStream is
        * trying to stop PortAudio, otherwise it can lead to a freeze.  We use
@@ -3272,7 +3321,7 @@
       if (gAudioIO->mUpdateMeters) {
          gAudioIO->mOutputMeter->UpdateDisplay(numPlaybackChannels,
                                                framesPerBuffer,
-                                               (float *)outputBuffer);
+                                               outputMeterFloats);
       }
       gAudioIO->mUpdatingMeters = false;
    }  // end playback VU meter update


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Audacity-cvs mailing list
Audacity-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to