tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_AudioBufferPool.tests.cpp
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace graph
12{
13
14#if GRAPH_UNIT_TESTS_AUDIOBUFFERPOOL
15
16class AudioBufferPoolTests : public juce::UnitTest
17{
18public:
19 AudioBufferPoolTests()
20 : juce::UnitTest ("AudioBufferPool", "tracktion_graph") {}
21
22 //==============================================================================
23 void runTest() override
24 {
25 runAllocationTests();
26 }
27
28private:
29 void runAllocationTests()
30 {
31 using namespace choc::buffer;
32
33 beginTest ("Allocation");
34 {
35 const auto size = Size::create (2, 128);
36
37 {
38 AudioBufferPool pool;
39 pool.setCapacity (1);
40 expectEquals<int> ((int) pool.getNumBuffers(), 0);
41 pool.release (ChannelArrayBuffer<float> (size));
42 expectEquals<int> ((int) pool.getNumBuffers(), 1);
43 expectEquals<int> ((int) pool.getAllocatedSize(), (int) SeparateChannelLayout<float>::getBytesNeeded (size));
44 }
45
46 {
47 AudioBufferPool pool (1);
48 expectEquals<int> ((int) pool.getNumBuffers(), 0);
49 pool.release (ChannelArrayBuffer<float> (size));
50 expectEquals<int> ((int) pool.getNumBuffers(), 1);
51 expectEquals<int> ((int) pool.getAllocatedSize(), (int) SeparateChannelLayout<float>::getBytesNeeded (size));
52 }
53
54 {
55 AudioBufferPool pool (2);
56 pool.reserve (1, size);
57
58 pool.release (ChannelArrayBuffer<float> (size));
59
60 auto buffer = pool.allocate (size);
61 const auto bufferSize = buffer.getSize();
62 expectGreaterOrEqual ((int) bufferSize.numFrames, (int) size.numFrames);
63 expectGreaterOrEqual ((int) bufferSize.numChannels, (int) size.numChannels);
64 expectEquals<int> ((int) pool.getAllocatedSize(), (int) SeparateChannelLayout<float>::getBytesNeeded (size));
65
66 expectEquals<int> ((int) pool.getNumBuffers(), 1);
67 pool.release (std::move (buffer));
68 expectEquals<int> ((int) pool.getNumBuffers(), 2);
69 }
70 }
71 }
72};
73
74static AudioBufferPoolTests audioBufferPoolTests;
75
76#endif
77
78}} // namespace tracktion_engine
T size(T... args)