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

Modified Files:
        ChangeSpeed.cpp 
Log Message:
Add more consistent time range comparisons to WaveClip class, and a couple
changes to WaveTrack::ClearAndPaste() to help eliminate zero-length clip
creation in Change Speed and similar effects (much inspired by Vidyashankar's
notes on zero-length clips).

Changes in ChangeSpeed.cpp are mostly just replacing tabs with spaces, but also
fix a recently-introduced bug in parameters to TimeWarper.


Index: ChangeSpeed.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/ChangeSpeed.cpp,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- ChangeSpeed.cpp     4 Nov 2009 23:16:45 -0000       1.65
+++ ChangeSpeed.cpp     19 Nov 2009 05:02:26 -0000      1.66
@@ -44,17 +44,17 @@
 
 EffectChangeSpeed::EffectChangeSpeed()
 {
-       // control values
-       m_PercentChange = 0.0;
-       m_FromVinyl = 0; 
-       m_ToVinyl = 0; 
+   // control values
+   m_PercentChange = 0.0;
+   m_FromVinyl = 0; 
+   m_ToVinyl = 0; 
 }
 
 wxString EffectChangeSpeed::GetEffectDescription() { 
    // Note: This is useful only after change amount has been set. 
    return wxString::Format(_("Applied effect: %s %.1f%%"), 
                            this->GetEffectName().c_str(), 
-                                                                       
m_PercentChange); 
+                           m_PercentChange); 
 } 
 
 bool EffectChangeSpeed::PromptUser()
@@ -63,10 +63,10 @@
    dlog.m_PercentChange = m_PercentChange;
    dlog.m_FromVinyl = m_FromVinyl;
    dlog.m_ToVinyl = m_ToVinyl;
-       // Don't need to call TransferDataToWindow, although other 
-       //      Audacity dialogs (from which I derived this one) do it, because 
-       //      ShowModal calls stuff that eventually calls 
wxWindowBase::OnInitDialog, 
-       //      which calls dlog.TransferDataToWindow();
+   // Don't need to call TransferDataToWindow, although other 
+   // Audacity dialogs (from which I derived this one) do it, because 
+   // ShowModal calls stuff that eventually calls wxWindowBase::OnInitDialog, 
+   // which calls dlog.TransferDataToWindow();
    dlog.CentreOnParent();
    dlog.ShowModal();
 
@@ -87,7 +87,7 @@
 
 bool EffectChangeSpeed::Process()
 {
-       // Similar to EffectSoundTouch::Process()
+   // Similar to EffectSoundTouch::Process()
 
    //Iterate over each track
    //Track::All is needed because this effect needs to introduce silence in 
the group tracks to keep sync
@@ -102,8 +102,8 @@
       return false;
    WaveTrack* pOutWaveTrack = (WaveTrack*)t;
    mCurTrackNum = 0;
-       m_maxNewLength = 0.0;
-       
+   m_maxNewLength = 0.0;
+
    //Get start and end times from track
    mCurT0 = pOutWaveTrack->GetStartTime();
    mCurT1 = pOutWaveTrack->GetEndTime();
@@ -166,12 +166,12 @@
 // ProcessOne() takes a track, transforms it to bunch of buffer-blocks,
 // and calls libsamplerate code on these blocks.
 bool EffectChangeSpeed::ProcessOne(WaveTrack * track,
-                                                                       
sampleCount start, sampleCount end, bool first)
+                           sampleCount start, sampleCount end, bool first)
 {
-       if (track == NULL)
-               return false;
+   if (track == NULL)
+      return false;
 
-       // initialization, per examples of Mixer::Mixer and
+   // initialization, per examples of Mixer::Mixer and
    // EffectSoundTouch::ProcessOne
 
    WaveTrack * outputTrack = mFactory->NewWaveTrack(track->GetSampleFormat(),
@@ -183,24 +183,24 @@
    double len = (double)(end - start);
 
    // Initiate processing buffers, most likely shorter than 
-       //      the length of the selection being processed.
-       sampleCount inBufferSize = track->GetMaxBlockSize();
+   // the length of the selection being processed.
+   sampleCount inBufferSize = track->GetMaxBlockSize();
 
    float * inBuffer = new float[inBufferSize];
 
    double factor = 100.0 / (100.0 + m_PercentChange);
-       sampleCount outBufferSize = 
+   sampleCount outBufferSize = 
       (sampleCount)((factor * inBufferSize) + 10);
    float * outBuffer = new float[outBufferSize]; 
 
-       // Set up the resampling stuff for this track.
+   // Set up the resampling stuff for this track.
    Resample resample(true, factor, factor);
 
    //Go through the track one buffer at a time. samplePos counts which
    //sample the current buffer starts at.
-       bool bLoopSuccess = true;
+   bool bLoopSuccess = true;
    sampleCount blockSize;
-       sampleCount samplePos = start;
+   sampleCount samplePos = start;
    while (samplePos < end) {
       //Get a blockSize of samples (smaller than the size of the buffer)
       blockSize = track->GetBestBlockSize(samplePos);
@@ -221,9 +221,9 @@
                                     outBuffer,
                                     outBufferSize);
       if (outgen < 0) {
-                       bLoopSuccess = false;
-                       break;
-               }
+         bLoopSuccess = false;
+         break;
+      }
 
       if (outgen > 0)
          outputTrack->Append((samplePtr)outBuffer, floatSample, 
@@ -234,13 +234,13 @@
 
       // Update the Progress meter
       if (TrackProgress(mCurTrackNum, (samplePos - start) / len)) {
-                       bLoopSuccess = false;
-                       break;
-               }
+         bLoopSuccess = false;
+         break;
+      }
    }
 
-       // Flush the output WaveTrack (since it's buffered, too)
-       outputTrack->Flush();
+   // Flush the output WaveTrack (since it's buffered, too)
+   outputTrack->Flush();
 
    // Clean up the buffers
    delete [] inBuffer;
@@ -248,14 +248,14 @@
 
    // Take the output track and insert it in place of the original
    // sample data
-       double newLength = outputTrack->GetEndTime(); 
-       if (bLoopSuccess) {
-      SetTimeWarper(new LinearTimeWarper(mT0, mT0, mT1, newLength ));
+   double newLength = outputTrack->GetEndTime(); 
+   if (bLoopSuccess) {
+      SetTimeWarper(new LinearTimeWarper(mCurT0, mCurT0, mCurT1, mCurT0 + 
newLength ));
       track->ClearAndPaste(mCurT0, mCurT1, outputTrack, true, false, 
mOutputTracks, true, first, GetTimeWarper());
-       }
+   }
 
-       if (newLength > m_maxNewLength) 
-               m_maxNewLength = newLength; 
+   if (newLength > m_maxNewLength) 
+      m_maxNewLength = newLength; 
 
    // Delete the outputTrack now that its data is inserted in place
    delete outputTrack;
@@ -306,18 +306,18 @@
 {
    m_bLoopDetect = false;
 
-       // NULL out these control members because there are some cases where 
the 
-       // event table handlers get called during this method, and those 
handlers that 
-       // can cause trouble check for NULL.
+   // NULL out these control members because there are some cases where the 
+   // event table handlers get called during this method, and those handlers 
that 
+   // can cause trouble check for NULL.
    m_pTextCtrl_PercentChange = NULL;
    m_pSlider_PercentChange = NULL;
    m_pChoice_FromVinyl = NULL;
    m_pChoice_ToVinyl = NULL;
-       
-       // effect parameters
-       m_PercentChange = 0.0;
-       m_FromVinyl = 0; 
-       m_ToVinyl = 0; 
+
+   // effect parameters
+   m_PercentChange = 0.0;
+   m_FromVinyl = 0; 
+   m_ToVinyl = 0; 
 
    Init();
 }
@@ -390,44 +390,44 @@
 {
    m_bLoopDetect = true;
 
-       // percent change controls
-       this->Update_Text_PercentChange();
-       this->Update_Slider_PercentChange();
+   // percent change controls
+   this->Update_Text_PercentChange();
+   this->Update_Slider_PercentChange();
 
-       // from/to Vinyl controls
-       if (m_pChoice_FromVinyl) 
-               m_pChoice_FromVinyl->SetSelection(m_FromVinyl);
+   // from/to Vinyl controls
+   if (m_pChoice_FromVinyl) 
+      m_pChoice_FromVinyl->SetSelection(m_FromVinyl);
 
-       if (m_pChoice_ToVinyl) 
-               m_pChoice_ToVinyl->SetSelection(m_ToVinyl);
+   if (m_pChoice_ToVinyl) 
+      m_pChoice_ToVinyl->SetSelection(m_ToVinyl);
 
-       m_bLoopDetect = false;
+   m_bLoopDetect = false;
 
-       return true;
+   return true;
 }
 
 bool ChangeSpeedDialog::TransferDataFromWindow()
 {
-       wxString str;
+   wxString str;
 
-       // percent change controls
+   // percent change controls
    if (m_pTextCtrl_PercentChange) {
       double newValue = 0;
       str = m_pTextCtrl_PercentChange->GetValue();
       str.ToDouble(&newValue);
-               m_PercentChange = newValue;
-       }
+      m_PercentChange = newValue;
+   }
 
-       // Ignore Slider_PercentChange because TextCtrl_PercentChange 
-       // always tracks it & is more precise (decimal points).
+   // Ignore Slider_PercentChange because TextCtrl_PercentChange 
+   // always tracks it & is more precise (decimal points).
 
 
-       // from/to Vinyl controls
-       if (m_pChoice_FromVinyl) 
-               m_FromVinyl = m_pChoice_FromVinyl->GetSelection();
+   // from/to Vinyl controls
+   if (m_pChoice_FromVinyl) 
+      m_FromVinyl = m_pChoice_FromVinyl->GetSelection();
 
-       if (m_pChoice_ToVinyl) 
-               m_ToVinyl = m_pChoice_ToVinyl->GetSelection();
+   if (m_pChoice_ToVinyl) 
+      m_ToVinyl = m_pChoice_ToVinyl->GetSelection();
 
    return true;
 }
@@ -443,11 +443,11 @@
       double newValue = 0;
       wxString str = m_pTextCtrl_PercentChange->GetValue();
       str.ToDouble(&newValue);
-               m_PercentChange = newValue;
+      m_PercentChange = newValue;
 
       m_bLoopDetect = true;
-               this->Update_Slider_PercentChange();
-               this->Update_Vinyl();
+      this->Update_Slider_PercentChange();
+      this->Update_Vinyl();
       m_bLoopDetect = false;
 
       FindWindow(wxID_OK)->Enable(m_PercentChange > -100.0);
@@ -459,17 +459,17 @@
    if (m_bLoopDetect)
       return;
 
-       if (m_pSlider_PercentChange) {
-               m_PercentChange = 
(double)(m_pSlider_PercentChange->GetValue()); 
-               // Warp positive values to actually go up faster & further than 
negatives.
-               if (m_PercentChange > 0.0)
-                       m_PercentChange = pow(m_PercentChange, 
PERCENTCHANGE_SLIDER_WARP);
+   if (m_pSlider_PercentChange) {
+      m_PercentChange = (double)(m_pSlider_PercentChange->GetValue()); 
+      // Warp positive values to actually go up faster & further than 
negatives.
+      if (m_PercentChange > 0.0)
+         m_PercentChange = pow(m_PercentChange, PERCENTCHANGE_SLIDER_WARP);
 
-          m_bLoopDetect = true;
-               this->Update_Text_PercentChange();
-               this->Update_Vinyl();
-          m_bLoopDetect = false;
-       }
+      m_bLoopDetect = true;
+      this->Update_Text_PercentChange();
+      this->Update_Vinyl();
+      m_bLoopDetect = false;
+   }
 }
 
 void ChangeSpeedDialog::OnChoice_FromVinyl(wxCommandEvent & event)
@@ -477,11 +477,11 @@
    if (m_bLoopDetect)
       return;
 
-       if (m_pChoice_FromVinyl) {
-               m_FromVinyl = m_pChoice_FromVinyl->GetSelection();
+   if (m_pChoice_FromVinyl) {
+      m_FromVinyl = m_pChoice_FromVinyl->GetSelection();
 
       m_bLoopDetect = true;
-               this->Update_PercentChange();
+      this->Update_PercentChange();
       m_bLoopDetect = false;
    }
 }
@@ -491,11 +491,11 @@
    if (m_bLoopDetect)
       return;
 
-       if (m_pChoice_ToVinyl) {
-               m_ToVinyl = m_pChoice_ToVinyl->GetSelection();
+   if (m_pChoice_ToVinyl) {
+      m_ToVinyl = m_pChoice_ToVinyl->GetSelection();
 
       m_bLoopDetect = true;
-               this->Update_PercentChange();
+      this->Update_PercentChange();
       m_bLoopDetect = false;
    }
 }
@@ -504,8 +504,8 @@
 {
    TransferDataFromWindow();
 
-       // Save & restore parameters around Preview, because we didn't do OK.
-       double oldPercentChange = mEffect->m_PercentChange;
+   // Save & restore parameters around Preview, because we didn't do OK.
+   double oldPercentChange = mEffect->m_PercentChange;
    if( m_PercentChange < -99.0)
    {
       m_PercentChange = -99.0;
@@ -520,64 +520,64 @@
 
 void ChangeSpeedDialog::Update_Text_PercentChange()
 {
-       if (m_pTextCtrl_PercentChange) {
-               wxString str;
-               str.Printf(wxT("%.3f"), m_PercentChange);
-               m_pTextCtrl_PercentChange->SetValue(str);
+   if (m_pTextCtrl_PercentChange) {
+      wxString str;
+      str.Printf(wxT("%.3f"), m_PercentChange);
+      m_pTextCtrl_PercentChange->SetValue(str);
       FindWindow(wxID_OK)->Enable(m_PercentChange > -100.0);
-       }
+   }
 }
 
 void ChangeSpeedDialog::Update_Slider_PercentChange()
 {
    if (m_pSlider_PercentChange) {
-               double unwarped = m_PercentChange;
-               if (unwarped > 0.0)
-                       // Un-warp values above zero to actually go up to 
PERCENTCHANGE_MAX.
-                       unwarped = pow(m_PercentChange, (1.0 / 
PERCENTCHANGE_SLIDER_WARP));
-               
-               // Add 0.5 to unwarped so trunc -> round.
-               m_pSlider_PercentChange->SetValue((int)(unwarped + 0.5)); 
-       }
+      double unwarped = m_PercentChange;
+      if (unwarped > 0.0)
+         // Un-warp values above zero to actually go up to PERCENTCHANGE_MAX.
+         unwarped = pow(m_PercentChange, (1.0 / PERCENTCHANGE_SLIDER_WARP));
+
+      // Add 0.5 to unwarped so trunc -> round.
+      m_pSlider_PercentChange->SetValue((int)(unwarped + 0.5)); 
+   }
 }
 
 void ChangeSpeedDialog::Update_Vinyl() 
 // Update Vinyl controls for new percent change.
 {
-       if (m_pChoice_ToVinyl) {
-               // Chances are so low that the slider will exactly match a 
-               // standard ratio, just turn it "n/a" unless it's 0.0.
-               if ((m_PercentChange == 0.0) && m_pChoice_FromVinyl)
-                       
m_pChoice_ToVinyl->SetSelection(m_pChoice_FromVinyl->GetSelection());
-               else
-                       m_pChoice_ToVinyl->SetSelection(CHOICE_NA);
+   if (m_pChoice_ToVinyl) {
+      // Chances are so low that the slider will exactly match a 
+      // standard ratio, just turn it "n/a" unless it's 0.0.
+      if ((m_PercentChange == 0.0) && m_pChoice_FromVinyl)
+         m_pChoice_ToVinyl->SetSelection(m_pChoice_FromVinyl->GetSelection());
+      else
+         m_pChoice_ToVinyl->SetSelection(CHOICE_NA);
         }
 }
 
 void ChangeSpeedDialog::Update_PercentChange() 
 // Update percent change controls for new Vinyl values.
 {
-       // If m_FromVinyl & m_ToVinyl are set, then there's a new percent 
change.
-       if ((m_FromVinyl != CHOICE_NA) && (m_ToVinyl != CHOICE_NA)) {
-               double fromRPM;
-               double toRPM;
-               switch (m_FromVinyl) {
+   // If m_FromVinyl & m_ToVinyl are set, then there's a new percent change.
+   if ((m_FromVinyl != CHOICE_NA) && (m_ToVinyl != CHOICE_NA)) {
+      double fromRPM;
+      double toRPM;
+      switch (m_FromVinyl) {
       default:
-               case CHOICE_33ANDATHIRD:        fromRPM = 33.0 + (1.0 / 3.0); 
break;
-               case CHOICE_45:                         fromRPM = 45.0; break;
-               case CHOICE_78:                         fromRPM = 78; break;
-               }
-               switch (m_ToVinyl) {
+      case CHOICE_33ANDATHIRD:   fromRPM = 33.0 + (1.0 / 3.0); break;
+      case CHOICE_45:            fromRPM = 45.0; break;
+      case CHOICE_78:            fromRPM = 78; break;
+      }
+      switch (m_ToVinyl) {
       default:
-               case CHOICE_33ANDATHIRD:        toRPM = 33.0 + (1.0 / 3.0); 
break;
-               case CHOICE_45:                         toRPM = 45.0; break;
-               case CHOICE_78:                         toRPM = 78; break;
-               }
-               m_PercentChange = ((toRPM * 100.0) / fromRPM) - 100.0;
+      case CHOICE_33ANDATHIRD:   toRPM = 33.0 + (1.0 / 3.0); break;
+      case CHOICE_45:            toRPM = 45.0; break;
+      case CHOICE_78:            toRPM = 78; break;
+      }
+      m_PercentChange = ((toRPM * 100.0) / fromRPM) - 100.0;
 
-               this->Update_Text_PercentChange();
-               this->Update_Slider_PercentChange();
-       }
+      this->Update_Text_PercentChange();
+      this->Update_Slider_PercentChange();
+   }
 }
 
 // Indentation settings for Vim and Emacs and unique identifier for Arch, a


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