Audacity  3.0.3
TimeWarper.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity - A Digital Audio Editor
4  Copyright 1999-2009 Audacity Team
5  License: GPL v2 - see LICENSE.txt
6 
7  Dan Horgan
8 
9 ******************************************************************//*******************************************************************/
55 
56 #ifndef __TIMEWARPER__
57 #define __TIMEWARPER__
58 
59 #include <memory>
60 
61 class AUDACITY_DLL_API TimeWarper /* not final */
62 {
63 public:
64  virtual ~TimeWarper();
65  virtual double Warp(double originalTime) const = 0;
66 };
67 
68 class AUDACITY_DLL_API IdentityTimeWarper final : public TimeWarper
69 {
70 public:
71  double Warp(double originalTime) const override;
72 };
73 
74 class AUDACITY_DLL_API ShiftTimeWarper final : public TimeWarper
75 {
76 private:
77  std::unique_ptr<TimeWarper> mWarper;
78  double mShift;
79 public:
80  ShiftTimeWarper(std::unique_ptr<TimeWarper> &&warper, double shiftAmount)
81  : mWarper(std::move(warper)), mShift(shiftAmount) { }
82  virtual ~ShiftTimeWarper() {}
83  double Warp(double originalTime) const override;
84 };
85 
86 class AUDACITY_DLL_API LinearTimeWarper final : public TimeWarper
87 {
88 private:
89  double mScale;
90  double mShift;
91 public:
92  LinearTimeWarper(double tBefore0, double tAfter0,
93  double tBefore1, double tAfter1)
94  : mScale((tAfter1 - tAfter0)/(tBefore1 - tBefore0)),
95  mShift(tAfter0 - mScale*tBefore0)
96  { }
97  double Warp(double originalTime) const override;
98 };
99 
100 class AUDACITY_DLL_API LinearInputRateTimeWarper final : public TimeWarper
101 {
102 private:
104  double mRStart;
105  double mTStart;
106  double mScale;
107 public:
108  LinearInputRateTimeWarper(double tStart, double tEnd,
109  double rStart, double rEnd);
110  double Warp(double originalTime) const override;
111 };
112 
113 class AUDACITY_DLL_API LinearOutputRateTimeWarper final : public TimeWarper
114 {
115 private:
117  double mRStart;
118  double mTStart;
119  double mScale;
120  double mC1;
121  double mC2;
122 public:
123  LinearOutputRateTimeWarper(double tStart, double tEnd,
124  double rStart, double rEnd);
125  double Warp(double originalTime) const override;
126 };
127 
128 class AUDACITY_DLL_API LinearInputStretchTimeWarper final : public TimeWarper
129 {
130 private:
132  double mTStart;
133  double mC1;
134  double mC2;
135 public:
136  LinearInputStretchTimeWarper(double tStart, double tEnd,
137  double rStart, double rEnd);
138  double Warp(double originalTime) const override;
139 };
140 
141 class AUDACITY_DLL_API LinearOutputStretchTimeWarper final : public TimeWarper
142 {
143 private:
145  double mTStart;
146  double mC1;
147  double mC2;
148 public:
149  LinearOutputStretchTimeWarper(double tStart, double tEnd,
150  double rStart, double rEnd);
151  double Warp(double originalTime) const override;
152 };
153 
154 class AUDACITY_DLL_API GeometricInputTimeWarper final : public TimeWarper
155 {
156 private:
158  double mTStart;
159  double mScale;
160  double mRatio;
161 public:
162  GeometricInputTimeWarper(double tStart, double tEnd,
163  double rStart, double rEnd);
164  double Warp(double originalTime) const override;
165 };
166 
167 class AUDACITY_DLL_API GeometricOutputTimeWarper final : public TimeWarper
168 {
169 private:
171  double mTStart;
172  double mScale;
173  double mC0;
174 public:
175  GeometricOutputTimeWarper(double tStart, double tEnd,
176  double rStart, double rEnd);
177  double Warp(double originalTime) const override;
178 };
179 
180 class AUDACITY_DLL_API PasteTimeWarper final : public TimeWarper
181 {
182 private:
183  const double mOldT1, mNewT1;
184 public:
185  PasteTimeWarper(double oldT1, double newT1);
186  double Warp(double originalTime) const override;
187 };
188 
189 
190 // Note: this assumes that tStart is a fixed point of warper->warp()
191 class AUDACITY_DLL_API RegionTimeWarper final : public TimeWarper
192 {
193 private:
194  std::unique_ptr<TimeWarper> mWarper;
195  double mTStart;
196  double mTEnd;
197  double mOffset;
198 public:
199  RegionTimeWarper(double tStart, double tEnd, std::unique_ptr<TimeWarper> &&warper)
200  : mWarper(std::move(warper)), mTStart(tStart), mTEnd(tEnd),
201  mOffset(mWarper->Warp(mTEnd)-mTEnd)
202  { }
203  virtual ~RegionTimeWarper() {}
204  double Warp(double originalTime) const override
205  {
206  if (originalTime < mTStart)
207  {
208  return originalTime;
209  } else if (originalTime < mTEnd)
210  {
211  return mWarper->Warp(originalTime);
212  } else
213  {
214  return mOffset + originalTime;
215  }
216  }
217 };
218 
219 #endif /* End of include guard: __TIMEWARPER__ */
LinearInputStretchTimeWarper::mC1
double mC1
Definition: TimeWarper.h:133
LinearInputStretchTimeWarper::mC2
double mC2
Definition: TimeWarper.h:134
TimeWarper
Transforms one point in time to another point. For example, a time stretching effect might use one to...
Definition: TimeWarper.h:62
GeometricOutputTimeWarper::mTimeWarper
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:170
RegionTimeWarper::~RegionTimeWarper
virtual ~RegionTimeWarper()
Definition: TimeWarper.h:203
LinearInputStretchTimeWarper
Definition: TimeWarper.h:129
TimeWarper::~TimeWarper
virtual ~TimeWarper()
ShiftTimeWarper::mShift
double mShift
Definition: TimeWarper.h:78
RegionTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:195
ShiftTimeWarper::ShiftTimeWarper
ShiftTimeWarper(std::unique_ptr< TimeWarper > &&warper, double shiftAmount)
Definition: TimeWarper.h:80
LinearOutputRateTimeWarper::mRStart
double mRStart
Definition: TimeWarper.h:117
GeometricInputTimeWarper::mScale
double mScale
Definition: TimeWarper.h:159
ShiftTimeWarper::mWarper
std::unique_ptr< TimeWarper > mWarper
Definition: TimeWarper.h:77
LinearOutputRateTimeWarper::mTimeWarper
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:116
LinearOutputStretchTimeWarper::mC1
double mC1
Definition: TimeWarper.h:146
LinearOutputRateTimeWarper::mC1
double mC1
Definition: TimeWarper.h:120
LinearOutputStretchTimeWarper::mTimeWarper
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:144
RegionTimeWarper::RegionTimeWarper
RegionTimeWarper(double tStart, double tEnd, std::unique_ptr< TimeWarper > &&warper)
Definition: TimeWarper.h:199
GeometricOutputTimeWarper
Definition: TimeWarper.h:168
LinearTimeWarper::mShift
double mShift
Definition: TimeWarper.h:90
LinearInputRateTimeWarper::mRateWarper
LinearTimeWarper mRateWarper
Definition: TimeWarper.h:103
GeometricOutputTimeWarper::mScale
double mScale
Definition: TimeWarper.h:172
LinearOutputStretchTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:145
LinearInputStretchTimeWarper::mTimeWarper
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:131
LinearInputRateTimeWarper
TimeScale - rate varies linearly with input.
Definition: TimeWarper.h:101
LinearOutputStretchTimeWarper
Definition: TimeWarper.h:142
RegionTimeWarper::mOffset
double mOffset
Definition: TimeWarper.h:197
GeometricInputTimeWarper
Definition: TimeWarper.h:155
ShiftTimeWarper::~ShiftTimeWarper
virtual ~ShiftTimeWarper()
Definition: TimeWarper.h:82
RegionTimeWarper
No change before the specified region; during the region, warp according to the given warper; after t...
Definition: TimeWarper.h:192
LinearOutputRateTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:118
GeometricOutputTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:171
RegionTimeWarper::mWarper
std::unique_ptr< TimeWarper > mWarper
Definition: TimeWarper.h:194
LinearTimeWarper::LinearTimeWarper
LinearTimeWarper(double tBefore0, double tAfter0, double tBefore1, double tAfter1)
Definition: TimeWarper.h:92
TimeWarper::Warp
virtual double Warp(double originalTime) const =0
LinearOutputRateTimeWarper::mScale
double mScale
Definition: TimeWarper.h:119
LinearInputStretchTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:132
RegionTimeWarper::Warp
double Warp(double originalTime) const override
Definition: TimeWarper.h:204
LinearOutputRateTimeWarper
TimeScale - rate varies linearly with output.
Definition: TimeWarper.h:114
LinearInputRateTimeWarper::mScale
double mScale
Definition: TimeWarper.h:106
PasteTimeWarper::mOldT1
const double mOldT1
Definition: TimeWarper.h:183
GeometricInputTimeWarper::mRatio
double mRatio
Definition: TimeWarper.h:160
LinearTimeWarper
Linear scaling, initialised by giving two points on the line.
Definition: TimeWarper.h:87
ShiftTimeWarper
Behaves like another, given TimeWarper, except shifted by a fixed amount.
Definition: TimeWarper.h:75
LinearOutputStretchTimeWarper::mC2
double mC2
Definition: TimeWarper.h:147
GeometricOutputTimeWarper::mC0
double mC0
Definition: TimeWarper.h:173
GeometricInputTimeWarper::mTimeWarper
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:157
RegionTimeWarper::mTEnd
double mTEnd
Definition: TimeWarper.h:196
LinearOutputRateTimeWarper::mC2
double mC2
Definition: TimeWarper.h:121
LinearTimeWarper::mScale
double mScale
Definition: TimeWarper.h:89
PasteTimeWarper
Unit slope but with either a jump (pasting more) or a flat interval (pasting less)
Definition: TimeWarper.h:181
LinearInputRateTimeWarper::mRStart
double mRStart
Definition: TimeWarper.h:104
LinearInputRateTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:105
GeometricInputTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:158
IdentityTimeWarper
No change to time at all.
Definition: TimeWarper.h:69