annotate src/opus-1.3/celt/kiss_fft.h @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 7aeed7906520
children
rev   line source
Chris@69 1 /*Copyright (c) 2003-2004, Mark Borgerding
Chris@69 2 Lots of modifications by Jean-Marc Valin
Chris@69 3 Copyright (c) 2005-2007, Xiph.Org Foundation
Chris@69 4 Copyright (c) 2008, Xiph.Org Foundation, CSIRO
Chris@69 5
Chris@69 6 All rights reserved.
Chris@69 7
Chris@69 8 Redistribution and use in source and binary forms, with or without
Chris@69 9 modification, are permitted provided that the following conditions are met:
Chris@69 10
Chris@69 11 * Redistributions of source code must retain the above copyright notice,
Chris@69 12 this list of conditions and the following disclaimer.
Chris@69 13 * Redistributions in binary form must reproduce the above copyright notice,
Chris@69 14 this list of conditions and the following disclaimer in the
Chris@69 15 documentation and/or other materials provided with the distribution.
Chris@69 16
Chris@69 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Chris@69 18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Chris@69 19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Chris@69 20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Chris@69 21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Chris@69 22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Chris@69 23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Chris@69 24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Chris@69 25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Chris@69 26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Chris@69 27 POSSIBILITY OF SUCH DAMAGE.*/
Chris@69 28
Chris@69 29 #ifndef KISS_FFT_H
Chris@69 30 #define KISS_FFT_H
Chris@69 31
Chris@69 32 #include <stdlib.h>
Chris@69 33 #include <math.h>
Chris@69 34 #include "arch.h"
Chris@69 35 #include "cpu_support.h"
Chris@69 36
Chris@69 37 #ifdef __cplusplus
Chris@69 38 extern "C" {
Chris@69 39 #endif
Chris@69 40
Chris@69 41 #ifdef USE_SIMD
Chris@69 42 # include <xmmintrin.h>
Chris@69 43 # define kiss_fft_scalar __m128
Chris@69 44 #define KISS_FFT_MALLOC(nbytes) memalign(16,nbytes)
Chris@69 45 #else
Chris@69 46 #define KISS_FFT_MALLOC opus_alloc
Chris@69 47 #endif
Chris@69 48
Chris@69 49 #ifdef FIXED_POINT
Chris@69 50 #include "arch.h"
Chris@69 51
Chris@69 52 # define kiss_fft_scalar opus_int32
Chris@69 53 # define kiss_twiddle_scalar opus_int16
Chris@69 54
Chris@69 55
Chris@69 56 #else
Chris@69 57 # ifndef kiss_fft_scalar
Chris@69 58 /* default is float */
Chris@69 59 # define kiss_fft_scalar float
Chris@69 60 # define kiss_twiddle_scalar float
Chris@69 61 # define KF_SUFFIX _celt_single
Chris@69 62 # endif
Chris@69 63 #endif
Chris@69 64
Chris@69 65 typedef struct {
Chris@69 66 kiss_fft_scalar r;
Chris@69 67 kiss_fft_scalar i;
Chris@69 68 }kiss_fft_cpx;
Chris@69 69
Chris@69 70 typedef struct {
Chris@69 71 kiss_twiddle_scalar r;
Chris@69 72 kiss_twiddle_scalar i;
Chris@69 73 }kiss_twiddle_cpx;
Chris@69 74
Chris@69 75 #define MAXFACTORS 8
Chris@69 76 /* e.g. an fft of length 128 has 4 factors
Chris@69 77 as far as kissfft is concerned
Chris@69 78 4*4*4*2
Chris@69 79 */
Chris@69 80
Chris@69 81 typedef struct arch_fft_state{
Chris@69 82 int is_supported;
Chris@69 83 void *priv;
Chris@69 84 } arch_fft_state;
Chris@69 85
Chris@69 86 typedef struct kiss_fft_state{
Chris@69 87 int nfft;
Chris@69 88 opus_val16 scale;
Chris@69 89 #ifdef FIXED_POINT
Chris@69 90 int scale_shift;
Chris@69 91 #endif
Chris@69 92 int shift;
Chris@69 93 opus_int16 factors[2*MAXFACTORS];
Chris@69 94 const opus_int16 *bitrev;
Chris@69 95 const kiss_twiddle_cpx *twiddles;
Chris@69 96 arch_fft_state *arch_fft;
Chris@69 97 } kiss_fft_state;
Chris@69 98
Chris@69 99 #if defined(HAVE_ARM_NE10)
Chris@69 100 #include "arm/fft_arm.h"
Chris@69 101 #endif
Chris@69 102
Chris@69 103 /*typedef struct kiss_fft_state* kiss_fft_cfg;*/
Chris@69 104
Chris@69 105 /**
Chris@69 106 * opus_fft_alloc
Chris@69 107 *
Chris@69 108 * Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
Chris@69 109 *
Chris@69 110 * typical usage: kiss_fft_cfg mycfg=opus_fft_alloc(1024,0,NULL,NULL);
Chris@69 111 *
Chris@69 112 * The return value from fft_alloc is a cfg buffer used internally
Chris@69 113 * by the fft routine or NULL.
Chris@69 114 *
Chris@69 115 * If lenmem is NULL, then opus_fft_alloc will allocate a cfg buffer using malloc.
Chris@69 116 * The returned value should be free()d when done to avoid memory leaks.
Chris@69 117 *
Chris@69 118 * The state can be placed in a user supplied buffer 'mem':
Chris@69 119 * If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
Chris@69 120 * then the function places the cfg in mem and the size used in *lenmem
Chris@69 121 * and returns mem.
Chris@69 122 *
Chris@69 123 * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
Chris@69 124 * then the function returns NULL and places the minimum cfg
Chris@69 125 * buffer size in *lenmem.
Chris@69 126 * */
Chris@69 127
Chris@69 128 kiss_fft_state *opus_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, const kiss_fft_state *base, int arch);
Chris@69 129
Chris@69 130 kiss_fft_state *opus_fft_alloc(int nfft,void * mem,size_t * lenmem, int arch);
Chris@69 131
Chris@69 132 /**
Chris@69 133 * opus_fft(cfg,in_out_buf)
Chris@69 134 *
Chris@69 135 * Perform an FFT on a complex input buffer.
Chris@69 136 * for a forward FFT,
Chris@69 137 * fin should be f[0] , f[1] , ... ,f[nfft-1]
Chris@69 138 * fout will be F[0] , F[1] , ... ,F[nfft-1]
Chris@69 139 * Note that each element is complex and can be accessed like
Chris@69 140 f[k].r and f[k].i
Chris@69 141 * */
Chris@69 142 void opus_fft_c(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
Chris@69 143 void opus_ifft_c(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
Chris@69 144
Chris@69 145 void opus_fft_impl(const kiss_fft_state *st,kiss_fft_cpx *fout);
Chris@69 146 void opus_ifft_impl(const kiss_fft_state *st,kiss_fft_cpx *fout);
Chris@69 147
Chris@69 148 void opus_fft_free(const kiss_fft_state *cfg, int arch);
Chris@69 149
Chris@69 150
Chris@69 151 void opus_fft_free_arch_c(kiss_fft_state *st);
Chris@69 152 int opus_fft_alloc_arch_c(kiss_fft_state *st);
Chris@69 153
Chris@69 154 #if !defined(OVERRIDE_OPUS_FFT)
Chris@69 155 /* Is run-time CPU detection enabled on this platform? */
Chris@69 156 #if defined(OPUS_HAVE_RTCD) && (defined(HAVE_ARM_NE10))
Chris@69 157
Chris@69 158 extern int (*const OPUS_FFT_ALLOC_ARCH_IMPL[OPUS_ARCHMASK+1])(
Chris@69 159 kiss_fft_state *st);
Chris@69 160
Chris@69 161 #define opus_fft_alloc_arch(_st, arch) \
Chris@69 162 ((*OPUS_FFT_ALLOC_ARCH_IMPL[(arch)&OPUS_ARCHMASK])(_st))
Chris@69 163
Chris@69 164 extern void (*const OPUS_FFT_FREE_ARCH_IMPL[OPUS_ARCHMASK+1])(
Chris@69 165 kiss_fft_state *st);
Chris@69 166 #define opus_fft_free_arch(_st, arch) \
Chris@69 167 ((*OPUS_FFT_FREE_ARCH_IMPL[(arch)&OPUS_ARCHMASK])(_st))
Chris@69 168
Chris@69 169 extern void (*const OPUS_FFT[OPUS_ARCHMASK+1])(const kiss_fft_state *cfg,
Chris@69 170 const kiss_fft_cpx *fin, kiss_fft_cpx *fout);
Chris@69 171 #define opus_fft(_cfg, _fin, _fout, arch) \
Chris@69 172 ((*OPUS_FFT[(arch)&OPUS_ARCHMASK])(_cfg, _fin, _fout))
Chris@69 173
Chris@69 174 extern void (*const OPUS_IFFT[OPUS_ARCHMASK+1])(const kiss_fft_state *cfg,
Chris@69 175 const kiss_fft_cpx *fin, kiss_fft_cpx *fout);
Chris@69 176 #define opus_ifft(_cfg, _fin, _fout, arch) \
Chris@69 177 ((*OPUS_IFFT[(arch)&OPUS_ARCHMASK])(_cfg, _fin, _fout))
Chris@69 178
Chris@69 179 #else /* else for if defined(OPUS_HAVE_RTCD) && (defined(HAVE_ARM_NE10)) */
Chris@69 180
Chris@69 181 #define opus_fft_alloc_arch(_st, arch) \
Chris@69 182 ((void)(arch), opus_fft_alloc_arch_c(_st))
Chris@69 183
Chris@69 184 #define opus_fft_free_arch(_st, arch) \
Chris@69 185 ((void)(arch), opus_fft_free_arch_c(_st))
Chris@69 186
Chris@69 187 #define opus_fft(_cfg, _fin, _fout, arch) \
Chris@69 188 ((void)(arch), opus_fft_c(_cfg, _fin, _fout))
Chris@69 189
Chris@69 190 #define opus_ifft(_cfg, _fin, _fout, arch) \
Chris@69 191 ((void)(arch), opus_ifft_c(_cfg, _fin, _fout))
Chris@69 192
Chris@69 193 #endif /* end if defined(OPUS_HAVE_RTCD) && (defined(HAVE_ARM_NE10)) */
Chris@69 194 #endif /* end if !defined(OVERRIDE_OPUS_FFT) */
Chris@69 195
Chris@69 196 #ifdef __cplusplus
Chris@69 197 }
Chris@69 198 #endif
Chris@69 199
Chris@69 200 #endif