tx.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVUTIL_TX_H
  19. #define AVUTIL_TX_H
  20. #include <stdint.h>
  21. #include <stddef.h>
  22. typedef struct AVTXContext AVTXContext;
  23. typedef struct AVComplexFloat {
  24. float re, im;
  25. } AVComplexFloat;
  26. typedef struct AVComplexDouble {
  27. double re, im;
  28. } AVComplexDouble;
  29. typedef struct AVComplexInt32 {
  30. int32_t re, im;
  31. } AVComplexInt32;
  32. enum AVTXType {
  33. /**
  34. * Standard complex to complex FFT with sample data type AVComplexFloat.
  35. * Output is not 1/len normalized. Scaling currently unsupported.
  36. * The stride parameter is ignored.
  37. */
  38. AV_TX_FLOAT_FFT = 0,
  39. /**
  40. * Standard MDCT with sample data type of float and a scale type of
  41. * float. Length is the frame size, not the window size (which is 2x frame)
  42. * For forward transforms, the stride specifies the spacing between each
  43. * sample in the output array in bytes. The input must be a flat array.
  44. * For inverse transforms, the stride specifies the spacing between each
  45. * sample in the input array in bytes. The output will be a flat array.
  46. * Stride must be a non-zero multiple of sizeof(float).
  47. * NOTE: the inverse transform is half-length, meaning the output will not
  48. * contain redundant data. This is what most codecs work with.
  49. */
  50. AV_TX_FLOAT_MDCT = 1,
  51. /**
  52. * Same as AV_TX_FLOAT_FFT with a data type of AVComplexDouble.
  53. */
  54. AV_TX_DOUBLE_FFT = 2,
  55. /**
  56. * Same as AV_TX_FLOAT_MDCT with data and scale type of double.
  57. * Stride must be a non-zero multiple of sizeof(double).
  58. */
  59. AV_TX_DOUBLE_MDCT = 3,
  60. /**
  61. * Same as AV_TX_FLOAT_FFT with a data type of AVComplexInt32.
  62. */
  63. AV_TX_INT32_FFT = 4,
  64. /**
  65. * Same as AV_TX_FLOAT_MDCT with data type of int32_t and scale type of float.
  66. * Only scale values less than or equal to 1.0 are supported.
  67. * Stride must be a non-zero multiple of sizeof(int32_t).
  68. */
  69. AV_TX_INT32_MDCT = 5,
  70. };
  71. /**
  72. * Function pointer to a function to perform the transform.
  73. *
  74. * @note Using a different context than the one allocated during av_tx_init()
  75. * is not allowed.
  76. *
  77. * @param s the transform context
  78. * @param out the output array
  79. * @param in the input array
  80. * @param stride the input or output stride in bytes
  81. *
  82. * The out and in arrays must be aligned to the maximum required by the CPU
  83. * architecture.
  84. * The stride must follow the constraints the transform type has specified.
  85. */
  86. typedef void (*av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride);
  87. /**
  88. * Flags for av_tx_init()
  89. */
  90. enum AVTXFlags {
  91. /**
  92. * Performs an in-place transformation on the input. The output argument
  93. * of av_tn_fn() MUST match the input. May be unsupported or slower for some
  94. * transform types.
  95. */
  96. AV_TX_INPLACE = 1ULL << 0,
  97. };
  98. /**
  99. * Initialize a transform context with the given configuration
  100. * (i)MDCTs with an odd length are currently not supported.
  101. *
  102. * @param ctx the context to allocate, will be NULL on error
  103. * @param tx pointer to the transform function pointer to set
  104. * @param type type the type of transform
  105. * @param inv whether to do an inverse or a forward transform
  106. * @param len the size of the transform in samples
  107. * @param scale pointer to the value to scale the output if supported by type
  108. * @param flags a bitmask of AVTXFlags or 0
  109. *
  110. * @return 0 on success, negative error code on failure
  111. */
  112. int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type,
  113. int inv, int len, const void *scale, uint64_t flags);
  114. /**
  115. * Frees a context and sets ctx to NULL, does nothing when ctx == NULL
  116. */
  117. void av_tx_uninit(AVTXContext **ctx);
  118. #endif /* AVUTIL_TX_H */