Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
NumberScale Class Reference

#include <NumberScale.h>

Classes

class  Iterator
 

Public Member Functions

 NumberScale ()
 
 NumberScale (NumberScaleType type, float value0, float value1)
 
NumberScale Reversal () const
 
bool operator== (const NumberScale &other) const
 
bool operator!= (const NumberScale &other) const
 
float PositionToValue (float pp) const
 
Iterator begin (float nPositions) const
 
float ValueToPosition (float val) const
 

Static Public Member Functions

static float hzToMel (float hz)
 
static float melToHz (float mel)
 
static float hzToBark (float hz)
 
static float barkToHz (float z1)
 
static float hzToErb (float hz)
 
static float erbToHz (float erb)
 
static float hzToPeriod (float hz)
 
static float periodToHz (float u)
 

Private Attributes

NumberScaleType mType
 
float mValue0
 
float mValue1
 

Detailed Description

Definition at line 31 of file NumberScale.h.

Constructor & Destructor Documentation

◆ NumberScale() [1/2]

NumberScale::NumberScale ( )
inline

Definition at line 34 of file NumberScale.h.

35 : mType(nstNone), mValue0(0), mValue1(1)
36 {}
@ nstNone
Definition: NumberScale.h:27
float mValue0
Definition: NumberScale.h:279
NumberScaleType mType
Definition: NumberScale.h:278
float mValue1
Definition: NumberScale.h:280

◆ NumberScale() [2/2]

NumberScale::NumberScale ( NumberScaleType  type,
float  value0,
float  value1 
)
inline

Definition at line 38 of file NumberScale.h.

39 : mType(type)
40 {
41 switch (mType) {
42 case nstLinear:
43 case nstNone:
44 {
45 mValue0 = value0;
46 mValue1 = value1;
47 }
48 break;
49 case nstLogarithmic:
50 {
51 mValue0 = logf(value0);
52 mValue1 = logf(value1);
53 }
54 break;
55 case nstMel:
56 {
57 mValue0 = hzToMel(value0);
58 mValue1 = hzToMel(value1);
59 }
60 break;
61 case nstBark:
62 {
63 mValue0 = hzToBark(value0);
64 mValue1 = hzToBark(value1);
65 }
66 break;
67 case nstErb:
68 {
69 mValue0 = hzToErb(value0);
70 mValue1 = hzToErb(value1);
71 }
72 break;
73 case nstPeriod:
74 {
75 mValue0 = hzToPeriod(value0);
76 mValue1 = hzToPeriod(value1);
77 }
78 break;
79 default:
80 wxASSERT(false);
81 }
82 }
@ nstMel
Definition: NumberScale.h:21
@ nstErb
Definition: NumberScale.h:23
@ nstPeriod
Definition: NumberScale.h:24
@ nstLinear
Definition: NumberScale.h:19
@ nstLogarithmic
Definition: NumberScale.h:20
@ nstBark
Definition: NumberScale.h:22
static float hzToPeriod(float hz)
Definition: NumberScale.h:144
static float hzToErb(float hz)
Definition: NumberScale.h:134
static float hzToBark(float hz)
Definition: NumberScale.h:113
static float hzToMel(float hz)
Definition: NumberScale.h:103

References hzToBark(), hzToErb(), hzToMel(), hzToPeriod(), mType, mValue0, mValue1, nstBark, nstErb, nstLinear, nstLogarithmic, nstMel, nstNone, and nstPeriod.

Here is the call graph for this function:

Member Function Documentation

◆ barkToHz()

static float NumberScale::barkToHz ( float  z1)
inlinestatic

Definition at line 125 of file NumberScale.h.

126 {
127 if (z1 < 2.0)
128 z1 = 2.0 + (z1 - 2.0) / 0.85;
129 else if (z1 > 20.1)
130 z1 = 20.1 + (z1 - 20.1) / 1.22;
131 return 1960 * (z1 + 0.53) / (26.28 - z1);
132 }

Referenced by NumberScale::Iterator::operator*(), and PositionToValue().

Here is the caller graph for this function:

◆ begin()

Iterator NumberScale::begin ( float  nPositions) const
inline

Definition at line 232 of file NumberScale.h.

233 {
234 switch (mType) {
235 default:
236 wxASSERT(false);
237 case nstLinear:
238 case nstNone:
239 case nstMel:
240 case nstBark:
241 case nstErb:
242 case nstPeriod:
243 return Iterator
244 (mType,
245 nPositions == 1 ? 0 : (mValue1 - mValue0) / (nPositions - 1),
246 mValue0);
247 case nstLogarithmic:
248 return Iterator
249 (mType,
250 nPositions == 1 ? 1 : exp((mValue1 - mValue0) / (nPositions - 1)),
251 exp(mValue0));
252 }
253 }

References mType, mValue0, mValue1, nstBark, nstErb, nstLinear, nstLogarithmic, nstMel, nstNone, and nstPeriod.

Referenced by anonymous_namespace{SpectrumView.cpp}::DrawClipSpectrum().

Here is the caller graph for this function:

◆ erbToHz()

static float NumberScale::erbToHz ( float  erb)
inlinestatic

Definition at line 139 of file NumberScale.h.

140 {
141 return 676170.4 / (47.06538 - exp(0.08950404 * erb)) - 14678.49;
142 }

Referenced by NumberScale::Iterator::operator*(), and PositionToValue().

Here is the caller graph for this function:

◆ hzToBark()

static float NumberScale::hzToBark ( float  hz)
inlinestatic

Definition at line 113 of file NumberScale.h.

114 {
115 // Traunmueller's formula
116 const float z1 = 26.81 * hz / (1960 + hz) - 0.53;
117 if (z1 < 2.0)
118 return z1 + 0.15 * (2.0 - z1);
119 else if (z1 > 20.1)
120 return z1 + 0.22 * (z1 - 20.1);
121 else
122 return z1;
123 }

Referenced by NumberScale(), and ValueToPosition().

Here is the caller graph for this function:

◆ hzToErb()

static float NumberScale::hzToErb ( float  hz)
inlinestatic

Definition at line 134 of file NumberScale.h.

135 {
136 return 11.17268 * log(1 + (46.06538 * hz) / (hz + 14678.49));
137 }

Referenced by NumberScale(), and ValueToPosition().

Here is the caller graph for this function:

◆ hzToMel()

static float NumberScale::hzToMel ( float  hz)
inlinestatic

Definition at line 103 of file NumberScale.h.

104 {
105 return 1127 * log(1 + hz / 700);
106 }

Referenced by NumberScale(), and ValueToPosition().

Here is the caller graph for this function:

◆ hzToPeriod()

static float NumberScale::hzToPeriod ( float  hz)
inlinestatic

Definition at line 144 of file NumberScale.h.

145 {
146 return -1.0 / std::max (1.0f, hz);
147 }

Referenced by NumberScale(), and ValueToPosition().

Here is the caller graph for this function:

◆ melToHz()

static float NumberScale::melToHz ( float  mel)
inlinestatic

Definition at line 108 of file NumberScale.h.

109 {
110 return 700 * (exp(mel / 1127) - 1);
111 }

Referenced by NumberScale::Iterator::operator*(), and PositionToValue().

Here is the caller graph for this function:

◆ operator!=()

bool NumberScale::operator!= ( const NumberScale other) const
inline

Definition at line 98 of file NumberScale.h.

99 {
100 return !(*this == other);
101 }

◆ operator==()

bool NumberScale::operator== ( const NumberScale other) const
inline

Definition at line 91 of file NumberScale.h.

92 {
93 return mType == other.mType
94 && mValue0 == other.mValue0
95 && mValue1 == other.mValue1;
96 }

References mType, mValue0, and mValue1.

◆ periodToHz()

static float NumberScale::periodToHz ( float  u)
inlinestatic

Definition at line 149 of file NumberScale.h.

150 {
151 return -1.0 / u;
152 }

Referenced by NumberScale::Iterator::operator*(), and PositionToValue().

Here is the caller graph for this function:

◆ PositionToValue()

float NumberScale::PositionToValue ( float  pp) const
inline

Definition at line 155 of file NumberScale.h.

156 {
157 switch (mType) {
158 default:
159 wxASSERT(false);
160 case nstLinear:
161 case nstNone:
162 return mValue0 + pp * (mValue1 - mValue0);
163 case nstLogarithmic:
164 return exp(mValue0 + pp * (mValue1 - mValue0));
165 case nstMel:
166 return melToHz(mValue0 + pp * (mValue1 - mValue0));
167 case nstBark:
168 return barkToHz(mValue0 + pp * (mValue1 - mValue0));
169 case nstErb:
170 return erbToHz(mValue0 + pp * (mValue1 - mValue0));
171 case nstPeriod:
172 return periodToHz(mValue0 + pp * (mValue1 - mValue0));
173 }
174 }
static float erbToHz(float erb)
Definition: NumberScale.h:139
static float periodToHz(float u)
Definition: NumberScale.h:149
static float barkToHz(float z1)
Definition: NumberScale.h:125
static float melToHz(float mel)
Definition: NumberScale.h:108

References barkToHz(), erbToHz(), melToHz(), mType, mValue0, mValue1, nstBark, nstErb, nstLinear, nstLogarithmic, nstMel, nstNone, nstPeriod, and periodToHz().

Referenced by SpectrumVRulerControls::DoHandleWheelRotation(), SpectrumVZoomHandle::DoZoom(), anonymous_namespace{SpectrumView.cpp}::DrawClipSpectrum(), anonymous_namespace{BrushHandle.cpp}::PositionToFrequency(), and anonymous_namespace{SelectHandle.cpp}::PositionToFrequency().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reversal()

NumberScale NumberScale::Reversal ( ) const
inline

Definition at line 84 of file NumberScale.h.

85 {
86 NumberScale result(*this);
87 std::swap(result.mValue0, result.mValue1);
88 return result;
89 }
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:645

References mValue0, mValue1, and anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ ValueToPosition()

float NumberScale::ValueToPosition ( float  val) const
inline

Definition at line 256 of file NumberScale.h.

257 {
258 switch (mType) {
259 default:
260 wxASSERT(false);
261 case nstLinear:
262 case nstNone:
263 return ((val - mValue0) / (mValue1 - mValue0));
264 case nstLogarithmic:
265 return ((log(val) - mValue0) / (mValue1 - mValue0));
266 case nstMel:
267 return ((hzToMel(val) - mValue0) / (mValue1 - mValue0));
268 case nstBark:
269 return ((hzToBark(val) - mValue0) / (mValue1 - mValue0));
270 case nstErb:
271 return ((hzToErb(val) - mValue0) / (mValue1 - mValue0));
272 case nstPeriod:
273 return ((hzToPeriod(val) - mValue0) / (mValue1 - mValue0));
274 }
275 }

References hzToBark(), hzToErb(), hzToMel(), hzToPeriod(), mType, mValue0, mValue1, nstBark, nstErb, nstLinear, nstLogarithmic, nstMel, nstNone, and nstPeriod.

Referenced by SpectrumVRulerControls::DoHandleWheelRotation(), anonymous_namespace{BrushHandle.cpp}::FrequencyToPosition(), and anonymous_namespace{SelectHandle.cpp}::FrequencyToPosition().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mType

NumberScaleType NumberScale::mType
private

Definition at line 278 of file NumberScale.h.

Referenced by begin(), NumberScale(), operator==(), PositionToValue(), and ValueToPosition().

◆ mValue0

float NumberScale::mValue0
private

◆ mValue1

float NumberScale::mValue1
private

The documentation for this class was generated from the following file: