OpenShot Audio Library | OpenShotAudio 0.3.2

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