tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mdct.h (4771B)


      1 /* Copyright (c) 2007-2008 CSIRO
      2   Copyright (c) 2007-2008 Xiph.Org Foundation
      3   Written by Jean-Marc Valin */
      4 /*
      5   Redistribution and use in source and binary forms, with or without
      6   modification, are permitted provided that the following conditions
      7   are met:
      8 
      9   - Redistributions of source code must retain the above copyright
     10   notice, this list of conditions and the following disclaimer.
     11 
     12   - Redistributions in binary form must reproduce the above copyright
     13   notice, this list of conditions and the following disclaimer in the
     14   documentation and/or other materials provided with the distribution.
     15 
     16   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
     20   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     21   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     22   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     23   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     24   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     25   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     26   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28 
     29 /* This is a simple MDCT implementation that uses a N/4 complex FFT
     30   to do most of the work. It should be relatively straightforward to
     31   plug in pretty much and FFT here.
     32 
     33   This replaces the Vorbis FFT (and uses the exact same API), which
     34   was a bit too messy and that was ending up duplicating code
     35   (might as well use the same FFT everywhere).
     36 
     37   The algorithm is similar to (and inspired from) Fabrice Bellard's
     38   MDCT implementation in FFMPEG, but has differences in signs, ordering
     39   and scaling in many places.
     40 */
     41 
     42 #ifndef MDCT_H
     43 #define MDCT_H
     44 
     45 #include "opus_defines.h"
     46 #include "kiss_fft.h"
     47 #include "arch.h"
     48 
     49 typedef struct {
     50   int n;
     51   int maxshift;
     52   const kiss_fft_state *kfft[4];
     53   const kiss_twiddle_scalar * OPUS_RESTRICT trig;
     54 } mdct_lookup;
     55 
     56 #if defined(HAVE_ARM_NE10)
     57 #include "arm/mdct_arm.h"
     58 #endif
     59 
     60 int clt_mdct_init(mdct_lookup *l,int N, int maxshift, int arch);
     61 void clt_mdct_clear(mdct_lookup *l, int arch);
     62 
     63 /** Compute a forward MDCT and scale by 4/N, trashes the input array */
     64 void clt_mdct_forward_c(const mdct_lookup *l, kiss_fft_scalar *in,
     65                        kiss_fft_scalar * OPUS_RESTRICT out,
     66                        const celt_coef *window, int overlap,
     67                        int shift, int stride, int arch);
     68 
     69 /** Compute a backward MDCT (no scaling) and performs weighted overlap-add
     70    (scales implicitly by 1/2) */
     71 void clt_mdct_backward_c(const mdct_lookup *l, kiss_fft_scalar *in,
     72      kiss_fft_scalar * OPUS_RESTRICT out,
     73      const celt_coef * OPUS_RESTRICT window,
     74      int overlap, int shift, int stride, int arch);
     75 
     76 #if !defined(OVERRIDE_OPUS_MDCT)
     77 /* Is run-time CPU detection enabled on this platform? */
     78 #if defined(OPUS_HAVE_RTCD) && defined(HAVE_ARM_NE10)
     79 
     80 extern void (*const CLT_MDCT_FORWARD_IMPL[OPUS_ARCHMASK+1])(
     81      const mdct_lookup *l, kiss_fft_scalar *in,
     82      kiss_fft_scalar * OPUS_RESTRICT out, const celt_coef *window,
     83      int overlap, int shift, int stride, int arch);
     84 
     85 #define clt_mdct_forward(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) \
     86   ((*CLT_MDCT_FORWARD_IMPL[(arch)&OPUS_ARCHMASK])(_l, _in, _out, \
     87                                                   _window, _overlap, _shift, \
     88                                                   _stride, _arch))
     89 
     90 extern void (*const CLT_MDCT_BACKWARD_IMPL[OPUS_ARCHMASK+1])(
     91      const mdct_lookup *l, kiss_fft_scalar *in,
     92      kiss_fft_scalar * OPUS_RESTRICT out, const celt_coef *window,
     93      int overlap, int shift, int stride, int arch);
     94 
     95 #define clt_mdct_backward(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) \
     96   (*CLT_MDCT_BACKWARD_IMPL[(arch)&OPUS_ARCHMASK])(_l, _in, _out, \
     97                                                   _window, _overlap, _shift, \
     98                                                   _stride, _arch)
     99 
    100 #else /* if defined(OPUS_HAVE_RTCD) && defined(HAVE_ARM_NE10) */
    101 
    102 #define clt_mdct_forward(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) \
    103   clt_mdct_forward_c(_l, _in, _out, _window, _overlap, _shift, _stride, _arch)
    104 
    105 #define clt_mdct_backward(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) \
    106   clt_mdct_backward_c(_l, _in, _out, _window, _overlap, _shift, _stride, _arch)
    107 
    108 #endif /* end if defined(OPUS_HAVE_RTCD) && defined(HAVE_ARM_NE10) && !defined(FIXED_POINT) */
    109 #endif /* end if !defined(OVERRIDE_OPUS_MDCT) */
    110 
    111 #endif