ac3dsp.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * AC-3 DSP functions
  3. * Copyright (c) 2011 Justin Ruggles
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef AVCODEC_AC3DSP_H
  22. #define AVCODEC_AC3DSP_H
  23. #include <stdint.h>
  24. /**
  25. * Number of mantissa bits written for each bap value.
  26. * bap values with fractional bits are set to 0 and are calculated separately.
  27. */
  28. extern const uint16_t ff_ac3_bap_bits[16];
  29. typedef struct AC3DSPContext {
  30. /**
  31. * Set each encoded exponent in a block to the minimum of itself and the
  32. * exponents in the same frequency bin of up to 5 following blocks.
  33. * @param exp pointer to the start of the current block of exponents.
  34. * constraints: align 16
  35. * @param num_reuse_blocks number of blocks that will reuse exponents from the current block.
  36. * constraints: range 0 to 5
  37. * @param nb_coefs number of frequency coefficients.
  38. */
  39. void (*ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
  40. /**
  41. * Calculate the maximum MSB of the absolute value of each element in an
  42. * array of int16_t.
  43. * @param src input array
  44. * constraints: align 16. values must be in range [-32767,32767]
  45. * @param len number of values in the array
  46. * constraints: multiple of 16 greater than 0
  47. * @return a value with the same MSB as max(abs(src[]))
  48. */
  49. int (*ac3_max_msb_abs_int16)(const int16_t *src, int len);
  50. /**
  51. * Left-shift each value in an array of int16_t by a specified amount.
  52. * @param src input array
  53. * constraints: align 16
  54. * @param len number of values in the array
  55. * constraints: multiple of 32 greater than 0
  56. * @param shift left shift amount
  57. * constraints: range [0,15]
  58. */
  59. void (*ac3_lshift_int16)(int16_t *src, unsigned int len, unsigned int shift);
  60. /**
  61. * Right-shift each value in an array of int32_t by a specified amount.
  62. * @param src input array
  63. * constraints: align 16
  64. * @param len number of values in the array
  65. * constraints: multiple of 16 greater than 0
  66. * @param shift right shift amount
  67. * constraints: range [0,31]
  68. */
  69. void (*ac3_rshift_int32)(int32_t *src, unsigned int len, unsigned int shift);
  70. /**
  71. * Convert an array of float in range [-1.0,1.0] to int32_t with range
  72. * [-(1<<24),(1<<24)]
  73. *
  74. * @param dst destination array of int32_t.
  75. * constraints: 16-byte aligned
  76. * @param src source array of float.
  77. * constraints: 16-byte aligned
  78. * @param len number of elements to convert.
  79. * constraints: multiple of 32 greater than zero
  80. */
  81. void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len);
  82. /**
  83. * Calculate bit allocation pointers.
  84. * The SNR is the difference between the masking curve and the signal. AC-3
  85. * uses this value for each frequency bin to allocate bits. The snroffset
  86. * parameter is a global adjustment to the SNR for all bins.
  87. *
  88. * @param[in] mask masking curve
  89. * @param[in] psd signal power for each frequency bin
  90. * @param[in] start starting bin location
  91. * @param[in] end ending bin location
  92. * @param[in] snr_offset SNR adjustment
  93. * @param[in] floor noise floor
  94. * @param[in] bap_tab look-up table for bit allocation pointers
  95. * @param[out] bap bit allocation pointers
  96. */
  97. void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end,
  98. int snr_offset, int floor,
  99. const uint8_t *bap_tab, uint8_t *bap);
  100. /**
  101. * Update bap counts using the supplied array of bap.
  102. *
  103. * @param[out] mant_cnt bap counts for 1 block
  104. * @param[in] bap array of bap, pointing to start coef bin
  105. * @param[in] len number of elements to process
  106. */
  107. void (*update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len);
  108. /**
  109. * Calculate the number of bits needed to encode a set of mantissas.
  110. *
  111. * @param[in] mant_cnt bap counts for all blocks
  112. * @return mantissa bit count
  113. */
  114. int (*compute_mantissa_size)(uint16_t mant_cnt[6][16]);
  115. void (*extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs);
  116. void (*sum_square_butterfly_int32)(int64_t sum[4], const int32_t *coef0,
  117. const int32_t *coef1, int len);
  118. void (*sum_square_butterfly_float)(float sum[4], const float *coef0,
  119. const float *coef1, int len);
  120. int out_channels;
  121. int in_channels;
  122. void (*downmix)(float **samples, float **matrix, int len);
  123. void (*downmix_fixed)(int32_t **samples, int16_t **matrix, int len);
  124. /**
  125. * Apply symmetric window in 16-bit fixed-point.
  126. * @param output destination array
  127. * constraints: 16-byte aligned
  128. * @param input source array
  129. * constraints: 16-byte aligned
  130. * @param window window array
  131. * constraints: 16-byte aligned, at least len/2 elements
  132. * @param len full window length
  133. * constraints: multiple of ? greater than zero
  134. */
  135. void (*apply_window_int16)(int16_t *output, const int16_t *input,
  136. const int16_t *window, unsigned int len);
  137. } AC3DSPContext;
  138. void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact);
  139. void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact);
  140. void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact);
  141. void ff_ac3dsp_init_mips(AC3DSPContext *c, int bit_exact);
  142. void ff_ac3dsp_downmix(AC3DSPContext *c, float **samples, float **matrix,
  143. int out_ch, int in_ch, int len);
  144. void ff_ac3dsp_downmix_fixed(AC3DSPContext *c, int32_t **samples, int16_t **matrix,
  145. int out_ch, int in_ch, int len);
  146. void ff_ac3dsp_set_downmix_x86(AC3DSPContext *c);
  147. #endif /* AVCODEC_AC3DSP_H */