OpenShot Audio Library | OpenShotAudio  0.6.0
juce_LogRampedValue_test.cpp
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2022 - Raw Material Software Limited
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11  Agreement and JUCE Privacy Policy.
12 
13  End User License Agreement: www.juce.com/juce-7-licence
14  Privacy Policy: www.juce.com/juce-privacy-policy
15 
16  Or: You may also use this code under the terms of the GPL v3 (see
17  www.gnu.org/licenses).
18 
19  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21  DISCLAIMED.
22 
23  ==============================================================================
24 */
25 
26 namespace juce::dsp
27 {
28 
29 static CommonSmoothedValueTests <LogRampedValue <float>> commonLogRampedValueTests;
30 
31 class LogRampedValueTests final : public UnitTest
32 {
33 public:
34  LogRampedValueTests()
35  : UnitTest ("LogRampedValueTests", UnitTestCategories::dsp)
36  {}
37 
38  void runTest() override
39  {
40  beginTest ("Curve");
41  {
42  Array<double> levels = { -0.12243, -1.21245, -12.2342, -22.4683, -30.0, -61.18753 };
43 
44  for (auto level : levels)
45  {
46  Array<Range<double>> ranges = { Range<double> (0.0, 1.0),
47  Range<double> (-2.345, 0.0),
48  Range<double> (-2.63, 3.56),
49  Range<double> (3.3, -0.2) };
50 
51  for (auto range : ranges)
52  {
53  LogRampedValue<double> slowStart { range.getStart() } , fastStart { range.getEnd() };
54 
55  auto numSamples = 12;
56  slowStart.reset (numSamples);
57  fastStart.reset (numSamples);
58 
59  slowStart.setLogParameters (level, true);
60  fastStart.setLogParameters (level, false);
61 
62  slowStart.setTargetValue (range.getEnd());
63  fastStart.setTargetValue (range.getStart());
64 
65  AudioBuffer<double> results (2, numSamples + 1);
66 
67  results.setSample (0, 0, slowStart.getCurrentValue());
68  results.setSample (1, 0, fastStart.getCurrentValue());
69 
70  for (int i = 1; i < results.getNumSamples(); ++i)
71  {
72  results.setSample (0, i, slowStart.getNextValue());
73  results.setSample (1, i, fastStart.getNextValue());
74  }
75 
76  for (int i = 0; i < results.getNumSamples(); ++i)
77  expectWithinAbsoluteError (results.getSample (0, i),
78  results.getSample (1, results.getNumSamples() - (i + 1)),
79  1.0e-7);
80 
81  auto expectedMidpoint = range.getStart() + (range.getLength() * Decibels::decibelsToGain (level));
82  expectWithinAbsoluteError (results.getSample (0, numSamples / 2),
83  expectedMidpoint,
84  1.0e-7);
85  }
86  }
87  }
88  }
89 };
90 
91 static LogRampedValueTests LogRampedValueTests;
92 
93 } // namespace juce::dsp
static Type decibelsToGain(Type decibels, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Definition: juce_Decibels.h:42
UnitTest(const String &name, const String &category=String())
void beginTest(const String &testName)
void expectWithinAbsoluteError(ValueType actual, ValueType expected, ValueType maxAbsoluteError, String failureMessage=String())