blob: 160ae4e0f3baac5014471e33a09f6f3867dad168 [file] [log] [blame]
Jean-Marc Valin8b2ff0d2009-10-17 21:40:10 -04001/* Copyright (c) 2007-2008 CSIRO
2 Copyright (c) 2007-2008 Xiph.Org Foundation
3 Written by Jean-Marc Valin */
Jean-Marc Valin4d0a7d02008-02-07 12:24:26 +11004/*
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 Maxwell71d39ad2011-07-30 00:00:29 -04008
Jean-Marc Valin4d0a7d02008-02-07 12:24:26 +11009 - Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
Gregory Maxwell71d39ad2011-07-30 00:00:29 -040011
Jean-Marc Valin4d0a7d02008-02-07 12:24:26 +110012 - 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 Maxwell71d39ad2011-07-30 00:00:29 -040015
Jean-Marc Valin4d0a7d02008-02-07 12:24:26 +110016 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 Valincb05e7c2012-04-20 16:40:24 -040019 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 Valin4d0a7d02008-02-07 12:24:26 +110021 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 Valin63590892007-11-29 17:01:16 +110028
Jean-Marc Valin4d0a7d02008-02-07 12:24:26 +110029/* 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 Maxwell71d39ad2011-07-30 00:00:29 -040032
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 Valin4d0a7d02008-02-07 12:24:26 +110035 (might as well use the same FFT everywhere).
Gregory Maxwell71d39ad2011-07-30 00:00:29 -040036
Jean-Marc Valin4d0a7d02008-02-07 12:24:26 +110037 The algorithm is similar to (and inspired from) Fabrice Bellard's
38 MDCT implementation in FFMPEG, but has differences in signs, ordering
Gregory Maxwell71d39ad2011-07-30 00:00:29 -040039 and scaling in many places.
Jean-Marc Valin4d0a7d02008-02-07 12:24:26 +110040*/
Jean-Marc Valin63590892007-11-29 17:01:16 +110041
Jean-Marc Valin81b38c22008-02-29 21:08:49 +110042#ifndef MDCT_H
43#define MDCT_H
44
Gregory Maxwellde0b5322012-07-18 12:12:35 -040045#include "opus_defines.h"
Jean-Marc Valin4d0a7d02008-02-07 12:24:26 +110046#include "kiss_fft.h"
Jean-Marc Valin4989c122008-04-22 12:18:36 +100047#include "arch.h"
Jean-Marc Valin63590892007-11-29 17:01:16 +110048
49typedef struct {
Jean-Marc Valin4d0a7d02008-02-07 12:24:26 +110050 int n;
Jean-Marc Valin72513f32010-07-07 21:26:38 -040051 int maxshift;
Jean-Marc Valin31b189b2010-08-25 21:21:43 -040052 const kiss_fft_state *kfft[4];
Gregory Maxwellde0b5322012-07-18 12:12:35 -040053 const kiss_twiddle_scalar * OPUS_RESTRICT trig;
Jean-Marc Valin63590892007-11-29 17:01:16 +110054} mdct_lookup;
55
Viswanath Puttaguntabae85452015-05-15 12:42:26 -050056#if defined(HAVE_ARM_NE10)
Viswanath Puttaguntaf48abe82015-05-15 12:42:19 -050057#include "arm/mdct_arm.h"
58#endif
59
60
61int clt_mdct_init(mdct_lookup *l,int N, int maxshift, int arch);
62void clt_mdct_clear(mdct_lookup *l, int arch);
Jean-Marc Valine6b74652008-02-20 18:01:08 +110063
Jean-Marc Valin66c612e2011-08-15 14:08:57 -040064/** Compute a forward MDCT and scale by 4/N, trashes the input array */
Viswanath Puttaguntaf48abe82015-05-15 12:42:19 -050065void 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 Valine6b74652008-02-20 18:01:08 +110069
Gregory Maxwell71d39ad2011-07-30 00:00:29 -040070/** Compute a backward MDCT (no scaling) and performs weighted overlap-add
Jean-Marc Valin3ccf3a52008-04-22 17:08:59 +100071 (scales implicitly by 1/2) */
Viswanath Puttagunta19c54062015-05-15 12:42:20 -050072void clt_mdct_backward_c(const mdct_lookup *l, kiss_fft_scalar *in,
Gregory Maxwellde4a2dd2012-07-20 12:08:29 -040073 kiss_fft_scalar * OPUS_RESTRICT out,
Viswanath Puttagunta19c54062015-05-15 12:42:20 -050074 const opus_val16 * OPUS_RESTRICT window,
75 int overlap, int shift, int stride, int arch);
Jean-Marc Valin63590892007-11-29 17:01:16 +110076
Viswanath Puttaguntaf48abe82015-05-15 12:42:19 -050077#if !defined(OVERRIDE_OPUS_MDCT)
78/* Is run-time CPU detection enabled on this platform? */
Viswanath Puttaguntabae85452015-05-15 12:42:26 -050079#if defined(OPUS_HAVE_RTCD) && defined(HAVE_ARM_NE10)
Viswanath Puttaguntaf48abe82015-05-15 12:42:19 -050080
81extern 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 Puttagunta19c54062015-05-15 12:42:20 -050090
91extern 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 Puttaguntabae85452015-05-15 12:42:26 -0500101#else /* if defined(OPUS_HAVE_RTCD) && defined(HAVE_ARM_NE10) */
Viswanath Puttaguntaf48abe82015-05-15 12:42:19 -0500102
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 Puttagunta19c54062015-05-15 12:42:20 -0500106#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 Puttaguntaba8713c2015-05-15 12:42:25 -0500109#endif /* end if defined(OPUS_HAVE_RTCD) && defined(HAVE_ARM_NE10) && !defined(FIXED_POINT) */
Viswanath Puttaguntaf48abe82015-05-15 12:42:19 -0500110#endif /* end if !defined(OVERRIDE_OPUS_MDCT) */
111
Jean-Marc Valin81b38c22008-02-29 21:08:49 +1100112#endif