comparison audioio/PlaySpeedRangeMapper.cpp @ 441:aa6fb3516e28 tonioni

Merge from cxx11 branch
author Chris Cannam
date Mon, 23 Mar 2015 11:26:28 +0000
parents 72c662fe7ea3
children 45054b36ddbf
comparison
equal deleted inserted replaced
440:2185d52b4758 441:aa6fb3516e28
23 m_maxpos(maxpos) 23 m_maxpos(maxpos)
24 { 24 {
25 } 25 }
26 26
27 int 27 int
28 PlaySpeedRangeMapper::getPositionForValue(float value) const 28 PlaySpeedRangeMapper::getPositionForValue(double value) const
29 { 29 {
30 // value is percent 30 // value is percent
31 float factor = getFactorForValue(value); 31 double factor = getFactorForValue(value);
32 int position = getPositionForFactor(factor); 32 int position = getPositionForFactor(factor);
33 return position; 33 return position;
34 } 34 }
35 35
36 int 36 int
37 PlaySpeedRangeMapper::getPositionForValueUnclamped(float value) const 37 PlaySpeedRangeMapper::getPositionForValueUnclamped(double value) const
38 { 38 {
39 // We don't really provide this 39 // We don't really provide this
40 return getPositionForValue(value); 40 return getPositionForValue(value);
41 } 41 }
42 42
43 int 43 int
44 PlaySpeedRangeMapper::getPositionForFactor(float factor) const 44 PlaySpeedRangeMapper::getPositionForFactor(double factor) const
45 { 45 {
46 bool slow = (factor > 1.0); 46 bool slow = (factor > 1.0);
47 47
48 if (!slow) factor = 1.0 / factor; 48 if (!slow) factor = 1.0 / factor;
49 49
50 int half = (m_maxpos + m_minpos) / 2; 50 int half = (m_maxpos + m_minpos) / 2;
51 51
52 factor = sqrtf((factor - 1.0) * 1000.f); 52 factor = sqrt((factor - 1.0) * 1000.0);
53 int position = lrintf(((factor * (half - m_minpos)) / 100.0) + m_minpos); 53 int position = int(lrint(((factor * (half - m_minpos)) / 100.0) + m_minpos));
54 54
55 if (slow) { 55 if (slow) {
56 position = half - position; 56 position = half - position;
57 } else { 57 } else {
58 position = position + half; 58 position = position + half;
61 // cerr << "value = " << value << " slow = " << slow << " factor = " << factor << " position = " << position << endl; 61 // cerr << "value = " << value << " slow = " << slow << " factor = " << factor << " position = " << position << endl;
62 62
63 return position; 63 return position;
64 } 64 }
65 65
66 float 66 double
67 PlaySpeedRangeMapper::getValueForPosition(int position) const 67 PlaySpeedRangeMapper::getValueForPosition(int position) const
68 { 68 {
69 float factor = getFactorForPosition(position); 69 double factor = getFactorForPosition(position);
70 float pc = getValueForFactor(factor); 70 double pc = getValueForFactor(factor);
71 return pc; 71 return pc;
72 } 72 }
73 73
74 float 74 double
75 PlaySpeedRangeMapper::getValueForPositionUnclamped(int position) const 75 PlaySpeedRangeMapper::getValueForPositionUnclamped(int position) const
76 { 76 {
77 // We don't really provide this 77 // We don't really provide this
78 return getValueForPosition(position); 78 return getValueForPosition(position);
79 } 79 }
80 80
81 float 81 double
82 PlaySpeedRangeMapper::getValueForFactor(float factor) const 82 PlaySpeedRangeMapper::getValueForFactor(double factor) const
83 { 83 {
84 float pc; 84 double pc;
85 if (factor < 1.0) pc = ((1.0 / factor) - 1.0) * 100.0; 85 if (factor < 1.0) pc = ((1.0 / factor) - 1.0) * 100.0;
86 else pc = (1.0 - factor) * 100.0; 86 else pc = (1.0 - factor) * 100.0;
87 // cerr << "position = " << position << " percent = " << pc << endl; 87 // cerr << "position = " << position << " percent = " << pc << endl;
88 return pc; 88 return pc;
89 } 89 }
90 90
91 float 91 double
92 PlaySpeedRangeMapper::getFactorForValue(float value) const 92 PlaySpeedRangeMapper::getFactorForValue(double value) const
93 { 93 {
94 // value is percent 94 // value is percent
95 95
96 float factor; 96 double factor;
97 97
98 if (value <= 0) { 98 if (value <= 0) {
99 factor = 1.0 - (value / 100.0); 99 factor = 1.0 - (value / 100.0);
100 } else { 100 } else {
101 factor = 1.0 / (1.0 + (value / 100.0)); 101 factor = 1.0 / (1.0 + (value / 100.0));
103 103
104 // cerr << "value = " << value << " factor = " << factor << endl; 104 // cerr << "value = " << value << " factor = " << factor << endl;
105 return factor; 105 return factor;
106 } 106 }
107 107
108 float 108 double
109 PlaySpeedRangeMapper::getFactorForPosition(int position) const 109 PlaySpeedRangeMapper::getFactorForPosition(int position) const
110 { 110 {
111 bool slow = false; 111 bool slow = false;
112 112
113 if (position < m_minpos) position = m_minpos; 113 if (position < m_minpos) position = m_minpos;
122 position = position - half; 122 position = position - half;
123 } 123 }
124 124
125 // position is between min and half (inclusive) 125 // position is between min and half (inclusive)
126 126
127 float factor; 127 double factor;
128 128
129 if (position == m_minpos) { 129 if (position == m_minpos) {
130 factor = 1.0; 130 factor = 1.0;
131 } else { 131 } else {
132 factor = ((position - m_minpos) * 100.0) / (half - m_minpos); 132 factor = ((position - m_minpos) * 100.0) / (half - m_minpos);