Alexandre Lision | 744f742 | 2013-09-25 11:39:37 -0400 | [diff] [blame] | 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 | int clt_mdct_init(mdct_lookup *l,int N, int maxshift); |
| 57 | void clt_mdct_clear(mdct_lookup *l); |
| 58 | |
| 59 | /** Compute a forward MDCT and scale by 4/N, trashes the input array */ |
| 60 | void clt_mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, |
| 61 | kiss_fft_scalar * OPUS_RESTRICT out, |
| 62 | const opus_val16 *window, int overlap, int shift, int stride); |
| 63 | |
| 64 | /** Compute a backward MDCT (no scaling) and performs weighted overlap-add |
| 65 | (scales implicitly by 1/2) */ |
| 66 | void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, |
| 67 | kiss_fft_scalar * OPUS_RESTRICT out, |
| 68 | const opus_val16 * OPUS_RESTRICT window, int overlap, int shift, int stride); |
| 69 | |
| 70 | #endif |