~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/test/audiobuffertest.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
 
3
 *  Author: Adrien Beraud <adrienberaud@gmail.com>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 *
 
19
 *  Additional permission under GNU GPL version 3 section 7:
 
20
 *
 
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.
 
29
 */
 
30
 
 
31
#include <string>
 
32
#include "audiobuffertest.h"
 
33
#include "audio/audiobuffer.h"
 
34
#include "audio/ringbuffer.h"
 
35
#include "logger.h"
 
36
#include "test_utils.h"
 
37
 
 
38
void AudioBufferTest::testAudioBufferConstructors()
 
39
{
 
40
    TITLE();
 
41
 
 
42
    SFLAudioSample test_samples1[] = {};
 
43
    SFLAudioSample test_samples2[] = {10, 11, 12, 13, 14, 15, 16, 17};
 
44
 
 
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);
 
49
 
 
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);
 
56
 
 
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);
 
61
 
 
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);
 
66
}
 
67
 
 
68
void AudioBufferTest::testAudioBufferMix()
 
69
{
 
70
    TITLE();
 
71
 
 
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};
 
74
 
 
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]);
 
86
 
 
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);
 
93
 
 
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
 
98
 
 
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]);
 
104
}
 
105
 
 
106
 
 
107
AudioBufferTest::AudioBufferTest() : CppUnit::TestCase("Audio Buffer Tests") {}