~ubuntu-branches/ubuntu/wily/ecasound/wily-proposed

« back to all changes in this revision

Viewing changes to libecasound/samplebuffer_test.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghedini
  • Date: 2011-05-12 17:58:03 UTC
  • Revision ID: james.westby@ubuntu.com-20110512175803-zy3lodjecabt9r3v
Tags: upstream-2.8.0
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ------------------------------------------------------------------------
 
2
// samplebuffer_test.h: Unit test for SAMPLE_BUFFER
 
3
// Copyright (C) 2009 Kai Vehmanen
 
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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 
18
// ------------------------------------------------------------------------
 
19
 
 
20
#include <string>
 
21
#include <cstdio>
 
22
 
 
23
#include "kvu_dbc.h"
 
24
#include "kvu_inttypes.h"
 
25
 
 
26
#include "samplebuffer.h"
 
27
#include "samplebuffer_functions.h"
 
28
#include "eca-test-case.h"
 
29
 
 
30
using namespace std;
 
31
 
 
32
/**
 
33
 * Unit test for SAMPLE_BUFFER
 
34
 */
 
35
class SAMPLE_BUFFER_TEST : public ECA_TEST_CASE {
 
36
 
 
37
protected:
 
38
 
 
39
  virtual string do_name(void) const { return("SAMPLE_BUFFER"); }
 
40
  virtual void do_run(void);
 
41
 
 
42
public:
 
43
 
 
44
  virtual ~SAMPLE_BUFFER_TEST(void) { }
 
45
 
 
46
private:
 
47
 
 
48
};
 
49
 
 
50
void SAMPLE_BUFFER_TEST::do_run(void)
 
51
{
 
52
  const int bufsize = 1024;
 
53
  const int channels = 12;
 
54
  const SAMPLE_BUFFER::sample_t multiplier = 100.1f;
 
55
 
 
56
  std::fprintf(stdout, "%s: tests for SAMPLE_BUFFER class\n",
 
57
               __FILE__);
 
58
 
 
59
  /* case: multiply_by */
 
60
  {
 
61
    std::fprintf(stdout, "%s: multiply_by\n",
 
62
                 __FILE__);
 
63
    SAMPLE_BUFFER sbuf_orig (bufsize, channels);
 
64
    SAMPLE_BUFFER sbuf_ref (bufsize, channels);
 
65
    SAMPLE_BUFFER sbuf_test (bufsize, channels);
 
66
 
 
67
    SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_orig);
 
68
    
 
69
    sbuf_test.copy_all_content(sbuf_orig);
 
70
    sbuf_ref.copy_all_content(sbuf_orig);
 
71
    
 
72
    sbuf_test.multiply_by(multiplier);
 
73
    sbuf_ref.multiply_by_ref(multiplier);
 
74
    
 
75
    if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) {
 
76
      ECA_TEST_FAILURE("optimized multiple_by");
 
77
    }
 
78
  }
 
79
 
 
80
  /* case: copy_all_content */
 
81
  {
 
82
    std::fprintf(stdout, "%s: copy_all_content\n",
 
83
                 __FILE__);
 
84
 
 
85
    SAMPLE_BUFFER sbuf_orig (bufsize, channels);
 
86
    SAMPLE_BUFFER sbuf_ref (bufsize, channels);
 
87
    SAMPLE_BUFFER sbuf_test (bufsize, channels);
 
88
 
 
89
    SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_orig);
 
90
 
 
91
    /* note: copy_all_content should modify the destination
 
92
     *       channel and sample counts to match those of
 
93
     *       the source object. */
 
94
    sbuf_test.number_of_channels(0);
 
95
    sbuf_test.length_in_samples(1);
 
96
 
 
97
    sbuf_test.copy_all_content(sbuf_orig);
 
98
    sbuf_ref.copy_matching_channels(sbuf_orig);
 
99
 
 
100
    if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) { 
 
101
      ECA_TEST_FAILURE("copy_all_content");
 
102
    }
 
103
  }
 
104
 
 
105
  /* case: multiply_by */
 
106
  {
 
107
    std::fprintf(stdout, "%s: add_matching_channels\n",
 
108
                 __FILE__);
 
109
    SAMPLE_BUFFER sbuf_orig (bufsize, channels);
 
110
    SAMPLE_BUFFER sbuf_ref (bufsize, channels);
 
111
    SAMPLE_BUFFER sbuf_test (bufsize, channels);
 
112
 
 
113
    SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_orig);
 
114
 
 
115
    sbuf_test.copy_all_content(sbuf_orig);
 
116
    sbuf_ref.copy_all_content(sbuf_orig);
 
117
 
 
118
    sbuf_test.add_matching_channels(sbuf_orig);
 
119
    sbuf_ref.add_matching_channels_ref(sbuf_orig);
 
120
    
 
121
    if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) { 
 
122
      ECA_TEST_FAILURE("optimized add_matching_channels");
 
123
    }
 
124
  }
 
125
}