Jean-Marc Valin | 8b2ff0d | 2009-10-17 21:40:10 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2007-2008 CSIRO |
| 2 | Copyright (c) 2007-2008 Xiph.Org Foundation |
| 3 | Written by Jean-Marc Valin */ |
Jean-Marc Valin | 4d0a7d0 | 2008-02-07 12:24:26 +1100 | [diff] [blame] | 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: |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 8 | |
Jean-Marc Valin | 4d0a7d0 | 2008-02-07 12:24:26 +1100 | [diff] [blame] | 9 | - Redistributions of source code must retain the above copyright |
| 10 | notice, this list of conditions and the following disclaimer. |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 11 | |
Jean-Marc Valin | 4d0a7d0 | 2008-02-07 12:24:26 +1100 | [diff] [blame] | 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. |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 15 | |
Jean-Marc Valin | 4d0a7d0 | 2008-02-07 12:24:26 +1100 | [diff] [blame] | 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 |
Jean-Marc Valin | cb05e7c | 2012-04-20 16:40:24 -0400 | [diff] [blame] | 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
| 20 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
Jean-Marc Valin | 4d0a7d0 | 2008-02-07 12:24:26 +1100 | [diff] [blame] | 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 | */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 28 | |
Jean-Marc Valin | 4d0a7d0 | 2008-02-07 12:24:26 +1100 | [diff] [blame] | 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. |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 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 |
Jean-Marc Valin | 4d0a7d0 | 2008-02-07 12:24:26 +1100 | [diff] [blame] | 35 | (might as well use the same FFT everywhere). |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 36 | |
Jean-Marc Valin | 4d0a7d0 | 2008-02-07 12:24:26 +1100 | [diff] [blame] | 37 | The algorithm is similar to (and inspired from) Fabrice Bellard's |
| 38 | MDCT implementation in FFMPEG, but has differences in signs, ordering |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 39 | and scaling in many places. |
Jean-Marc Valin | 4d0a7d0 | 2008-02-07 12:24:26 +1100 | [diff] [blame] | 40 | */ |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 41 | |
Jean-Marc Valin | 81b38c2 | 2008-02-29 21:08:49 +1100 | [diff] [blame] | 42 | #ifndef MDCT_H |
| 43 | #define MDCT_H |
| 44 | |
Gregory Maxwell | de0b532 | 2012-07-18 12:12:35 -0400 | [diff] [blame] | 45 | #include "opus_defines.h" |
Jean-Marc Valin | 4d0a7d0 | 2008-02-07 12:24:26 +1100 | [diff] [blame] | 46 | #include "kiss_fft.h" |
Jean-Marc Valin | 4989c12 | 2008-04-22 12:18:36 +1000 | [diff] [blame] | 47 | #include "arch.h" |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 48 | |
| 49 | typedef struct { |
Jean-Marc Valin | 4d0a7d0 | 2008-02-07 12:24:26 +1100 | [diff] [blame] | 50 | int n; |
Jean-Marc Valin | 72513f3 | 2010-07-07 21:26:38 -0400 | [diff] [blame] | 51 | int maxshift; |
Jean-Marc Valin | 31b189b | 2010-08-25 21:21:43 -0400 | [diff] [blame] | 52 | const kiss_fft_state *kfft[4]; |
Gregory Maxwell | de0b532 | 2012-07-18 12:12:35 -0400 | [diff] [blame] | 53 | const kiss_twiddle_scalar * OPUS_RESTRICT trig; |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 54 | } mdct_lookup; |
| 55 | |
Viswanath Puttagunta | bae8545 | 2015-05-15 12:42:26 -0500 | [diff] [blame] | 56 | #if defined(HAVE_ARM_NE10) |
Viswanath Puttagunta | f48abe8 | 2015-05-15 12:42:19 -0500 | [diff] [blame] | 57 | #include "arm/mdct_arm.h" |
| 58 | #endif |
| 59 | |
| 60 | |
| 61 | int clt_mdct_init(mdct_lookup *l,int N, int maxshift, int arch); |
| 62 | void clt_mdct_clear(mdct_lookup *l, int arch); |
Jean-Marc Valin | e6b7465 | 2008-02-20 18:01:08 +1100 | [diff] [blame] | 63 | |
Jean-Marc Valin | 66c612e | 2011-08-15 14:08:57 -0400 | [diff] [blame] | 64 | /** Compute a forward MDCT and scale by 4/N, trashes the input array */ |
Viswanath Puttagunta | f48abe8 | 2015-05-15 12:42:19 -0500 | [diff] [blame] | 65 | void clt_mdct_forward_c(const mdct_lookup *l, kiss_fft_scalar *in, |
| 66 | kiss_fft_scalar * OPUS_RESTRICT out, |
| 67 | const opus_val16 *window, int overlap, |
| 68 | int shift, int stride, int arch); |
Jean-Marc Valin | e6b7465 | 2008-02-20 18:01:08 +1100 | [diff] [blame] | 69 | |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 70 | /** Compute a backward MDCT (no scaling) and performs weighted overlap-add |
Jean-Marc Valin | 3ccf3a5 | 2008-04-22 17:08:59 +1000 | [diff] [blame] | 71 | (scales implicitly by 1/2) */ |
Viswanath Puttagunta | 19c5406 | 2015-05-15 12:42:20 -0500 | [diff] [blame] | 72 | void clt_mdct_backward_c(const mdct_lookup *l, kiss_fft_scalar *in, |
Gregory Maxwell | de4a2dd | 2012-07-20 12:08:29 -0400 | [diff] [blame] | 73 | kiss_fft_scalar * OPUS_RESTRICT out, |
Viswanath Puttagunta | 19c5406 | 2015-05-15 12:42:20 -0500 | [diff] [blame] | 74 | const opus_val16 * OPUS_RESTRICT window, |
| 75 | int overlap, int shift, int stride, int arch); |
Jean-Marc Valin | 6359089 | 2007-11-29 17:01:16 +1100 | [diff] [blame] | 76 | |
Viswanath Puttagunta | f48abe8 | 2015-05-15 12:42:19 -0500 | [diff] [blame] | 77 | #if !defined(OVERRIDE_OPUS_MDCT) |
| 78 | /* Is run-time CPU detection enabled on this platform? */ |
Viswanath Puttagunta | bae8545 | 2015-05-15 12:42:26 -0500 | [diff] [blame] | 79 | #if defined(OPUS_HAVE_RTCD) && defined(HAVE_ARM_NE10) |
Viswanath Puttagunta | f48abe8 | 2015-05-15 12:42:19 -0500 | [diff] [blame] | 80 | |
| 81 | extern void (*const CLT_MDCT_FORWARD_IMPL[OPUS_ARCHMASK+1])( |
| 82 | const mdct_lookup *l, kiss_fft_scalar *in, |
| 83 | kiss_fft_scalar * OPUS_RESTRICT out, const opus_val16 *window, |
| 84 | int overlap, int shift, int stride, int arch); |
| 85 | |
| 86 | #define clt_mdct_forward(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) \ |
| 87 | ((*CLT_MDCT_FORWARD_IMPL[(arch)&OPUS_ARCHMASK])(_l, _in, _out, \ |
| 88 | _window, _overlap, _shift, \ |
| 89 | _stride, _arch)) |
Viswanath Puttagunta | 19c5406 | 2015-05-15 12:42:20 -0500 | [diff] [blame] | 90 | |
| 91 | extern void (*const CLT_MDCT_BACKWARD_IMPL[OPUS_ARCHMASK+1])( |
| 92 | const mdct_lookup *l, kiss_fft_scalar *in, |
| 93 | kiss_fft_scalar * OPUS_RESTRICT out, const opus_val16 *window, |
| 94 | int overlap, int shift, int stride, int arch); |
| 95 | |
| 96 | #define clt_mdct_backward(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) \ |
| 97 | (*CLT_MDCT_BACKWARD_IMPL[(arch)&OPUS_ARCHMASK])(_l, _in, _out, \ |
| 98 | _window, _overlap, _shift, \ |
| 99 | _stride, _arch) |
| 100 | |
Viswanath Puttagunta | bae8545 | 2015-05-15 12:42:26 -0500 | [diff] [blame] | 101 | #else /* if defined(OPUS_HAVE_RTCD) && defined(HAVE_ARM_NE10) */ |
Viswanath Puttagunta | f48abe8 | 2015-05-15 12:42:19 -0500 | [diff] [blame] | 102 | |
| 103 | #define clt_mdct_forward(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) \ |
| 104 | clt_mdct_forward_c(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) |
| 105 | |
Viswanath Puttagunta | 19c5406 | 2015-05-15 12:42:20 -0500 | [diff] [blame] | 106 | #define clt_mdct_backward(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) \ |
| 107 | clt_mdct_backward_c(_l, _in, _out, _window, _overlap, _shift, _stride, _arch) |
| 108 | |
Viswanath Puttagunta | ba8713c | 2015-05-15 12:42:25 -0500 | [diff] [blame] | 109 | #endif /* end if defined(OPUS_HAVE_RTCD) && defined(HAVE_ARM_NE10) && !defined(FIXED_POINT) */ |
Viswanath Puttagunta | f48abe8 | 2015-05-15 12:42:19 -0500 | [diff] [blame] | 110 | #endif /* end if !defined(OVERRIDE_OPUS_MDCT) */ |
| 111 | |
Jean-Marc Valin | 81b38c2 | 2008-02-29 21:08:49 +1100 | [diff] [blame] | 112 | #endif |