Audacity 3.2.0
EqualizationCurvesList.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 EqualizationCurvesList.cpp
6
7 Mitch Golden
8 Vaughan Johnson (Preview)
9 Martyn Shaw (FIR filters, response curve, graphic EQ)
10
11 Paul Licameli split from Equalization.cpp
12
13 /*********************************************************************/
15#include "EqualizationFilter.h"
16#include "Envelope.h"
17#include "SampleFormat.h"
18
19//
20// Set NEW curve selection (safe to call outside of the UI)
21//
23{
24 mParameters.mCurveName = mCurves[ curve ].Name;
25}
26
27//
28// Capture updated envelope
29//
31{
34 else
36}
37
39{
40 const auto &hiFreq = mParameters.mHiFreq;
41 const auto &drawMode = mParameters.mDrawMode;
42 auto &logEnvelope = mParameters.mLogEnvelope;
43
44 // Allocate and populate point arrays
45 size_t numPoints = env.GetNumberOfPoints();
46 Doubles when{ numPoints };
47 Doubles value{ numPoints };
48 env.GetPoints( when.get(), value.get(), numPoints );
49
50 // Clear the unnamed curve
51 int curve = mCurves.size() - 1;
52 mCurves[ curve ].points.clear();
53
54 if(lin)
55 {
56 // Copy and convert points
57 for (size_t point = 0; point < numPoints; point++)
58 {
59 double freq = when[ point ] * hiFreq;
60 double db = value[ point ];
61
62 // Add it to the curve
63 mCurves[ curve ].points.push_back( EQPoint( freq, db ) );
64 }
65 }
66 else
67 {
68 double loLog = log10( 20. );
69 double hiLog = log10( hiFreq );
70 double denom = hiLog - loLog;
71
72 // Copy and convert points
73 for (size_t point = 0; point < numPoints; point++)
74 {
75 double freq = pow( 10., ( ( when[ point ] * denom ) + loLog ));
76 double db = value[ point ];
77
78 // Add it to the curve
79 mCurves[ curve ].points.push_back( EQPoint( freq, db ) );
80 }
81 }
82
83 // Update unnamed curve (so it's there for next time)
84 //(done in a hurry, may not be the neatest -MJS)
85 if (!drawMode)
86 {
87 size_t numPoints = logEnvelope.GetNumberOfPoints();
88 Doubles when{ numPoints };
89 Doubles value{ numPoints };
90 logEnvelope.GetPoints(when.get(), value.get(), numPoints);
91 for (size_t i = 0, j = 0; j + 2 < numPoints; i++, j++)
92 {
93 if ((value[i] < value[i + 1] + .05) && (value[i] > value[i + 1] - .05) &&
94 (value[i + 1] < value[i + 2] + .05) && (value[i + 1] > value[i + 2] - .05))
95 { // within < 0.05 dB?
96 logEnvelope.Delete(j + 1);
97 numPoints--;
98 j--;
99 }
100 }
101 Select((int) mCurves.size() - 1);
102 }
103
104 // set 'unnamed' as the selected curve
105 Select( (int) mCurves.size() - 1 );
106}
One point in a curve.
Piecewise linear or piecewise exponential function from double to double.
Definition: Envelope.h:72
size_t GetNumberOfPoints() const
Return number of points.
Definition: Envelope.cpp:695
void GetPoints(double *bufferWhen, double *bufferValue, int bufferLen) const
Returns the sets of when and value pairs.
Definition: Envelope.cpp:700
EqualizationFilter & mParameters