~ubuntu-branches/ubuntu/vivid/aeolus/vivid

« back to all changes in this revision

Viewing changes to source/asection.cc

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-04-19 19:12:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100419191251-hgarjfcdfl7c0ryl
Tags: 0.8.4-3
debian/patches/01-makefile.patch: Drop -march=native flag, it isn't valid
for Debian packages as the results are unpredictable, thanks to
Bastian Blank for reporting this (Closes: #578278).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>
 
3
    
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the Free Software
 
16
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
*/
 
18
 
 
19
 
 
20
#include <stdio.h>
 
21
#include <string.h>
 
22
#include <math.h>
 
23
#include "asection.h"
 
24
 
 
25
 
 
26
extern float exp2ap (float);
 
27
 
 
28
 
 
29
#define N (MIXLEN * PERIOD)
 
30
 
 
31
 
 
32
void Diffuser::init (int size, float c)
 
33
{
 
34
    _size = size;
 
35
    _data = new float [size];
 
36
    memset (_data, 0, size * sizeof (float));
 
37
    _i = 0;
 
38
    _c = c;
 
39
}
 
40
 
 
41
 
 
42
void Diffuser::fini (void)
 
43
{
 
44
    delete[] _data;
 
45
}
 
46
 
 
47
 
 
48
float Asection::_refl [16] =
 
49
{
 
50
    0.250f, 0.440f, 0.615f, 0.940f,
 
51
    0.200f, 0.370f, 0.560f, 0.900f,
 
52
    0.230f, 0.400f, 0.500f, 0.920f,
 
53
    0.280f, 0.460f, 0.690f, 0.960f
 
54
};
 
55
 
 
56
 
 
57
Asection::Asection (float fsam) : _fsam (fsam)
 
58
{
 
59
    _base = new float [NCHANN * N]; 
 
60
    memset (_base, 0, NCHANN * N * sizeof (float));
 
61
 
 
62
    _offs0 = 0;
 
63
    _sw = _sx = _sy = 0.0f;
 
64
    _dif0.init ((int)(fsam * 0.017f), 0.5f);
 
65
    _dif1.init ((int)(fsam * 0.029f), 0.5f);
 
66
    _dif2.init ((int)(fsam * 0.023f), 0.5f);
 
67
    _dif3.init ((int)(fsam * 0.013f), 0.5f);
 
68
 
 
69
    _apar [AZIMUTH]._val =  0.0f;
 
70
    _apar [AZIMUTH]._min = -0.5f;
 
71
    _apar [AZIMUTH]._max =  0.5f;
 
72
    _apar [STWIDTH]._val = 0.8f;
 
73
    _apar [STWIDTH]._min = 0.0f;
 
74
    _apar [STWIDTH]._max = 1.0f;
 
75
    _apar [DIRECT]._val = 0.56f;
 
76
    _apar [DIRECT]._min = 0.00f;
 
77
    _apar [DIRECT]._max = 1.00f;
 
78
    _apar [REFLECT]._val = 0.25f;
 
79
    _apar [REFLECT]._min = 0.00f;
 
80
    _apar [REFLECT]._max = 1.00f;
 
81
    _apar [REVERB]._val = 0.32f;
 
82
    _apar [REVERB]._min = 0.00f;
 
83
    _apar [REVERB]._max = 1.00f;
 
84
}
 
85
 
 
86
 
 
87
Asection::~Asection (void) 
 
88
{
 
89
    delete[] _base;
 
90
    _dif0.fini ();
 
91
    _dif1.fini ();
 
92
    _dif2.fini ();
 
93
    _dif3.fini ();
 
94
}
 
95
 
 
96
 
 
97
void Asection::set_size (float time) 
 
98
{
 
99
    int   i, d;
 
100
    float r;
 
101
 
 
102
    r = (time * _fsam);
 
103
    if (r > N - PERIOD) r = N - PERIOD;
 
104
    for (i = 0; i < 16; i++)
 
105
    {
 
106
        d = (int)(r * _refl [i]);
 
107
        d = (_offs0 - d * PERIOD) & (N - 1);
 
108
        _offs [i] = d + (i >> 2) * N;
 
109
    }
 
110
}
 
111
 
 
112
 
 
113
void Asection::process (float vol, float *W, float *X, float *Y, float *R) 
 
114
{
 
115
    int     i;
 
116
    float   s, d, g, gw, gr, gx1, gy1, gx2, gy2;
 
117
    float   *p, t0, t1, t2, t3;
 
118
    float   x [PERIOD];
 
119
    float   y [PERIOD];
 
120
 
 
121
    gw = vol * _apar [DIRECT]._val;   
 
122
    g = 0.45f * _apar [STWIDTH]._val;
 
123
    s = 0.5f + g * (1 - g);
 
124
    d = g - 0.5f;
 
125
    gx1 = gw * (s - d);
 
126
    gy1 = gw * (s + d);
 
127
    g = 0.25f * _apar [STWIDTH]._val;
 
128
    s = 0.5f + g * (1 - g);
 
129
    d = g - 0.5f;
 
130
    gx2 = gw * (s - d);
 
131
    gy2 = gw * (s + d);
 
132
    p = _base + _offs0;
 
133
    gr = 0.5f * _apar [REVERB]._val;
 
134
    for (i = 0; i < PERIOD; i++)
 
135
    {
 
136
        t0 = p [0 * N];
 
137
        t1 = p [1 * N];
 
138
        t2 = p [2 * N];
 
139
        t3 = p [3 * N];
 
140
        p++;
 
141
        s = t0 + t1 + t2 + t3; 
 
142
        R [i] += gr * s; 
 
143
        W [i] += gw * s;
 
144
        x [i] = gx1 * (t3 + t0) + gx2 * (t2 + t1);
 
145
        y [i] = gy1 * (t3 - t0) + gy2 * (t2 - t1);
 
146
    }
 
147
 
 
148
    gr = vol * _apar [REFLECT]._val;
 
149
    p = _base;
 
150
    for (i = 0; i < PERIOD; i++)
 
151
    {
 
152
        t0 = _dif0.process (p [_offs [1]] + p [_offs  [5]] + p [_offs [11]] + p [_offs [15]] + 1e-20f);  
 
153
        t1 = _dif1.process (p [_offs [0]] + p [_offs  [4]] + p [_offs [10]] + p [_offs [14]] + 1e-20f);  
 
154
        t2 = _dif2.process (p [_offs [2]] + p [_offs  [6]] + p [_offs  [8]] + p [_offs [12]] + 2e-20f);  
 
155
        t3 = _dif3.process (p [_offs [3]] + p [_offs  [7]] + p [_offs  [9]] + p [_offs [13]] + 2e-20f);  
 
156
        p++;
 
157
        s = t0 + t1 + t2 + t3; 
 
158
        _sw += 0.5f * (s - _sw);
 
159
        _sx += 0.5f * (0.4f * (t0 + t3) + 0.6f * (t2 + t1) - _sx);
 
160
        _sy += 0.5f * (0.9f * (t0 - t3) + 0.8f * (t2 - t1) - _sy);
 
161
        W [i] += gr * _sw;
 
162
        x [i] += gr * _sx;
 
163
        y [i] += gr * _sy;
 
164
    }
 
165
 
 
166
    g = 6.283184f * _apar [AZIMUTH]._val;   
 
167
    gx1 = cosf (g);
 
168
    gy1 = sinf (g);
 
169
    for (i = 0; i < PERIOD; i++)
 
170
    {
 
171
        X [i] += gx1 * x [i] + gy1 * y [i];
 
172
        Y [i] += gx1 * y [i] - gy1 * x [i];
 
173
    }
 
174
 
 
175
    _offs0 = (_offs0 + PERIOD) & (N - 1);
 
176
    for (i = 0; i < 16; i++) _offs [i] = ((_offs [i] + PERIOD) & (N - 1)) + (i >> 2) * N;
 
177
    p = _base + _offs0;
 
178
    memset (p + 0 * N, 0, PERIOD * sizeof (float)); 
 
179
    memset (p + 1 * N, 0, PERIOD * sizeof (float)); 
 
180
    memset (p + 2 * N, 0, PERIOD * sizeof (float)); 
 
181
    memset (p + 3 * N, 0, PERIOD * sizeof (float)); 
 
182
}
 
183