Audacity  3.0.3
TimeWarper.cpp
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 ******************************************************************//*******************************************************************/
17 
18 
19 #include "TimeWarper.h"
20 
21 #include <wx/string.h>
22 #include <math.h>
23 #include <wx/debug.h>
24 
25 TimeWarper::~TimeWarper() = default;
26 
27 double IdentityTimeWarper::Warp(double originalTime) const
28 {
29  return originalTime;
30 }
31 
32 double ShiftTimeWarper::Warp(double originalTime) const
33 {
34  return mWarper->Warp(originalTime + mShift);
35 }
36 
37 double LinearTimeWarper::Warp(double originalTime) const
38 {
39  return originalTime*mScale + mShift;
40 }
41 
42 double LinearInputRateTimeWarper::Warp(double originalTime) const
43 {
44  double rate = mRateWarper.Warp(originalTime);
45  return mTStart + mScale*log(rate/mRStart);
46 }
47 
49  double rStart, double rEnd)
50 : mRateWarper(tStart, rStart, tEnd, rEnd), mRStart(rStart),
51  mTStart(tStart), mScale((tEnd-tStart)/(rEnd-rStart))
52 {
53  wxASSERT(mRStart != 0.0);
54  wxASSERT(tStart < tEnd);
55 }
56 
57 double LinearOutputRateTimeWarper::Warp(double originalTime) const
58 {
59  double scaledTime = mTimeWarper.Warp(originalTime);
60  return mTStart + mScale*(sqrt(mC1 + scaledTime * mC2) - mRStart);
61 }
62 
64  double rStart, double rEnd)
65 : mTimeWarper(tStart, 0.0, tEnd, 1.0),
66  mRStart(rStart), mTStart(tStart),
67  mScale(2.0*(tEnd-tStart)/(rEnd*rEnd-rStart*rStart)),
68  mC1(rStart*rStart), mC2(rEnd*rEnd-rStart*rStart)
69 {
70  wxASSERT(rStart != rEnd);
71  wxASSERT(rStart > 0.0);
72  wxASSERT(rEnd > 0.0);
73  wxASSERT(tStart < tEnd);
74 }
75 
76 double LinearInputStretchTimeWarper::Warp(double originalTime) const
77 {
78  double scaledTime = mTimeWarper.Warp(originalTime);
79  return mTStart + mC1 * scaledTime * (1.0 + mC2 * scaledTime);
80 }
81 
83  double rStart, double rEnd)
84 : mTimeWarper(tStart, 0.0, tEnd, 1.0), mTStart(tStart),
85  mC1((tEnd-tStart)/rStart), mC2(0.5*(rStart/rEnd - 1.0))
86 {
87  wxASSERT(rStart > 0.0);
88  wxASSERT(rEnd > 0.0);
89  wxASSERT(tStart < tEnd);
90 }
91 
92 double LinearOutputStretchTimeWarper::Warp(double originalTime) const
93 {
94  double scaledTime = mTimeWarper.Warp(originalTime);
95  return mTStart + mC1 * (pow(mC2, scaledTime) - 1.0);
96 }
97 
99  double rStart, double rEnd)
100 : mTimeWarper(tStart, 0.0, tEnd, 1.0), mTStart(tStart),
101  mC1((tEnd-tStart)/(rStart*log(rStart/rEnd))), mC2(rStart/rEnd)
102 {
103  wxASSERT(rStart != rEnd);
104  wxASSERT(rStart > 0.0);
105  wxASSERT(rEnd > 0.0);
106  wxASSERT(tStart < tEnd);
107 }
108 
109 double GeometricInputTimeWarper::Warp(double originalTime) const
110 {
111  double scaledTime = mTimeWarper.Warp(originalTime);
112  return mTStart + mScale*(pow(mRatio,scaledTime) - 1.0);
113 }
114 
116  double rStart, double rEnd)
117 : mTimeWarper(tStart, 0.0, tEnd, 1.0), mTStart(tStart),
118  mScale((tEnd-tStart)/(log(rStart/rEnd)*rStart)), mRatio(rStart/rEnd)
119 {
120  wxASSERT(rStart != rEnd);
121  wxASSERT(rStart > 0.0);
122  wxASSERT(rEnd > 0.0);
123  wxASSERT(tStart < tEnd);
124 }
125 
126 double GeometricOutputTimeWarper::Warp(double originalTime) const
127 {
128  double scaledTime = mTimeWarper.Warp(originalTime);
129  return mTStart + mScale*log1p(mC0 * scaledTime);
130 }
131 
133  double rStart, double rEnd)
134 : mTimeWarper(tStart, 0.0, tEnd, 1.0), mTStart(tStart),
135  mScale((tEnd-tStart)/(rEnd-rStart)), mC0((rEnd-rStart)/rStart)
136 {
137  wxASSERT(rStart > 0.0);
138  wxASSERT(rEnd > 0.0);
139  wxASSERT(tStart < tEnd);
140 }
141 
142 PasteTimeWarper::PasteTimeWarper(double oldT1, double newT1)
143 : mOldT1{ oldT1 }, mNewT1{ newT1 }
144 { }
145 
146 double PasteTimeWarper::Warp(double originalTime) const
147 {
148  if (originalTime < mOldT1)
149  return std::min(originalTime, mNewT1);
150  else
151  return originalTime + mNewT1 - mOldT1;
152 }
LinearInputStretchTimeWarper::mC1
double mC1
Definition: TimeWarper.h:133
LinearInputStretchTimeWarper::mC2
double mC2
Definition: TimeWarper.h:134
PasteTimeWarper::mNewT1
const double mNewT1
Definition: TimeWarper.h:183
PasteTimeWarper::PasteTimeWarper
PasteTimeWarper(double oldT1, double newT1)
Definition: TimeWarper.cpp:142
IdentityTimeWarper::Warp
double Warp(double originalTime) const override
Definition: TimeWarper.cpp:27
LinearInputRateTimeWarper::LinearInputRateTimeWarper
LinearInputRateTimeWarper(double tStart, double tEnd, double rStart, double rEnd)
Definition: TimeWarper.cpp:48
GeometricOutputTimeWarper::mTimeWarper
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:170
TimeWarper::~TimeWarper
virtual ~TimeWarper()
TimeWarper.h
Contains declarations for TimeWarper, IdentityTimeWarper, ShiftTimeWarper, LinearTimeWarper,...
ShiftTimeWarper::mShift
double mShift
Definition: TimeWarper.h:78
LinearOutputRateTimeWarper::mRStart
double mRStart
Definition: TimeWarper.h:117
LinearInputStretchTimeWarper::Warp
double Warp(double originalTime) const override
Definition: TimeWarper.cpp:76
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
GeometricInputTimeWarper::Warp
double Warp(double originalTime) const override
Definition: TimeWarper.cpp:109
LinearTimeWarper::Warp
double Warp(double originalTime) const override
Definition: TimeWarper.cpp:37
LinearOutputRateTimeWarper::mC1
double mC1
Definition: TimeWarper.h:120
LinearOutputStretchTimeWarper::mTimeWarper
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:144
LinearOutputStretchTimeWarper::LinearOutputStretchTimeWarper
LinearOutputStretchTimeWarper(double tStart, double tEnd, double rStart, double rEnd)
Definition: TimeWarper.cpp:98
LinearTimeWarper::mShift
double mShift
Definition: TimeWarper.h:90
LinearInputRateTimeWarper::mRateWarper
LinearTimeWarper mRateWarper
Definition: TimeWarper.h:103
GeometricOutputTimeWarper::mScale
double mScale
Definition: TimeWarper.h:172
GeometricInputTimeWarper::GeometricInputTimeWarper
GeometricInputTimeWarper(double tStart, double tEnd, double rStart, double rEnd)
Definition: TimeWarper.cpp:115
PasteTimeWarper::Warp
double Warp(double originalTime) const override
Definition: TimeWarper.cpp:146
LinearOutputStretchTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:145
LinearInputStretchTimeWarper::mTimeWarper
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:131
LinearOutputRateTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:118
GeometricOutputTimeWarper::GeometricOutputTimeWarper
GeometricOutputTimeWarper(double tStart, double tEnd, double rStart, double rEnd)
Definition: TimeWarper.cpp:132
GeometricOutputTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:171
LinearOutputRateTimeWarper::mScale
double mScale
Definition: TimeWarper.h:119
LinearInputRateTimeWarper::Warp
double Warp(double originalTime) const override
Definition: TimeWarper.cpp:42
LinearInputStretchTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:132
ShiftTimeWarper::Warp
double Warp(double originalTime) const override
Definition: TimeWarper.cpp:32
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
LinearInputStretchTimeWarper::LinearInputStretchTimeWarper
LinearInputStretchTimeWarper(double tStart, double tEnd, double rStart, double rEnd)
Definition: TimeWarper.cpp:82
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
LinearOutputStretchTimeWarper::mC2
double mC2
Definition: TimeWarper.h:147
GeometricOutputTimeWarper::mC0
double mC0
Definition: TimeWarper.h:173
GeometricInputTimeWarper::mTimeWarper
LinearTimeWarper mTimeWarper
Definition: TimeWarper.h:157
LinearOutputRateTimeWarper::mC2
double mC2
Definition: TimeWarper.h:121
LinearOutputStretchTimeWarper::Warp
double Warp(double originalTime) const override
Definition: TimeWarper.cpp:92
LinearTimeWarper::mScale
double mScale
Definition: TimeWarper.h:89
LinearOutputRateTimeWarper::Warp
double Warp(double originalTime) const override
Definition: TimeWarper.cpp:57
LinearInputRateTimeWarper::mRStart
double mRStart
Definition: TimeWarper.h:104
GeometricOutputTimeWarper::Warp
double Warp(double originalTime) const override
Definition: TimeWarper.cpp:126
LinearOutputRateTimeWarper::LinearOutputRateTimeWarper
LinearOutputRateTimeWarper(double tStart, double tEnd, double rStart, double rEnd)
Definition: TimeWarper.cpp:63
LinearInputRateTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:105
GeometricInputTimeWarper::mTStart
double mTStart
Definition: TimeWarper.h:158