| 1 | /*---------------------------------------------------------------------------- |
| 2 | ChucK Strongly-timed Audio Programming Language |
| 3 | Compiler, Virtual Machine, and Synthesis Engine |
| 4 | |
| 5 | Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved. |
| 6 | http://chuck.stanford.edu/ |
| 7 | http://chuck.cs.princeton.edu/ |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the dual-license terms of EITHER the MIT License OR the GNU |
| 11 | General Public License (the latter as published by the Free Software |
| 12 | Foundation; either version 2 of the License or, at your option, any |
| 13 | later version). |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful and/or |
| 16 | interesting, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 17 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | MIT Licence and/or the GNU General Public License for details. |
| 19 | |
| 20 | You should have received a copy of the MIT License and the GNU General |
| 21 | Public License (GPL) along with this program; a copy of the GPL can also |
| 22 | be obtained by writing to the Free Software Foundation, Inc., 59 Temple |
| 23 | Place, Suite 330, Boston, MA 02111-1307 U.S.A. |
| 24 | -----------------------------------------------------------------------------*/ |
| 25 | |
| 26 | //----------------------------------------------------------------------------- |
| 27 | // name: util_xform.h |
| 28 | // desc: transform utilities |
| 29 | // |
| 30 | // authors: Ge Wang ([email protected] | [email protected]) |
| 31 | // Perry R. Cook ([email protected]) |
| 32 | // FFT - from CARL distribution |
| 33 | // date: 11.27.2003 |
| 34 | //----------------------------------------------------------------------------- |
| 35 | #ifndef __UTIL_XFORM_H__ |
| 36 | #define __UTIL_XFORM_H__ |
| 37 | |
| 38 | #include <math.h> |
| 39 | #include "chuck_def.h" |
| 40 | |
| 41 | // our float type |
| 42 | #define FLOAT_XFORM SAMPLE |
| 43 | |
| 44 | // complex absolute value |
| 45 | #define cmp_abs(x) ( sqrt( (x).re * (x).re + (x).im * (x).im ) ) |
| 46 | #define __modulus(x) cmp_abs(x) |
| 47 | #define __phase(x) ( atan2((double)(x).im, (double)(x).re) ) |
| 48 | |
| 49 | #define FFT_FORWARD 1 |
| 50 | #define FFT_INVERSE 0 |
| 51 | #define make_window hanning |
| 52 | |
| 53 | // c linkage |
| 54 | #if defined(_cplusplus) || defined(__cplusplus) |
| 55 | extern "C" { |
| 56 | #endif |
| 57 | |
| 58 | // make the window |
| 59 | void hanning( FLOAT_XFORM * window, unsigned long length ); |
| 60 | void hamming( FLOAT_XFORM * window, unsigned long length ); |
| 61 | void blackman( FLOAT_XFORM * window, unsigned long length ); |
| 62 | void bartlett( FLOAT_XFORM * window, unsigned long length ); |
| 63 | // apply the window |
| 64 | void apply_window( FLOAT_XFORM * data, FLOAT_XFORM * window, unsigned long length ); |
| 65 | |
| 66 | // real fft, N must be power of 2 |
| 67 | void rfft( FLOAT_XFORM * x, long N, unsigned int forward ); |
| 68 | // complex fft, NC must be power of 2 |
| 69 | void cfft( FLOAT_XFORM * x, long NC, unsigned int forward ); |
| 70 | |
| 71 | // type II dct, often referred to as "the dct" |
| 72 | void the_dct( FLOAT_XFORM * x, unsigned long N, FLOAT_XFORM * out, unsigned long Nout ); |
| 73 | // generates NxN type II dct matrix |
| 74 | void the_dct_matrix( FLOAT_XFORM ** out, unsigned long N ); |
| 75 | // type III dct, often referred to as "the inverse_dct" |
| 76 | void the_inverse_dct( FLOAT_XFORM * x, unsigned long N, FLOAT_XFORM * out, unsigned long Nout ); |
| 77 | // generates NxN type II dct matrix |
| 78 | void the_inverse_dct_matrix( FLOAT_XFORM ** out, unsigned long N ); |
| 79 | |
| 80 | // apply dct from matrix |
| 81 | void the_dct_now( FLOAT_XFORM * x, FLOAT_XFORM ** matrix, unsigned long N, FLOAT_XFORM * out, unsigned long Nout ); |
| 82 | // apply inverse dct from matrix |
| 83 | void the_inverse_dct_now( FLOAT_XFORM * x, FLOAT_XFORM ** matrix, unsigned long N, FLOAT_XFORM * out, unsigned long Nout ); |
| 84 | |
| 85 | // c linkage |
| 86 | #if ( defined( __cplusplus ) || defined( _cplusplus ) ) |
| 87 | } |
| 88 | #endif |
| 89 | |
| 90 | #endif |