mdct.h 4.7 KB

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