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