OpenShot Library | OpenShotAudio 0.2.2
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
27namespace juce
28{
29namespace dsp
30{
31
32static CommonSmoothedValueTests <LogRampedValue <float>> commonLogRampedValueTests;
33
35{
36public:
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)
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
94static LogRampedValueTests LogRampedValueTests;
95
96} // namespace dsp
97} // namespace juce
A multi-channel buffer containing floating point audio samples.
Type getSample(int channel, int sampleIndex) const noexcept
Returns a sample from the buffer.
int getNumSamples() const noexcept
Returns the number of samples allocated in each of the buffer's channels.
void setSample(int destChannel, int destSample, Type newValue) noexcept
Sets a sample in the buffer.
static Type decibelsToGain(Type decibels, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Converts a dBFS value to its equivalent gain level.
Definition: juce_Decibels.h:46
A general-purpose range object, that simply represents any linear range with a start and end point.
Definition: juce_Range.h:44
This is a base class for classes that perform a unit test.
Definition: juce_UnitTest.h:74
UnitTest(const String &name, const String &category=String())
Creates a test with the given name and optionally places it in a category.
void beginTest(const String &testName)
Tells the system that a new subsection of tests is beginning.
void expectWithinAbsoluteError(ValueType actual, ValueType expected, ValueType maxAbsoluteError, String failureMessage=String())
Computes the difference between a value and a comparison value, and if it is larger than a specified ...
void runTest() override
Implement this method in your subclass to actually run your tests.
Utility class for logarithmically smoothed linear values.
void reset(double sampleRate, double rampLengthInSeconds) noexcept
Reset to a new sample rate and ramp length.