~ubuntu-branches/ubuntu/saucy/faust/saucy

« back to all changes in this revision

Viewing changes to architecture/math.lib

  • Committer: Package Import Robot
  • Author(s): Mario Lang
  • Date: 2012-04-04 13:52:01 UTC
  • mfrom: (1.1.6) (3.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120404135201-hpsrk87x3hga94tc
Tags: 0.9.46-2
* Fix "ftbfs with GCC-4.7":
  - debian/patches/unistd: Include <unistd.h> where necessary.
    (Closes: #667163)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************************************
 
2
 ************************************************************************
 
3
        FAUST library file
 
4
        Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
 
5
    ---------------------------------------------------------------------
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU Lesser General Public License as 
 
8
        published by the Free Software Foundation; either version 2.1 of the 
 
9
        License, or (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU Lesser General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU Lesser General Public
 
17
        License along with the GNU C Library; if not, write to the Free
 
18
        Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
19
        02111-1307 USA. 
 
20
 ************************************************************************
 
21
 ************************************************************************/
 
22
 
 
23
declare name "Math Library";
 
24
declare author "GRAME";
 
25
declare copyright "GRAME";
 
26
declare version "1.0";
 
27
declare license "LGPL"; 
 
28
 
1
29
//--------------------------------------------------------------------------------
2
30
//                                              Mathematic library for Faust
3
31
 
12
40
 
13
41
// -- Utilities and constants
14
42
 
15
 
SR                      = fconstant(int fSamplingFreq, <math.h>);
 
43
SR                      = min(192000, max(1, fconstant(int fSamplingFreq, <math.h>)));
16
44
BS          = fvariable(int count, <math.h>);
17
45
 
18
46
PI          = 3.1415926535897932385;
97
125
isnan           = ffunction(int isnan (float),<math.h>,"");
98
126
nextafter       = ffunction(float nextafter(float, float),<math.h>,"");
99
127
 
100
 
 
 
128
// Pattern matching functions to count and access the elements of a list
 
129
// USAGE :      count ((10,20,30,40))   -> 4  
 
130
//                      take  (3,(10,20,30,40)) -> 30
 
131
// 
 
132
 
 
133
count ((xs, xxs)) = 1 + count(xxs);
 
134
count (xx) = 1;
 
135
 
 
136
take (1, (xs, xxs))     = xs;
 
137
take (1, xs)                    = xs;
 
138
take (nn, (xs, xxs))    = take (nn-1, xxs);
 
139
 
 
140
// linear interpolation between two signals 
 
141
interpolate(i) = *(1.0-i),*(i) : +; 
 
142
 
 
143
// if-then-else implemented with a select2. 
 
144
if(cond,thn,els) = select2(cond,els,thn);
 
145
 
 
146
 
 
147
//-----------------------------------------------------------------
 
148
// countdown(count,trig) 
 
149
// start counting down from count, count-1,...,0 when trig > 0
 
150
//-----------------------------------------------------------------
 
151
countdown(count, trig)  = \(c).(if(trig>0, count, max(0, c-1))) ~_;
 
152
 
 
153
//-----------------------------------------------------------------
 
154
// countup(count,trig) 
 
155
// start counting down from 0, 1, ... count-1, count when trig > 0
 
156
//-----------------------------------------------------------------
 
157
countup(count, trig)    = \(c).(if(trig>0, 0, min(count, c+1))) ~_;
 
158
 
 
159
/******************************************************************
 
160
 *  Hadamard matrix function
 
161
 *  Implementation contributed by Remy Muller
 
162
 *****************************************************************/
 
163
 
 
164
// bus(n) : n parallel cables
 
165
bus(2) = _,_; // avoids a lot of "bus(1)" labels in block diagrams
 
166
bus(n) = par(i, n, _);
 
167
 
 
168
// selector(i,n) : select ith cable among n
 
169
selector(i,n) = par(j, n, S(i, j))    with { S(i,i) = _; S(i,j) = !; };
 
170
 
 
171
// interleave(m,n) : interleave m*n cables : x(0), x(m), x(2m), ..., x(1),x(1+m), x(1+2m)...
 
172
//interleave(m,n) = bus(m*n) <: par(i, m, par(j, n, selector(i+j*m,m*n))); 
 
173
 
 
174
// interleave(row,col) : interleave row*col cables from column order to row order.
 
175
// input : x(0), x(1), x(2) ..., x(row*col-1)
 
176
// output: x(0+0*row), x(0+1*row), x(0+2*row), ..., x(1+0*row), x(1+1*row), x(1+2*row), ...
 
177
interleave(row,col) = bus(row*col) <: par(r, row, par(c, col, selector(r+c*row,row*col))); 
 
178
 
 
179
// butterfly(n) : addition then substraction of interleaved signals : 
 
180
butterfly(n) = bus(n) <: interleave(n/2,2), interleave(n/2,2) : par(i, n/2, +), par(i, n/2, -);
 
181
 
 
182
// hadamard(n) : hadamard matrix function of size n = 2^k
 
183
hadamard(2) = butterfly(2);
 
184
hadamard(n) = butterfly(n) : (hadamard(n/2) , hadamard(n/2));