Audacity 3.2.0
Namespaces | Typedefs | Functions | Variables
ClipSegmentTest.cpp File Reference
#include "ClipSegment.h"
#include "AudioContainer.h"
#include "FloatVectorClip.h"
#include <catch2/catch.hpp>
Include dependency graph for ClipSegmentTest.cpp:

Go to the source code of this file.

Namespaces

namespace  anonymous_namespace{ClipSegmentTest.cpp}
 

Typedefs

using anonymous_namespace{ClipSegmentTest.cpp}::FloatVectorVector = std::vector< std::vector< float > >
 

Functions

 TEST_CASE ("ClipSegment")
 

Variables

constexpr auto anonymous_namespace{ClipSegmentTest.cpp}::sampleRate = 3
 

Function Documentation

◆ TEST_CASE()

TEST_CASE ( "ClipSegment"  )

Definition at line 24 of file ClipSegmentTest.cpp.

25{
26 const auto direction =
28
29 SECTION("simple test case")
30 {
31 const auto numChannels = GENERATE(1u, 2u);
32 const auto clip =
33 numChannels == 1u ?
34 std::make_shared<FloatVectorClip>(
35 sampleRate, FloatVectorVector { { 1.f, 2.f, 3.f } }) :
36 std::make_shared<FloatVectorClip>(
38 FloatVectorVector { { 1.f, 2.f, 3.f }, { -1.f, -2.f, -3.f } });
39 ClipSegment sut { *clip, 0., direction };
40 AudioContainer output(sampleRate, numChannels);
41 REQUIRE(sut.GetFloats(output.channelPointers.data(), sampleRate) == sampleRate);
42 if (numChannels == 1u)
43 {
44 const auto expected = direction == PlaybackDirection::forward ?
45 std::vector<float> { 1.f, 2.f, 3.f } :
46 std::vector<float> { 3.f, 2.f, 1.f };
47 const auto asExpected = output.channelVectors[0] == expected;
48 REQUIRE(asExpected);
49 }
50 else
51 {
52 const auto expected =
53 direction == PlaybackDirection::forward ?
54 std::vector<std::vector<float>> { { 1.f, 2.f, 3.f },
55 { -1.f, -2.f, -3.f } } :
56 std::vector<std::vector<float>> { { 3.f, 2.f, 1.f },
57 { -3.f, -2.f, -1.f } };
58 const auto asExpected = output.channelVectors == expected;
59 REQUIRE(asExpected);
60 }
61 }
62
63 SECTION("accounts for playback offset")
64 {
65 const auto clip = std::make_shared<FloatVectorClip>(
66 sampleRate, FloatVectorVector { { 1.f, 2.f, 3.f, 4.f, 5.f } });
67 const auto numSamples = clip->GetVisibleSampleCount().as_size_t(); // 5
68 // Offset of two samples, in seconds.
69 constexpr auto playbackOffset = 2 / static_cast<double>(sampleRate);
70 ClipSegment sut { *clip, playbackOffset, direction };
71 AudioContainer output(numSamples, 1u);
72 REQUIRE(sut.GetFloats(output.channelPointers.data(), numSamples) == 3);
73 const auto expected = direction == PlaybackDirection::forward ?
74 std::vector<float> { 3.f, 4.f, 5.f, 0.f, 0.f } :
75 std::vector<float> { 3.f, 2.f, 1.f, 0.f, 0.f };
76 REQUIRE(output.channelVectors[0] == expected);
77 }
78}
std::vector< std::vector< float > > FloatVectorVector

References backward, AudioContainer::channelPointers, AudioContainer::channelVectors, forward, and anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.