annotate src/vamp-sdk/ext/vamp_kiss_fft_guts.h @ 535:45b2bd15d8ae

Show error code if library can't be loaded
author Chris Cannam
date Tue, 03 Mar 2020 11:47:52 +0000
parents 90571dcc371a
children
rev   line source
Chris@501 1 #ifndef VAMP_KISS_FFT__GUTS_H
Chris@501 2 #define VAMP_KISS_FFT__GUTS_H
Chris@434 3 /*
Chris@434 4 Copyright (c) 2003-2010, Mark Borgerding
Chris@434 5
Chris@434 6 All rights reserved.
Chris@434 7
Chris@434 8 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Chris@434 9
Chris@434 10 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Chris@434 11 * 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.
Chris@434 12 * 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.
Chris@434 13
Chris@434 14 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.
Chris@434 15 */
Chris@434 16
Chris@434 17 /* kiss_fft.h
Chris@434 18 defines kiss_fft_scalar as either short or a float type
Chris@434 19 and defines
Chris@434 20 typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
Chris@501 21 #include "vamp_kiss_fft.h"
Chris@434 22 #include <limits.h>
Chris@434 23
Chris@434 24 #define MAXFACTORS 32
Chris@434 25 /* e.g. an fft of length 128 has 4 factors
Chris@434 26 as far as kissfft is concerned
Chris@434 27 4*4*4*2
Chris@434 28 */
Chris@434 29
Chris@501 30 struct vamp_kiss_fft_state{
Chris@434 31 int nfft;
Chris@434 32 int inverse;
Chris@434 33 int factors[2*MAXFACTORS];
Chris@501 34 vamp_kiss_fft_cpx twiddles[1];
Chris@434 35 };
Chris@434 36
Chris@434 37 /*
Chris@434 38 Explanation of macros dealing with complex math:
Chris@434 39
Chris@434 40 C_MUL(m,a,b) : m = a*b
Chris@434 41 C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise
Chris@434 42 C_SUB( res, a,b) : res = a - b
Chris@434 43 C_SUBFROM( res , a) : res -= a
Chris@434 44 C_ADDTO( res , a) : res += a
Chris@434 45 * */
Chris@434 46
Chris@434 47 # define S_MUL(a,b) ( (a)*(b) )
Chris@434 48 #define C_MUL(m,a,b) \
Chris@434 49 do{ (m).r = (a).r*(b).r - (a).i*(b).i;\
Chris@434 50 (m).i = (a).r*(b).i + (a).i*(b).r; }while(0)
Chris@434 51 # define C_FIXDIV(c,div) /* NOOP */
Chris@434 52 # define C_MULBYSCALAR( c, s ) \
Chris@434 53 do{ (c).r *= (s);\
Chris@434 54 (c).i *= (s); }while(0)
Chris@434 55
Chris@434 56 # define CHECK_OVERFLOW_OP(a,op,b) /* noop */
Chris@434 57
Chris@434 58 #define C_ADD( res, a,b)\
Chris@434 59 do { \
Chris@434 60 CHECK_OVERFLOW_OP((a).r,+,(b).r)\
Chris@434 61 CHECK_OVERFLOW_OP((a).i,+,(b).i)\
Chris@434 62 (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \
Chris@434 63 }while(0)
Chris@434 64 #define C_SUB( res, a,b)\
Chris@434 65 do { \
Chris@434 66 CHECK_OVERFLOW_OP((a).r,-,(b).r)\
Chris@434 67 CHECK_OVERFLOW_OP((a).i,-,(b).i)\
Chris@434 68 (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \
Chris@434 69 }while(0)
Chris@434 70 #define C_ADDTO( res , a)\
Chris@434 71 do { \
Chris@434 72 CHECK_OVERFLOW_OP((res).r,+,(a).r)\
Chris@434 73 CHECK_OVERFLOW_OP((res).i,+,(a).i)\
Chris@434 74 (res).r += (a).r; (res).i += (a).i;\
Chris@434 75 }while(0)
Chris@434 76
Chris@434 77 #define C_SUBFROM( res , a)\
Chris@434 78 do {\
Chris@434 79 CHECK_OVERFLOW_OP((res).r,-,(a).r)\
Chris@434 80 CHECK_OVERFLOW_OP((res).i,-,(a).i)\
Chris@434 81 (res).r -= (a).r; (res).i -= (a).i; \
Chris@434 82 }while(0)
Chris@434 83
Chris@434 84
Chris@501 85 # define VAMP_KISS_FFT_COS(phase) (vamp_kiss_fft_scalar) cos(phase)
Chris@501 86 # define VAMP_KISS_FFT_SIN(phase) (vamp_kiss_fft_scalar) sin(phase)
Chris@434 87 # define HALF_OF(x) ((x)*.5)
Chris@434 88
Chris@434 89 #define kf_cexp(x,phase) \
Chris@434 90 do{ \
Chris@501 91 (x)->r = VAMP_KISS_FFT_COS(phase);\
Chris@501 92 (x)->i = VAMP_KISS_FFT_SIN(phase);\
Chris@434 93 }while(0)
Chris@434 94
Chris@501 95 #define VAMP_KISS_FFT_TMP_ALLOC(nbytes) VAMP_KISS_FFT_MALLOC(nbytes)
Chris@501 96 #define VAMP_KISS_FFT_TMP_FREE(ptr) VAMP_KISS_FFT_FREE(ptr)
Chris@434 97
Chris@434 98 /* a debugging function */
Chris@434 99 #define pcpx(c)\
Chris@434 100 fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) )
Chris@434 101
Chris@434 102 #endif