2
* Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
* Author: Adrien Beraud <adrienberaud@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Additional permission under GNU GPL version 3 section 7:
21
* If you modify this program, or any covered work, by linking or
22
* combining it with the OpenSSL project's OpenSSL library (or a
23
* modified version of that library), containing parts covered by the
24
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
25
* grants you additional permission to convey the resulting work.
26
* Corresponding Source for a non-source form of such a combination
27
* shall include the source code for the parts of OpenSSL used as well
28
* as that of the covered work.
32
#include "audiobuffertest.h"
33
#include "audio/audiobuffer.h"
34
#include "audio/ringbuffer.h"
36
#include "test_utils.h"
38
void AudioBufferTest::testAudioBufferConstructors()
42
SFLAudioSample test_samples1[] = {};
43
SFLAudioSample test_samples2[] = {10, 11, 12, 13, 14, 15, 16, 17};
45
AudioBuffer empty_buf(0, 1, 8000);
46
CPPUNIT_ASSERT(empty_buf.frames() == 0);
47
CPPUNIT_ASSERT(empty_buf.channels() == 1);
48
CPPUNIT_ASSERT(empty_buf.getChannel(0)->size() == 0);
50
AudioBuffer test_buf1(8, 2, 8000);
51
CPPUNIT_ASSERT(test_buf1.frames() == 8);
52
CPPUNIT_ASSERT(test_buf1.channels() == 2);
53
CPPUNIT_ASSERT(test_buf1.getChannel(0)->size() == 8);
54
CPPUNIT_ASSERT(test_buf1.getChannel(1)->size() == 8);
55
CPPUNIT_ASSERT(test_buf1.getChannel(2) == NULL);
57
AudioBuffer test_buf2(test_samples1, 0, 0, 8000);
58
CPPUNIT_ASSERT(test_buf2.frames() == 0);
59
CPPUNIT_ASSERT(test_buf2.channels() == 1);
60
CPPUNIT_ASSERT(test_buf2.getChannel(0)->size() == 0);
62
AudioBuffer test_buf3(test_samples2, 4, 2, 8000);
63
CPPUNIT_ASSERT(test_buf3.frames() == 4);
64
CPPUNIT_ASSERT(test_buf3.channels() == 2);
65
CPPUNIT_ASSERT(test_buf3.getChannel(0)->size() == 4);
68
void AudioBufferTest::testAudioBufferMix()
72
SFLAudioSample test_samples1[] = {18, 19, 20, 21, 22, 23, 24, 25};
73
SFLAudioSample test_samples2[] = {10, 11, 12, 13, 14, 15, 16, 17, 18};
75
AudioBuffer test_buf1(test_samples1, 4, 2, 8000);
76
CPPUNIT_ASSERT(test_buf1.channels() == 2);
77
test_buf1.setChannelNum(1);
78
CPPUNIT_ASSERT(test_buf1.channels() == 1);
79
test_buf1.setChannelNum(2);
80
CPPUNIT_ASSERT(test_buf1.channels() == 2);
81
CPPUNIT_ASSERT(test_buf1.getChannel(1)->size() == 4);
82
CPPUNIT_ASSERT((*test_buf1.getChannel(1))[0] == 0);
83
test_buf1.setChannelNum(1);
84
test_buf1.setChannelNum(2, true);
85
CPPUNIT_ASSERT((*test_buf1.getChannel(1))[0] == test_samples1[0]);
87
AudioBuffer test_buf2(0, 1, 8000);
88
test_buf2.deinterleave(test_samples2, 3, 3);
89
CPPUNIT_ASSERT((*test_buf2.getChannel(0))[2] == test_samples2[6]);
90
CPPUNIT_ASSERT((*test_buf2.getChannel(1))[1] == test_samples2[4]);
91
CPPUNIT_ASSERT((*test_buf2.getChannel(2))[0] == test_samples2[2]);
92
CPPUNIT_ASSERT(test_buf2.capacity() == 9);
94
SFLAudioSample *output = new SFLAudioSample[test_buf2.capacity()];
95
test_buf2.interleave(output);
96
CPPUNIT_ASSERT(std::equal(test_samples2, test_samples2 + sizeof test_samples2 / sizeof *test_samples2, output));
97
//CPPUNIT_ASSERT(std::equal(std::begin(test_samples2), std::end(test_samples2), std::begin(output))); C++11
99
test_buf1.mix(test_buf2);
100
CPPUNIT_ASSERT(test_buf1.channels() == 2);
101
CPPUNIT_ASSERT(test_buf1.frames() == 4);
102
CPPUNIT_ASSERT((*test_buf1.getChannel(0))[0] == test_samples1[0]+test_samples2[0]);
103
CPPUNIT_ASSERT((*test_buf1.getChannel(1))[0] == test_samples1[0]+test_samples2[1]);
107
AudioBufferTest::AudioBufferTest() : CppUnit::TestCase("Audio Buffer Tests") {}