mdct.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright (c) 2007-2012 IETF Trust, CSIRO, Xiph.Org Foundation. All rights reserved.
  2. Written by Jean-Marc Valin */
  3. /*
  4. This file is extracted from RFC6716. Please see that RFC for additional
  5. information.
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions
  8. are met:
  9. - Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. - Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in the
  13. documentation and/or other materials provided with the distribution.
  14. - Neither the name of Internet Society, IETF or IETF Trust, nor the
  15. names of specific contributors, may be used to endorse or promote
  16. products derived from this software without specific prior written
  17. permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  22. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /* This is a simple MDCT implementation that uses a N/4 complex FFT
  31. to do most of the work. It should be relatively straightforward to
  32. plug in pretty much and FFT here.
  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. The algorithm is similar to (and inspired from) Fabrice Bellard's
  37. MDCT implementation in FFMPEG, but has differences in signs, ordering
  38. and scaling in many places.
  39. */
  40. #ifndef MDCT_H
  41. #define MDCT_H
  42. #include "kiss_fft.h"
  43. #include "arch.h"
  44. typedef struct {
  45. int n;
  46. int maxshift;
  47. const kiss_fft_state *kfft[4];
  48. const kiss_twiddle_scalar * restrict trig;
  49. } mdct_lookup;
  50. int clt_mdct_init(mdct_lookup *l,int N, int maxshift);
  51. void clt_mdct_clear(mdct_lookup *l);
  52. /** Compute a forward MDCT and scale by 4/N, trashes the input array */
  53. void clt_mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar *out,
  54. const opus_val16 *window, int overlap, int shift, int stride);
  55. /** Compute a backward MDCT (no scaling) and performs weighted overlap-add
  56. (scales implicitly by 1/2) */
  57. void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar *out,
  58. const opus_val16 * restrict window, int overlap, int shift, int stride);
  59. #endif