Audacity 3.2.0
CompressorProcessorTests.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 CompressorProcessorTests.cpp
7
8 Matthieu Hodgkinson
9
10**********************************************************************/
11#pragma once
12
13#include "CompressorProcessor.h"
14#include <catch2/catch.hpp>
15
16TEST_CASE("GetMaxCompressionDb", "simple test")
17{
19 settings.inCompressionThreshDb = -20;
20 settings.outCompressionThreshDb = -10;
21 settings.kneeWidthDb = 0;
22
23 // Infinite ratio -> max compression simply is the input compression
24 // threshold.
25 settings.compressionRatio = std::numeric_limits<float>::infinity();
27
28 // 2:1 ratio -> half the input compression threshold.
29 settings.compressionRatio = 2;
31
32 // So long as the knee half width is less than the input compression
33 // threshold, it shouldn't change the result.
34 settings.kneeWidthDb = 40;
36
37 // But if it's greater, it should.
38 settings.kneeWidthDb = 60;
40}
41
42TEST_CASE("CompressorProcessor", "smoke test")
43{
45 settings.lookaheadMs = 5;
47 constexpr auto sampleRate = 44100;
48 constexpr auto numChannels = 2;
49 constexpr auto blockSize = 44100;
50 constexpr auto signalSize = 2 * blockSize;
51 sut.Init(sampleRate, numChannels, blockSize);
52 std::vector<std::vector<float>> buffer(numChannels);
53 std::vector<float*> pointers(numChannels);
54 for (auto i = 0; i < numChannels; ++i)
55 {
56 auto& in = buffer[i];
57 in.resize(signalSize);
58 std::fill(in.begin(), in.begin() + signalSize / 2, 0.0f);
59 std::fill(in.begin() + signalSize / 2, in.end(), 1.0f);
60 }
61 auto progress = 0;
62 while (progress < signalSize)
63 {
64 const auto remaining = signalSize - progress;
65 const auto toProcess = std::min(remaining, blockSize);
66 std::transform(
67 buffer.begin(), buffer.end(), pointers.begin(),
68 [progress](std::vector<float>& v) { return v.data() + progress; });
69 const auto p = pointers.data();
70 sut.Process(p, p, toProcess);
71 progress += toProcess;
72 }
73}
int min(int a, int b)
TEST_CASE("GetMaxCompressionDb", "simple test")
static Settings & settings()
Definition: TrackInfo.cpp:51
static float GetMaxCompressionDb(const DynamicRangeProcessorSettings &settings)