~ubuntu-branches/ubuntu/oneiric/faac/oneiric

« back to all changes in this revision

Viewing changes to libfaac/kiss_fft/_kiss_fft_guts.h

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-01-06 22:47:35 UTC
  • mfrom: (0.1.3 hoary) (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080106224735-jhb3ptzjfm2j7n89
Tags: 1.26-0.1ubuntu1
* Sync from debian-multimedia
* Ubuntu Changes:
 - Maintainer Spec
 - Versioned mp4v2 dep

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 2003-2004, Mark Borgerding
 
3
 
 
4
All rights reserved.
 
5
 
 
6
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 
7
 
 
8
    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 
9
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 
10
    * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 
11
 
 
12
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
13
*/
 
14
 
 
15
/* kiss_fft.h
 
16
   defines kiss_fft_scalar as either short or a float type
 
17
   and defines
 
18
   typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
 
19
#include "kiss_fft.h"
 
20
 
 
21
 
 
22
#define MAXFACTORS 32
 
23
/* e.g. an fft of length 128 has 4 factors 
 
24
 as far as kissfft is concerned
 
25
 4*4*4*2
 
26
 */
 
27
 
 
28
struct kiss_fft_state{
 
29
    int nfft;
 
30
    int inverse;
 
31
    int factors[2*MAXFACTORS];
 
32
    kiss_fft_cpx twiddles[1];
 
33
};
 
34
 
 
35
/*
 
36
  Explanation of macros dealing with complex math:
 
37
 
 
38
   C_MUL(m,a,b)         : m = a*b
 
39
   C_FIXDIV( c , div )  : if a fixed point impl., c /= div. noop otherwise
 
40
   C_SUB( res, a,b)     : res = a - b
 
41
   C_SUBFROM( res , a)  : res -= a
 
42
   C_ADDTO( res , a)    : res += a
 
43
 * */
 
44
#ifdef FIXED_POINT
 
45
 
 
46
#   define smul(a,b) ( (long)(a)*(b) )
 
47
#   define sround( x )  (short)( ( (x) + (1<<14) ) >>15 )
 
48
 
 
49
#   define S_MUL(a,b) sround( smul(a,b) )
 
50
 
 
51
#   define C_MUL(m,a,b) \
 
52
      do{ (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \
 
53
          (m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0)
 
54
 
 
55
#   define C_FIXDIV(c,div) \
 
56
    do{ (c).r /= div; (c).i /=div; }while(0)
 
57
 
 
58
#   define C_MULBYSCALAR( c, s ) \
 
59
    do{ (c).r =  sround( smul( (c).r , s ) ) ;\
 
60
        (c).i =  sround( smul( (c).i , s ) ) ; }while(0)
 
61
 
 
62
#else  /* not FIXED_POINT*/
 
63
 
 
64
#   define S_MUL(a,b) ( (a)*(b) )
 
65
#define C_MUL(m,a,b) \
 
66
    do{ (m).r = (a).r*(b).r - (a).i*(b).i;\
 
67
        (m).i = (a).r*(b).i + (a).i*(b).r; }while(0)
 
68
#   define C_FIXDIV(c,div) /* NOOP */
 
69
#   define C_MULBYSCALAR( c, s ) \
 
70
    do{ (c).r *= (s);\
 
71
        (c).i *= (s); }while(0)
 
72
#endif
 
73
 
 
74
#define  C_ADD( res, a,b)\
 
75
    do {    (res).r=(a).r+(b).r;  (res).i=(a).i+(b).i;  }while(0)
 
76
#define  C_SUB( res, a,b)\
 
77
    do {    (res).r=(a).r-(b).r;  (res).i=(a).i-(b).i;  }while(0)
 
78
#define C_ADDTO( res , a)\
 
79
    do {    (res).r += (a).r;  (res).i += (a).i;  }while(0)
 
80
#define C_SUBFROM( res , a)\
 
81
    do {    (res).r -= (a).r;  (res).i -= (a).i;  }while(0)
 
82
 
 
83
static 
 
84
void kf_cexp(kiss_fft_cpx * x,double phase) /* returns e ** (j*phase)   */
 
85
{
 
86
#ifdef FIXED_POINT
 
87
    x->r = (kiss_fft_scalar) (32767 * cos (phase));
 
88
    x->i = (kiss_fft_scalar) (32767 * sin (phase));
 
89
#else
 
90
    x->r = cos (phase);
 
91
    x->i = sin (phase);
 
92
#endif
 
93
}
 
94
 
 
95
/* a debugging function */
 
96
#define pcpx(c)\
 
97
    fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) )