media/libopus/celt/kiss_fft.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*Copyright (c) 2003-2004, Mark Borgerding
michael@0 2 Lots of modifications by Jean-Marc Valin
michael@0 3 Copyright (c) 2005-2007, Xiph.Org Foundation
michael@0 4 Copyright (c) 2008, Xiph.Org Foundation, CSIRO
michael@0 5
michael@0 6 All rights reserved.
michael@0 7
michael@0 8 Redistribution and use in source and binary forms, with or without
michael@0 9 modification, are permitted provided that the following conditions are met:
michael@0 10
michael@0 11 * Redistributions of source code must retain the above copyright notice,
michael@0 12 this list of conditions and the following disclaimer.
michael@0 13 * Redistributions in binary form must reproduce the above copyright notice,
michael@0 14 this list of conditions and the following disclaimer in the
michael@0 15 documentation and/or other materials provided with the distribution.
michael@0 16
michael@0 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
michael@0 18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
michael@0 20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
michael@0 21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
michael@0 22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
michael@0 23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
michael@0 24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
michael@0 25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
michael@0 26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
michael@0 27 POSSIBILITY OF SUCH DAMAGE.*/
michael@0 28
michael@0 29 #ifndef KISS_FFT_H
michael@0 30 #define KISS_FFT_H
michael@0 31
michael@0 32 #include <stdlib.h>
michael@0 33 #include <math.h>
michael@0 34 #include "arch.h"
michael@0 35
michael@0 36 #ifdef __cplusplus
michael@0 37 extern "C" {
michael@0 38 #endif
michael@0 39
michael@0 40 #ifdef USE_SIMD
michael@0 41 # include <xmmintrin.h>
michael@0 42 # define kiss_fft_scalar __m128
michael@0 43 #define KISS_FFT_MALLOC(nbytes) memalign(16,nbytes)
michael@0 44 #else
michael@0 45 #define KISS_FFT_MALLOC opus_alloc
michael@0 46 #endif
michael@0 47
michael@0 48 #ifdef FIXED_POINT
michael@0 49 #include "arch.h"
michael@0 50
michael@0 51 # define kiss_fft_scalar opus_int32
michael@0 52 # define kiss_twiddle_scalar opus_int16
michael@0 53
michael@0 54
michael@0 55 #else
michael@0 56 # ifndef kiss_fft_scalar
michael@0 57 /* default is float */
michael@0 58 # define kiss_fft_scalar float
michael@0 59 # define kiss_twiddle_scalar float
michael@0 60 # define KF_SUFFIX _celt_single
michael@0 61 # endif
michael@0 62 #endif
michael@0 63
michael@0 64 typedef struct {
michael@0 65 kiss_fft_scalar r;
michael@0 66 kiss_fft_scalar i;
michael@0 67 }kiss_fft_cpx;
michael@0 68
michael@0 69 typedef struct {
michael@0 70 kiss_twiddle_scalar r;
michael@0 71 kiss_twiddle_scalar i;
michael@0 72 }kiss_twiddle_cpx;
michael@0 73
michael@0 74 #define MAXFACTORS 8
michael@0 75 /* e.g. an fft of length 128 has 4 factors
michael@0 76 as far as kissfft is concerned
michael@0 77 4*4*4*2
michael@0 78 */
michael@0 79
michael@0 80 typedef struct kiss_fft_state{
michael@0 81 int nfft;
michael@0 82 #ifndef FIXED_POINT
michael@0 83 kiss_fft_scalar scale;
michael@0 84 #endif
michael@0 85 int shift;
michael@0 86 opus_int16 factors[2*MAXFACTORS];
michael@0 87 const opus_int16 *bitrev;
michael@0 88 const kiss_twiddle_cpx *twiddles;
michael@0 89 } kiss_fft_state;
michael@0 90
michael@0 91 /*typedef struct kiss_fft_state* kiss_fft_cfg;*/
michael@0 92
michael@0 93 /**
michael@0 94 * opus_fft_alloc
michael@0 95 *
michael@0 96 * Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
michael@0 97 *
michael@0 98 * typical usage: kiss_fft_cfg mycfg=opus_fft_alloc(1024,0,NULL,NULL);
michael@0 99 *
michael@0 100 * The return value from fft_alloc is a cfg buffer used internally
michael@0 101 * by the fft routine or NULL.
michael@0 102 *
michael@0 103 * If lenmem is NULL, then opus_fft_alloc will allocate a cfg buffer using malloc.
michael@0 104 * The returned value should be free()d when done to avoid memory leaks.
michael@0 105 *
michael@0 106 * The state can be placed in a user supplied buffer 'mem':
michael@0 107 * If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
michael@0 108 * then the function places the cfg in mem and the size used in *lenmem
michael@0 109 * and returns mem.
michael@0 110 *
michael@0 111 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
michael@0 112 * then the function returns NULL and places the minimum cfg
michael@0 113 * buffer size in *lenmem.
michael@0 114 * */
michael@0 115
michael@0 116 kiss_fft_state *opus_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, const kiss_fft_state *base);
michael@0 117
michael@0 118 kiss_fft_state *opus_fft_alloc(int nfft,void * mem,size_t * lenmem);
michael@0 119
michael@0 120 /**
michael@0 121 * opus_fft(cfg,in_out_buf)
michael@0 122 *
michael@0 123 * Perform an FFT on a complex input buffer.
michael@0 124 * for a forward FFT,
michael@0 125 * fin should be f[0] , f[1] , ... ,f[nfft-1]
michael@0 126 * fout will be F[0] , F[1] , ... ,F[nfft-1]
michael@0 127 * Note that each element is complex and can be accessed like
michael@0 128 f[k].r and f[k].i
michael@0 129 * */
michael@0 130 void opus_fft(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
michael@0 131 void opus_ifft(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
michael@0 132
michael@0 133 void opus_fft_free(const kiss_fft_state *cfg);
michael@0 134
michael@0 135 #ifdef __cplusplus
michael@0 136 }
michael@0 137 #endif
michael@0 138
michael@0 139 #endif

mercurial