Update of /cvsroot/audacity/audacity-src/src
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5235/src

Modified Files:
        AudioIO.cpp AudioIO.h 
Log Message:
Remove emulated input volume control because it's never actually useful, only 
confuses people because they change the control and it doesn't fix clipping, 
just make it quieter



Index: AudioIO.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/AudioIO.cpp,v
retrieving revision 1.234
retrieving revision 1.235
diff -u -d -r1.234 -r1.235
--- AudioIO.cpp 20 Nov 2009 01:54:47 -0000      1.234
+++ AudioIO.cpp 21 Nov 2009 22:16:36 -0000      1.235
@@ -331,8 +331,7 @@
 #else
    mEmulateMixerOutputVol = true;
    mMixerOutputVol = 1.0;
-   mEmulateMixerInputVol = true;
-   mMixerInputVol = 1.0;
+   mInputMixerWorks = false;
 #endif
 }
 
@@ -371,7 +370,6 @@
                        float playbackVolume)
 {
    mMixerOutputVol = playbackVolume;
-   mMixerInputVol = recordVolume;
 
 #if defined(USE_PORTMIXER)
    PxMixer *mixer = mPortMixer;
@@ -405,10 +403,10 @@
    {
       *recordDevice = Px_GetCurrentInputSource(mixer);
 
-      if (mEmulateMixerInputVol)
-         *recordVolume = mMixerInputVol;
-      else
+      if (mInputMixerWorks)
          *recordVolume = Px_GetInputVolume(mixer);
+      else
+         *recordVolume = 1.0f;
 
       if (mEmulateMixerOutputVol)
          *playbackVolume = mMixerOutputVol;
@@ -421,10 +419,15 @@
 #endif
 
    *recordDevice = 0;
-   *recordVolume = mMixerInputVol;
+   *recordVolume = 1.0f;
    *playbackVolume = mMixerOutputVol;
 }
 
+bool AudioIO::InputMixerWorks()
+{
+   return mInputMixerWorks;
+}
+
 wxArrayString AudioIO::GetInputSourceNames()
 {
 #if defined(USE_PORTMIXER)
@@ -502,9 +505,8 @@
       // mCachedSampleRates is still empty, but it's not used again, so
       // can ignore
    }
-   mEmulateMixerInputVol = true;
+   mInputMixerWorks = false;
    mEmulateMixerOutputVol = true;
-   mMixerInputVol = 1.0;
    mMixerOutputVol = 1.0;
 
    int error;
@@ -575,9 +577,9 @@
    if( error )
       return;
 
-   // Determine mixer capabilities - if it doesn't support either
-   // input or output, we emulate them (by multiplying this value
-   // by all incoming/outgoing samples)
+   // Determine mixer capabilities - if it doesn't support control of output
+   // signal level, we emulate it (by multiplying this value by all outgoing
+   // samples)
 
    mMixerOutputVol = Px_GetPCMOutputVolume(mPortMixer);
    mEmulateMixerOutputVol = false;
@@ -590,26 +592,25 @@
       mEmulateMixerOutputVol = true;
    Px_SetPCMOutputVolume(mPortMixer, mMixerOutputVol);
 
-   mMixerInputVol = Px_GetInputVolume(mPortMixer);
-   mEmulateMixerInputVol = false;
+   float inputVol = Px_GetInputVolume(mPortMixer);
+   mInputMixerWorks = true;   // assume it works unless proved wrong
    Px_SetInputVolume(mPortMixer, 0.0);
    if (Px_GetInputVolume(mPortMixer) > 0.1)
-      mEmulateMixerInputVol = true;
+      mInputMixerWorks = false;  // can't set to zero
    Px_SetInputVolume(mPortMixer, 0.2f);
    if (Px_GetInputVolume(mPortMixer) < 0.1 ||
        Px_GetInputVolume(mPortMixer) > 0.3)
-      mEmulateMixerInputVol = true;
-   Px_SetInputVolume(mPortMixer, mMixerInputVol);
+      mInputMixerWorks = false;  // can't set level accurately
+   Px_SetInputVolume(mPortMixer, inputVol);
 
    Pa_CloseStream(stream);
 
    #if 0
    printf("PortMixer: Output: %s Input: %s\n",
           mEmulateMixerOutputVol? "emulated": "native",
-          mEmulateMixerInputVol? "emulated": "native");
+          mInputMixerWorks? "hardware": "no control");
    #endif
 
-   mMixerInputVol = 1.0;
    mMixerOutputVol = 1.0;
 
 #endif   // USE_PORTMIXER
@@ -2971,13 +2972,9 @@
                       0, framesPerBuffer * numPlaybackChannels);
 
          if (inputBuffer && gAudioIO->mSoftwarePlaythrough) {
-            float gain = 1.0;
-            if (gAudioIO->mEmulateMixerInputVol)
-               gain = gAudioIO->mMixerInputVol;
-
             DoSoftwarePlaythrough(inputBuffer, gAudioIO->mCaptureFormat,
                                   numCaptureChannels,
-                                  (float *)outputBuffer, (int)framesPerBuffer, 
gain);
+                                  (float *)outputBuffer, (int)framesPerBuffer, 
1.0f);
          }
       }
 
@@ -3000,13 +2997,9 @@
             outputFloats[i] = 0.0;
 
          if (inputBuffer && gAudioIO->mSoftwarePlaythrough) {
-            float gain = 1.0;
-            if (gAudioIO->mEmulateMixerInputVol)
-               gain = gAudioIO->mMixerInputVol;
-
             DoSoftwarePlaythrough(inputBuffer, gAudioIO->mCaptureFormat,
                                   numCaptureChannels,
-                                  (float *)outputBuffer, (int)framesPerBuffer, 
gain);
+                                  (float *)outputBuffer, (int)framesPerBuffer, 
1.0f);
          }
 
          if (gAudioIO->mSeek)
@@ -3151,11 +3144,6 @@
             wxPrintf(wxT("lost %d samples\n"), (int)(framesPerBuffer - len));
          }
 
-         float gain = 1.0;
-         
-         if (gAudioIO->mEmulateMixerInputVol)
-            gain = gAudioIO->mMixerInputVol;
-
          if (len > 0) {
             for( t = 0; t < numCaptureChannels; t++) {
                
@@ -3170,7 +3158,7 @@
                   float *inputFloats = (float *)inputBuffer;
                   for( i = 0; i < len; i++)
                      tempFloats[i] =
-                        inputFloats[numCaptureChannels*i+t] * gain;
+                        inputFloats[numCaptureChannels*i+t];
                } break;
                case int24Sample:
                   // We should never get here. Audacity's int24Sample format
@@ -3183,7 +3171,7 @@
                   short *inputShorts = (short *)inputBuffer;
                   short *tempShorts = (short *)tempBuffer;
                   for( i = 0; i < len; i++) {
-                     float tmp = inputShorts[numCaptureChannels*i+t] * gain;
+                     float tmp = inputShorts[numCaptureChannels*i+t];
                      if (tmp > 32767)
                         tmp = 32767;
                      if (tmp < -32768)
@@ -3260,13 +3248,9 @@
             outputFloats[i] = 0.0;
          
          if (inputBuffer && gAudioIO->mSoftwarePlaythrough) {
-            float gain = 1.0;
-            if (gAudioIO->mEmulateMixerInputVol)
-               gain = gAudioIO->mMixerInputVol;
-            
             DoSoftwarePlaythrough(inputBuffer, gAudioIO->mCaptureFormat,
                                   numCaptureChannels,
-                                  (float *)outputBuffer, (int)framesPerBuffer, 
gain);
+                                  (float *)outputBuffer, (int)framesPerBuffer, 
1.0f);
          }
       }
    }

Index: AudioIO.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/AudioIO.h,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- AudioIO.h   8 Nov 2009 05:18:41 -0000       1.81
+++ AudioIO.h   21 Nov 2009 22:16:36 -0000      1.82
@@ -159,13 +159,20 @@
    /* Mixer services are always available.  If no stream is running, these
     * methods use whatever device is specified by the preferences.  If a
     * stream *is* running, naturally they manipulate the mixer associated
-    * with that stream.  If no mixer is available, they are emulated
-    * (a gain is applied to input and output samples).
+    * with that stream.  If no mixer is available, output is emulated and 
+    * input is stuck at 1.0f (a gain is applied to output samples).
     */
    void SetMixer(int inputSource, float inputVolume,
                  float playbackVolume);
    void GetMixer(int *inputSource, float *inputVolume,
                  float *playbackVolume);
+   /** @brief Find out if the input hardware level control is available
+    *
+    * Checks the mInputMixerWorks variable, which is set up in
+    * AudioIO::HandleDeviceChange(). External people care, because we want to
+    * disable the UI if it doesn't work.
+    */
+   bool InputMixerWorks();
    /** \brief Get the list of inputs to the current mixer device
     *
     * Returns an array of strings giving the names of the inputs to the 
@@ -481,9 +488,15 @@
    #endif /* USE_PORTMIXER */
 
    bool                mEmulateMixerOutputVol;
-   bool                mEmulateMixerInputVol;
+   /** @brief Can we control the hardware input level?
+    *
+    * This flag is set to true if using portmixer to control the 
+    * input volume seems to be working (and so we offer the user the control),
+    * and to false (locking the control out) otherwise. This avoids stupid
+    * scaled clipping problems when trying to do software emulated input volume
+    * control */
+   bool                mInputMixerWorks;
    float               mMixerOutputVol;
-   float               mMixerInputVol;
 
    bool                mPlayLooped;
    double              mCutPreviewGapStart;


------------------------------------------------------------------------------
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