Audacity 3.2.0
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 or later - see LICENSE.txt
6
7 Dan Horgan
8
9******************************************************************//*******************************************************************/
55
56#ifndef __TIMEWARPER__
57#define __TIMEWARPER__
58
59#include <memory>
60
61class TRACK_API TimeWarper /* not final */
62{
63public:
64 virtual ~TimeWarper();
65 virtual double Warp(double originalTime) const = 0;
66};
67
68class TRACK_API IdentityTimeWarper final : public TimeWarper
69{
70public:
71 double Warp(double originalTime) const override;
72};
73
74class TRACK_API ShiftTimeWarper final : public TimeWarper
75{
76private:
77 std::unique_ptr<TimeWarper> mWarper;
78 double mShift;
79public:
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
86class TRACK_API LinearTimeWarper final : public TimeWarper
87{
88private:
89 double mScale;
90 double mShift;
91public:
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
100class TRACK_API LinearInputRateTimeWarper final : public TimeWarper
101{
102private:
104 double mRStart;
105 double mTStart;
106 double mScale;
107public:
108 LinearInputRateTimeWarper(double tStart, double tEnd,
109 double rStart, double rEnd);
110 double Warp(double originalTime) const override;
111};
112
113class TRACK_API LinearOutputRateTimeWarper final : public TimeWarper
114{
115private:
117 double mRStart;
118 double mTStart;
119 double mScale;
120 double mC1;
121 double mC2;
122public:
123 LinearOutputRateTimeWarper(double tStart, double tEnd,
124 double rStart, double rEnd);
125 double Warp(double originalTime) const override;
126};
127
128class TRACK_API LinearInputStretchTimeWarper final : public TimeWarper
129{
130private:
132 double mTStart;
133 double mC1;
134 double mC2;
135public:
136 LinearInputStretchTimeWarper(double tStart, double tEnd,
137 double rStart, double rEnd);
138 double Warp(double originalTime) const override;
139};
140
141class TRACK_API LinearOutputStretchTimeWarper final : public TimeWarper
142{
143private:
145 double mTStart;
146 double mC1;
147 double mC2;
148public:
149 LinearOutputStretchTimeWarper(double tStart, double tEnd,
150 double rStart, double rEnd);
151 double Warp(double originalTime) const override;
152};
153
154class TRACK_API GeometricInputTimeWarper final : public TimeWarper
155{
156private:
158 double mTStart;
159 double mScale;
160 double mRatio;
161public:
162 GeometricInputTimeWarper(double tStart, double tEnd,
163 double rStart, double rEnd);
164 double Warp(double originalTime) const override;
165};
166
167class TRACK_API GeometricOutputTimeWarper final : public TimeWarper
168{
169private:
171 double mTStart;
172 double mScale;
173 double mC0;
174public:
175 GeometricOutputTimeWarper(double tStart, double tEnd,
176 double rStart, double rEnd);
177 double Warp(double originalTime) const override;
178};
179
180class TRACK_API PasteTimeWarper final : public TimeWarper
181{
182private:
183 const double mOldT1, mNewT1;
184public:
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()
191class TRACK_API RegionTimeWarper final : public TimeWarper
192{
193private:
194 std::unique_ptr<TimeWarper> mWarper;
195 double mTStart;
196 double mTEnd;
197 double mOffset;
198public:
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__ */
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:157
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:170
No change to time at all.
Definition: TimeWarper.h:69
TimeScale - rate varies linearly with input.
Definition: TimeWarper.h:101
LinearTimeWarper mRateWarper
Definition: TimeWarper.h:103
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:131
TimeScale - rate varies linearly with output.
Definition: TimeWarper.h:114
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:116
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:144
Linear scaling, initialised by giving two points on the line.
Definition: TimeWarper.h:87
LinearTimeWarper(double tBefore0, double tAfter0, double tBefore1, double tAfter1)
Definition: TimeWarper.h:92
Unit slope but with either a jump (pasting more) or a flat interval (pasting less)
Definition: TimeWarper.h:181
const double mNewT1
Definition: TimeWarper.h:183
No change before the specified region; during the region, warp according to the given warper; after t...
Definition: TimeWarper.h:192
double Warp(double originalTime) const override
Definition: TimeWarper.h:204
RegionTimeWarper(double tStart, double tEnd, std::unique_ptr< TimeWarper > &&warper)
Definition: TimeWarper.h:199
virtual ~RegionTimeWarper()
Definition: TimeWarper.h:203
std::unique_ptr< TimeWarper > mWarper
Definition: TimeWarper.h:194
Behaves like another, given TimeWarper, except shifted by a fixed amount.
Definition: TimeWarper.h:75
std::unique_ptr< TimeWarper > mWarper
Definition: TimeWarper.h:77
virtual ~ShiftTimeWarper()
Definition: TimeWarper.h:82
ShiftTimeWarper(std::unique_ptr< TimeWarper > &&warper, double shiftAmount)
Definition: TimeWarper.h:80
Transforms one point in time to another point. For example, a time stretching effect might use one to...
Definition: TimeWarper.h:62
virtual double Warp(double originalTime) const =0
virtual ~TimeWarper()
STL namespace.