~ubuntu-branches/ubuntu/lucid/ecasound2.2/lucid

« back to all changes in this revision

Viewing changes to libecasound/audiofx_amplitude_test.h

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2009-11-02 18:22:35 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091102182235-4ngh7699dmkgonyu
Tags: 2.7.0-1
* New upstream release.
* Depend on libreadline-dev instead of libreadline5-dev by request of
  Mattias Klose. It's now libreadline6-dev. (closes: #553748)
* Update menu file to use section Applications/ instead of Apps/.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ------------------------------------------------------------------------
 
2
// audiofx_amplitu_test.h: Unit tests for EFFECT_AMPLIFY* classes
 
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 <cassert>
 
22
#include <cstdio>
 
23
#include <cstdlib>
 
24
#include <cstring>
 
25
#include <ctime>
 
26
 
 
27
#include "kvu_dbc.h"
 
28
#include "kvu_inttypes.h"
 
29
 
 
30
#include "audiofx_amplitude.h"
 
31
#include "samplebuffer_functions.h"
 
32
#include "eca-test-case.h"
 
33
 
 
34
using namespace std;
 
35
 
 
36
/**
 
37
 * Unit test for EFFECT_AMPLIFY
 
38
 */
 
39
class EFFECT_AMPLIFY_TEST : public ECA_TEST_CASE {
 
40
 
 
41
protected:
 
42
 
 
43
  virtual string do_name(void) const { return("EFFECT_AMPLIFY"); }
 
44
  virtual void do_run(void);
 
45
 
 
46
public:
 
47
 
 
48
  virtual ~EFFECT_AMPLIFY_TEST(void) { }
 
49
 
 
50
private:
 
51
 
 
52
};
 
53
 
 
54
void EFFECT_AMPLIFY_TEST::do_run(void)
 
55
{
 
56
  const int bufsize = 1024;
 
57
  const int channels = 12;
 
58
  const SAMPLE_BUFFER::sample_t multiplier = 112.1f;
 
59
 
 
60
  std::fprintf(stdout, "%s: tests for %s class\n",
 
61
               name().c_str(), __FILE__);
 
62
 
 
63
  /* case: multiply_by */
 
64
  {
 
65
    std::fprintf(stdout, "%s: EFFECT_AMPLIFY::process\n",
 
66
                 __FILE__);
 
67
    SAMPLE_BUFFER sbuf_test (bufsize, channels);
 
68
    SAMPLE_BUFFER sbuf_ref (bufsize, channels);
 
69
 
 
70
    EFFECT_AMPLIFY amp_test;
 
71
    EFFECT_AMPLIFY amp_ref;
 
72
    
 
73
    SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_ref);
 
74
    sbuf_test.copy_all_content(sbuf_ref);
 
75
 
 
76
    amp_test.init(&sbuf_test);
 
77
    amp_ref.init(&sbuf_ref);
 
78
    
 
79
    amp_test.set_parameter(1, multiplier);
 
80
    amp_ref.set_parameter(1, multiplier);
 
81
 
 
82
    amp_test.process();
 
83
    amp_ref.process_ref();
 
84
    
 
85
    if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) {
 
86
      ECA_TEST_FAILURE("optimized EFFECT_AMPLIFY");
 
87
    }
 
88
  }
 
89
}
 
90
 
 
91
/**
 
92
 * Unit test for EFFECT_AMPLIFY_CHANNEL
 
93
 */
 
94
class EFFECT_AMPLIFY_CHANNEL_TEST : public ECA_TEST_CASE {
 
95
 
 
96
protected:
 
97
 
 
98
  virtual string do_name(void) const { return("EFFECT_AMPLIFY_CHANNEL"); }
 
99
  virtual void do_run(void);
 
100
 
 
101
public:
 
102
 
 
103
  virtual ~EFFECT_AMPLIFY_CHANNEL_TEST(void) { }
 
104
 
 
105
private:
 
106
 
 
107
};
 
108
 
 
109
void EFFECT_AMPLIFY_CHANNEL_TEST::do_run(void)
 
110
{
 
111
  const int bufsize = 1024;
 
112
  const int channels = 12;
 
113
  const SAMPLE_BUFFER::sample_t multiplier = 112.1f;
 
114
 
 
115
  std::fprintf(stdout, "%s: tests for %s class\n",
 
116
               name().c_str(), __FILE__);
 
117
 
 
118
  /* case: process() */
 
119
  {
 
120
    std::fprintf(stdout, "%s: process()\n", __FILE__);
 
121
    SAMPLE_BUFFER sbuf_test (bufsize, channels);
 
122
    SAMPLE_BUFFER sbuf_ref (bufsize, channels);
 
123
 
 
124
    EFFECT_AMPLIFY_CHANNEL amp_test;
 
125
    EFFECT_AMPLIFY_CHANNEL amp_ref;
 
126
    
 
127
    SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_ref);
 
128
    sbuf_test.copy_all_content(sbuf_ref);
 
129
 
 
130
    amp_test.init(&sbuf_test);
 
131
    amp_ref.init(&sbuf_ref);
 
132
    
 
133
    amp_test.set_parameter(1, multiplier);
 
134
    amp_test.set_parameter(2, 3);
 
135
    amp_ref.set_parameter(1, multiplier);
 
136
    amp_ref.set_parameter(2, 3);
 
137
 
 
138
    amp_test.process();
 
139
    amp_ref.process_ref();
 
140
    
 
141
    if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) {
 
142
      ECA_TEST_FAILURE("optimized process()");
 
143
    }
 
144
  }
 
145
}