1
/***************************************************************************
4
begin : Halloween, 2011
5
copyright : (C) 2011 Owen Williams
6
email : owilliams@mixxx.org
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
20
#include "vinylcontrolxwax.h"
21
#include "steadypitch.h"
24
SteadyPitch::SteadyPitch(double threshold)
26
m_dPitchThreshold = threshold; //variation above which we say we aren't steady
27
m_dOldSteadyPitch = 1.0f; //last-known steady pitch value
28
m_dSteadyPitchTime = 0.0f; //last track location we had a steady pitch
29
m_dLastSteadyDur = 0.0f; //last known duration of steadiness
30
m_dLastTime = 0.0f; //track location of previous call
31
m_iPlayDirection = 1; //1=forward, -1=backward
35
void SteadyPitch::reset(double pitch, double time)
37
m_dSteadyPitch = pitch;
38
m_dSteadyPitchTime = time;
40
if (m_dSteadyPitch >= 0) {
43
m_iPlayDirection = -1;
45
m_dLastSteadyDur = 0.0;
48
bool SteadyPitch::directionChanged(double pitch)
51
return m_iPlayDirection != 1;
53
return m_iPlayDirection != -1;
57
bool SteadyPitch::resyncDetected(double new_time)
59
//did track location jump opposite to the play direction?
60
if (m_iPlayDirection >= 0)
62
return new_time < m_dLastTime;
66
return new_time > m_dLastTime;
70
double SteadyPitch::check(double pitch, double time, bool looping=false)
72
//return length of time pitch has been steady, 0 if not steady
73
if (directionChanged(pitch))
75
//we've reversed direction, reset
80
if (resyncDetected(time))
85
//if looping, rereport the last value since we don't know where the
87
if (fabs(pitch - m_dSteadyPitch) < m_dPitchThreshold)
89
//fabricate an old time by take current time and applying
91
m_dSteadyPitchTime = time - (m_dLastSteadyDur * m_iPlayDirection);
92
return m_dLastSteadyDur;
100
if (fabs(pitch - m_dSteadyPitch) < m_dPitchThreshold)
102
if (fabs(time - m_dSteadyPitchTime) > 2.0) //fabs for both directions
104
m_dSteadyPitch = pitch;
105
m_dOldSteadyPitch = m_dSteadyPitch; //this was a known-good value
106
//update steady pitch time so it's between 1 and 2 seconds ago
107
//(or ahead, if moving backward)
108
m_dSteadyPitchTime += 1.0 * m_iPlayDirection;
110
m_dLastSteadyDur = fabs(time - m_dSteadyPitchTime);
111
return m_dLastSteadyDur;
119
double SteadyPitch::steadyValue(void)
121
return m_dOldSteadyPitch;