Audacity 3.2.0
DownwardMeterValueProvider.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 DownwardMeterValueProvider.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
12#include <algorithm>
13#include <cassert>
14
15namespace
16{
17constexpr auto decayPerSecondDb = 10.f;
18constexpr auto decayPerTickDb =
20constexpr auto maxDelayMs = 5000;
22} // namespace
23
25 : mUpperValue { upperValue }
26 , mGlobalMin { upperValue }
27 , mCurrentMin { upperValue }
28 , mFiveSecMinState { upperValue }
29{
30 mRingBuffer.fill(upperValue);
31}
32
33void DownwardMeterValueProvider::Update(float newValue, bool alsoFiveSecondMax)
34{
36
37 const auto value = mRingBuffer[mRingBufferIndex];
38 mRingBuffer[mRingBufferIndex] = newValue;
40
41 if (value < mCurrentMin)
42 {
43 mCurrentMin = value;
45 }
46 else
48
49 mLastFiveSeconds.emplace_back(mTimerCount, value);
50 while (!mLastFiveSeconds.empty() &&
53
54 if (!mLastFiveSeconds.empty() && alsoFiveSecondMax)
55 {
56 const auto rawMin =
57 std::min_element(
59 [](const auto& a, const auto& b) { return a.second < b.second; })
60 ->second;
61 if (rawMin <= mFiveSecMinState)
62 mFiveSecMinState = rawMin;
63 else
66 }
67}
68
70{
71 return mGlobalMin;
72}
73
75{
76 return mFiveSecMinState;
77}
78
80{
81 return mCurrentMin;
82}
83
86{
88}
89
91{
92 return mCurrentMin >= mUpperValue;
93}
int min(int a, int b)
static constexpr auto compressorMeterUpdatePeriodMs
static constexpr auto ringBufferLength
std::array< float, ringBufferLength > mRingBuffer
void Update(float value, bool alsoFiveSecondMax) override
std::vector< std::pair< int, float > > mLastFiveSeconds
Direction GetDirection() const override
DownwardMeterValueProvider(float upperValue=0.f)