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

Modified Files:
        ChangePitch.cpp ChangeSpeed.cpp ChangeTempo.cpp Effect.cpp 
        Effect.h Generator.cpp Noise.cpp Noise.h NoiseRemoval.cpp 
        SBSMSEffect.cpp SoundTouchEffect.cpp SoundTouchEffect.h 
Added Files:
        TimeWarper.cpp TimeWarper.h 
Log Message:
Work on the time-alteration behaviour of effects, and associated general and 
scripting improvements.

New files:
src/commands/PreferenceCommands.cpp
src/commands/PreferenceCommands.h
src/commands/SetTrackInfoCommand.cpp
src/commands/SetTrackInfoCommand.h
src/effects/TimeWarper.cpp
src/effects/TimeWarper.h

(Mac & win projects not updated yet)

Introduced 'time warper' objects which describe how an effect changes time when
it is applied. Any effect can have one, but they are only used directly by
Generator, SBSMS, SoundTouch and ChangeSpeed at the moment.

WaveTrack::ClearAndPaste can now use one of these objects to adjust split
points that were in the original audio, which means the effects that use this
method no longer lose the clip structure. (Except for Nyquist). 'Silent' clips
appear where there was white space in the input, because of how these effects
work.

ClearAndPaste also now has a 'useHandlePaste' so that the track-specific
behaviour needed for moving labels can be done inside the method rather than
out. (Otherwise the new whitespace behaviour would only work for the first
tracks in groups).  It's not a particularly pleasant method and this area would
probably benefit from some rethinking after 2.0.

I haven't changed how effects move labels at all, but this could be adapted to
use the new time warpers. I noticed TimeScale moves the labels linearly which
isn't quite right.

I've also been using a script to test the effects, which would otherwise be
quite time consuming. I cleaned up the test script and added a
testClearAndPasters sub which does this test.

Also added some new commands:
SetTrackInfo (only for setting track name currently)
SetPreference and
GetPreference for directly adjusting preferences

Fixed a slight problem with the Select command, where it was incorrectly
reporting what it had selected.

Adjusted Noise generator to read duration preference in an Init method.





Index: ChangeTempo.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/ChangeTempo.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- ChangeTempo.cpp     14 Dec 2008 22:32:44 -0000      1.44
+++ ChangeTempo.cpp     16 Aug 2009 14:44:20 -0000      1.45
@@ -27,6 +27,7 @@
 #include "ChangeTempo.h"
 
 #include "../ShuttleGui.h"
+#include "TimeWarper.h"
 
 #include <math.h>
 
@@ -104,6 +105,8 @@
 {
    mSoundTouch = new SoundTouch();
    mSoundTouch->setTempoChange(m_PercentChange);
+   double mT1Dashed = mT0 + (mT1 - mT0)/(m_PercentChange/100.0 + 1.0);
+   SetTimeWarper(new LinearTimeWarper(mT0, mT0, mT1, mT1Dashed ));
    bool success = this->EffectSoundTouch::Process();
    if( success )
       mT1 = mT0 + (mT1 - mT0)/(m_PercentChange/100 + 1.);

Index: Noise.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/Noise.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- Noise.cpp   25 Mar 2009 04:14:44 -0000      1.37
+++ Noise.cpp   16 Aug 2009 14:44:20 -0000      1.38
@@ -30,6 +30,11 @@
 // EffectNoise
 //
 
+bool EffectNoise::Init()
+{
+   return gPrefs->Read(wxT("/CsPresets/NoiseGen_Duration"), &mDuration, 1L);
+}
+
 bool EffectNoise::PromptUser()
 {
    wxArrayString noiseTypeList;

--- NEW FILE: TimeWarper.h ---
/**********************************************************************

   Audacity - A Digital Audio Editor
   Copyright 1999-2009 Audacity Team
   License: GPL v2 - see LICENSE.txt

   Dan Horgan

******************************************************************//**

\file TimeWarper.h
\brief Contains declarations for TimeWarper, IdentityTimeWarper,
ShiftTimeWarper, LinearTimeWarper, LogarithmicTimeWarper classes

\class TimeWarper
\brief Transforms one point in time to another point. For example, a time
stretching effect might use one to keep track of what happens to labels and
split points in the input.

\class IdentityTimeWarper
\brief No change to time at all

\class ShiftTimeWarper
\brief Behaves like another, given TimeWarper, except shifted by a fixed amount

\class LinearTimeWarper
\brief Linear scaling, initialised by giving two points on the line

\class LogarithmicTimeWarper
\brief TimeScale - rate varies linearly, so time changes logarithmically.

\class StepTimeWarper
\brief Like identity but with a jump

*//*******************************************************************/

#ifndef __TIMEWARPER__
#define __TIMEWARPER__

class TimeWarper
{
public:
   virtual ~TimeWarper() { }
   virtual double Warp(double originalTime) const = 0;
};

class IdentityTimeWarper : public TimeWarper
{
public:
   virtual double Warp(double originalTime) const;
};

class ShiftTimeWarper : public TimeWarper
{
private:
   TimeWarper *mWarper;
   double mShift;
public:
   ShiftTimeWarper(TimeWarper *warper, double shiftAmount)
      : mWarper(warper), mShift(shiftAmount) { }
   virtual ~ShiftTimeWarper()
   { delete mWarper; }
   virtual double Warp(double originalTime) const;
};

class LinearTimeWarper : public TimeWarper
{
private:
   double mScale;
   double mShift;
public:
   LinearTimeWarper(double tBefore0, double tAfter0,
                    double tBefore1, double tAfter1)
      : mScale((tAfter1 - tAfter0)/(tBefore1 - tBefore0)),
        mShift(tAfter0 - mScale*tBefore0)
   { }
   virtual double Warp(double originalTime) const;
};

class LogarithmicTimeWarper : public TimeWarper
{
private:
   LinearTimeWarper mRateWarper;
   double mRStart;
   double mTStart;
   double mScale;
public:
   LogarithmicTimeWarper(double tStart, double tEnd,
                         double rStart, double rEnd);
   virtual double Warp(double originalTime) const;
};

class StepTimeWarper : public TimeWarper
{
private:
   double mTStep;
   double mOffset;
public:
   StepTimeWarper(double tStep, double offset);
   virtual double Warp(double originalTime) const;
};

#endif /* End of include guard: __TIMEWARPER__ */

// Indentation settings for Vim and Emacs and unique identifier for Arch, a
// version control system. Please do not modify past this point.
//
// Local Variables:
// c-basic-offset: 3
// indent-tabs-mode: nil
// End:
//
// vim: et sts=3 sw=3
// arch-tag: TBD

Index: NoiseRemoval.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/NoiseRemoval.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- NoiseRemoval.cpp    25 Jun 2009 02:16:01 -0000      1.62
+++ NoiseRemoval.cpp    16 Aug 2009 14:44:20 -0000      1.63
@@ -681,7 +681,7 @@
       if (bLoopSuccess) {
          // Filtering effects always end up with more data than they started 
with.  Delete this 'tail'.
          mOutputTrack->HandleClear(mT1 - mT0, mOutputTrack->GetEndTime(), 
false, false);
-         track->ClearAndPaste(mT0, mT1, mOutputTrack);
+         track->ClearAndPaste(mT0, mT1, mOutputTrack, true, false);
       }
 
       // Delete the outputTrack now that its data is inserted in place

--- NEW FILE: TimeWarper.cpp ---
/**********************************************************************

   Audacity - A Digital Audio Editor
   Copyright 1999-2009 Audacity Team
   License: GPL v2 - see LICENSE.txt

   Dan Horgan

******************************************************************//**

\file TimeWarper.cpp
\brief Contains definitions for IdentityTimeWarper, ShiftTimeWarper,
LinearTimeWarper, LogarithmicTimeWarper classes

*//*******************************************************************/

#include <wx/string.h>
#include "TimeWarper.h"
#include <math.h>

double IdentityTimeWarper::Warp(double originalTime) const
{
   return originalTime;
}

double ShiftTimeWarper::Warp(double originalTime) const
{
   return mWarper->Warp(originalTime + mShift);
}

double LinearTimeWarper::Warp(double originalTime) const
{
   return originalTime*mScale + mShift;
}

double LogarithmicTimeWarper::Warp(double originalTime) const
{
   double rate = mRateWarper.Warp(originalTime);
   return mTStart + mScale*log(rate/mRStart);
}

LogarithmicTimeWarper::LogarithmicTimeWarper(double tStart, double tEnd,
                                             double rStart, double rEnd)
: mRateWarper(tStart, rStart, tEnd, rEnd), mRStart(rStart),
  mTStart(tStart), mScale((tEnd-tStart)/(rEnd-rStart))
{
   wxASSERT(mRStart != 0.0);
   wxASSERT(tStart < tEnd);
}

StepTimeWarper::StepTimeWarper(double tStep, double offset)
: mTStep(tStep), mOffset(offset)
{ }

double StepTimeWarper::Warp(double originalTime) const
{
   return originalTime + ((originalTime > mTStep) ? mOffset : 0.0);
}

// Indentation settings for Vim and Emacs and unique identifier for Arch, a
// version control system. Please do not modify past this point.
//
// Local Variables:
// c-basic-offset: 3
// indent-tabs-mode: nil
// End:
//
// vim: et sts=3 sw=3
// arch-tag: TBD

Index: Effect.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/Effect.h,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- Effect.h    6 Jul 2009 16:21:53 -0000       1.51
+++ Effect.h    16 Aug 2009 14:44:20 -0000      1.52
@@ -28,6 +28,8 @@
 #include "../Internat.h"
 #include "../widgets/ProgressDialog.h"
 
+class TimeWarper;
+
 #define PLUGIN_EFFECT   0x0001
 #define BUILTIN_EFFECT  0x0002
 // ADVANCED_EFFECT was introduced for Lynn Allan's 'CleanSpeech'
@@ -150,7 +152,7 @@
    Effect();
 
    //The destructor.
-   virtual ~Effect() {}
+   virtual ~Effect();
  
    // Called once each time an effect is called.  Perform any initialization;
    // make sure that the effect can be performed on the selected tracks and
@@ -197,6 +199,7 @@
    TrackList      *mOutputTracks; // used only if CopyInputTracks() is called.
    double         mT0;
    double         mT1;
+   TimeWarper     *mWarper;
 
  //
  // protected methods
@@ -227,6 +230,9 @@
    // Calculates the start time and selection length in samples
    void GetSamples(WaveTrack *track, sampleCount *start, sampleCount *len);
 
+   void SetTimeWarper(TimeWarper *warper);
+   TimeWarper *GetTimeWarper();
+
  //
  // protected static data
  //

Index: ChangeSpeed.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/ChangeSpeed.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- ChangeSpeed.cpp     8 Jul 2009 10:04:15 -0000       1.63
+++ ChangeSpeed.cpp     16 Aug 2009 14:44:20 -0000      1.64
@@ -27,6 +27,7 @@
 #include "../Envelope.h"
 #include "../Prefs.h"
 #include "../Project.h"
+#include "TimeWarper.h"
 
 #include <math.h>
 
@@ -248,12 +249,16 @@
    // Take the output track and insert it in place of the original
    // sample data
        if (bLoopSuccess) {
+
+      double mT1Dashed = mT0 + (mT1 - mT0)/(m_PercentChange/100.0 + 1.0);
+      SetTimeWarper(new LinearTimeWarper(mT0, mT0, mT1, mT1Dashed ));
+      track->ClearAndPaste(mCurT0, mCurT1, outputTrack, true, false, 
mOutputTracks, true, first, GetTimeWarper());
+
+      /*
       if (first)
-                  track->ClearAndPaste(mCurT0, mCurT1, outputTrack, true, 
true, mOutputTracks, true);
-      else {
-         track->HandleClear(mCurT0, mCurT1, false, false);
-         track->HandlePaste(mCurT0, outputTrack);
-      }
+      {
+         first = false;
+      }*/
        }
 
        double newLength = outputTrack->GetEndTime(); 

Index: SBSMSEffect.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/SBSMSEffect.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- SBSMSEffect.cpp     8 Jul 2009 10:04:15 -0000       1.13
+++ SBSMSEffect.cpp     16 Aug 2009 14:44:20 -0000      1.14
@@ -20,6 +20,7 @@
 #include "SBSMSEffect.h"
 #include "../WaveTrack.h"
 #include "../Project.h"
+#include "TimeWarper.h"
 
 class resampleBuf
 {
@@ -254,8 +255,21 @@
             sampleCount samplesToGenerate = (sampleCount) 
((real)samplesToProcess * stretch2);
             sampleCount samplesOut = (sampleCount) ((real)samplesIn * 
stretch2);
             double duration =  (mCurT1-mCurT0) * stretch2;
+
             if(duration > maxDuration)
                maxDuration = duration;
+
+            TimeWarper *warper = NULL;
+            if (mCurT0 == mCurT1)
+            {
+               warper = new LinearTimeWarper(mCurT0, mCurT0,
+                                             mCurT1, mCurT0+maxDuration);
+            } else
+            {
+               warper = new LogarithmicTimeWarper(mCurT0, mCurT1,
+                                                  rateStart, rateEnd);
+            }
+            SetTimeWarper(warper);
             
             sbsmsInfo si;
             si.rs = rb.resampler;
@@ -358,16 +372,10 @@
             if(rightTrack)
                rb.outputRightTrack->Flush();
             
-            if (first)
-               leftTrack->ClearAndPaste(mCurT0, mCurT1, rb.outputLeftTrack, 
true, true, NULL, true);
-            else {
-               leftTrack->HandleClear(mCurT0, mCurT1, false, false);
-               leftTrack->HandlePaste(mCurT0, rb.outputLeftTrack);
-            }
+            leftTrack->ClearAndPaste(mCurT0, mCurT1, rb.outputLeftTrack, true, 
false, NULL, true, first, GetTimeWarper());
 
             if(rightTrack) {
-               rightTrack->HandleClear(mCurT0, mCurT1, false, false);
-               rightTrack->HandlePaste(mCurT0, rb.outputRightTrack);
+               rightTrack->ClearAndPaste(mCurT0, mCurT1, rb.outputRightTrack, 
true, false, NULL, true, false, GetTimeWarper());
             }
 
             first = false;

Index: Effect.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/Effect.cpp,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- Effect.cpp  6 Jul 2009 16:21:53 -0000       1.84
+++ Effect.cpp  16 Aug 2009 14:44:20 -0000      1.85
@@ -39,6 +39,7 @@
 #include "../WaveTrack.h"
 #include "../widgets/ProgressDialog.h"
 #include "../ondemand/ODManager.h"
+#include "TimeWarper.h"
 
 WX_DECLARE_VOIDPTR_HASH_MAP( bool, t2bHash );
 
@@ -62,6 +63,7 @@
 //
 
 Effect::Effect()
+   : mWarper(NULL)
 {
    mTracks = NULL;
    mOutputTracks = NULL;
@@ -75,6 +77,11 @@
    mFlags = BUILTIN_EFFECT | PROCESS_EFFECT | ADVANCED_EFFECT;
 }
 
+Effect::~Effect() {
+   if (mWarper != NULL)
+      delete mWarper;
+}
+
 bool Effect::DoEffect(wxWindow *parent, int flags,
                       double projectRate,
                       TrackList *list,
@@ -203,6 +210,24 @@
    }
 }
 
+void Effect::SetTimeWarper(TimeWarper *warper)
+{
+   if (mWarper != NULL)
+   {
+      delete mWarper;
+      mWarper = NULL;
+   }
+
+   wxASSERT(warper != NULL);
+   mWarper = warper;
+}
+
+TimeWarper *Effect::GetTimeWarper()
+{
+   wxASSERT(mWarper != NULL);
+   return mWarper;
+}
+
 //
 // private methods
 //

Index: SoundTouchEffect.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/SoundTouchEffect.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- SoundTouchEffect.h  6 Jul 2009 16:21:53 -0000       1.8
+++ SoundTouchEffect.h  16 Aug 2009 14:44:20 -0000      1.9
@@ -39,6 +39,8 @@
 
  protected:
    SoundTouch *mSoundTouch;
+   double mCurT0;
+   double mCurT1;
 
  private:
    bool ProcessOne(WaveTrack * t,
@@ -50,8 +52,6 @@
                               WaveTrack* outputRightTrack);
 
    int    mCurTrackNum;
-   double mCurT0;
-   double mCurT1;
 
        double m_maxNewLength;
 };

Index: Generator.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/Generator.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- Generator.cpp       26 Jul 2009 21:03:43 -0000      1.11
+++ Generator.cpp       16 Aug 2009 14:44:20 -0000      1.12
@@ -17,6 +17,7 @@
 #include "../Prefs.h"
 
 #include "Generator.h"
+#include "TimeWarper.h"
 
 bool Generator::Process()
 {
@@ -73,15 +74,13 @@
             else {
                // Transfer the data from the temporary track to the actual one
                tmp->Flush();
+               SetTimeWarper(new StepTimeWarper(mT1, mDuration-mT1));
+               bGoodResult = track->ClearAndPaste(mT0, mT1, tmp, true,
+                     false, mOutputTracks,
+                     false, first, GetTimeWarper());
                if (first) {
-                  bGoodResult = track->ClearAndPaste(mT0, mT1, tmp, true, 
true, mOutputTracks);
                   first = false;
                }
-               else {
-                  bGoodResult = track->HandleClear(mT0, mT1, false, false);
-                  if (bGoodResult)
-                     bGoodResult = track->HandlePaste(mT0, tmp);
-               }
                delete tmp;
             }
 

Index: SoundTouchEffect.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/SoundTouchEffect.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- SoundTouchEffect.cpp        8 Jul 2009 10:04:15 -0000       1.27
+++ SoundTouchEffect.cpp        16 Aug 2009 14:44:20 -0000      1.28
@@ -21,6 +21,7 @@
 #include "SoundTouchEffect.h"
 #include "../WaveTrack.h"
 #include "../Project.h"
+#include "TimeWarper.h"
 
 
 bool EffectSoundTouch::Process()
@@ -202,12 +203,7 @@
    
    // Take the output track and insert it in place of the original
    // sample data
-   if (first)
-      track->ClearAndPaste(mCurT0, mCurT1, outputTrack, true, true, NULL, 
true);
-   else {
-      track->HandleClear(mCurT0, mCurT1, false, false);
-      track->HandlePaste(mCurT0, outputTrack);
-   }
+   track->ClearAndPaste(mCurT0, mCurT1, outputTrack, true, false, NULL, true, 
first, GetTimeWarper());
    
    double newLength = outputTrack->GetEndTime(); 
    m_maxNewLength = wxMax(m_maxNewLength, newLength);
@@ -311,14 +307,8 @@
    
    // Take the output tracks and insert in place of the original
    // sample data.
-   if (first)
-      leftTrack->ClearAndPaste(mCurT0, mCurT1, outputLeftTrack, true, true, 
NULL, true);
-   else {
-      leftTrack->HandleClear(mCurT0, mCurT1, false, false);
-      leftTrack->HandlePaste(mCurT0, outputLeftTrack);
-   }
-   rightTrack->HandleClear(mCurT0, mCurT1, false, false);
-   rightTrack->HandlePaste(mCurT0, outputRightTrack);
+   leftTrack->ClearAndPaste(mCurT0, mCurT1, outputLeftTrack, true, false, 
NULL, true, first, GetTimeWarper());
+   rightTrack->ClearAndPaste(mCurT0, mCurT1, outputRightTrack, true, false, 
NULL, true, false, GetTimeWarper());
 
    // Track the longest result length
    double newLength = outputLeftTrack->GetEndTime();

Index: ChangePitch.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/ChangePitch.cpp,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- ChangePitch.cpp     25 Jun 2009 02:16:01 -0000      1.53
+++ ChangePitch.cpp     16 Aug 2009 14:44:20 -0000      1.54
@@ -21,6 +21,7 @@
 #include "../PitchName.h"
 #include "../Spectrum.h"
 #include "../WaveTrack.h"
+#include "TimeWarper.h"
 
 #include <math.h>
 
@@ -153,6 +154,7 @@
 bool EffectChangePitch::Process()
 {
    mSoundTouch = new SoundTouch();
+   SetTimeWarper(new IdentityTimeWarper());
    mSoundTouch->setPitchSemiTones((float)(m_SemitonesChange));
    return this->EffectSoundTouch::Process();
 }

Index: Noise.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/Noise.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- Noise.h     20 May 2009 06:22:49 -0000      1.18
+++ Noise.h     16 Aug 2009 14:44:20 -0000      1.19
@@ -37,6 +37,7 @@
       noiseType = 0;
       noiseAmplitude = 1.0;
    }
+   virtual bool Init();
 
    virtual wxString GetEffectName() {
       return wxString(_("Noise..."));


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