You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.6KB

  1. /*
  2. * AC-3 DSP utils
  3. * Copyright (c) 2011 Justin Ruggles
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; 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. typedef struct AC3DSPContext {
  25. /**
  26. * Set each encoded exponent in a block to the minimum of itself and the
  27. * exponents in the same frequency bin of up to 5 following blocks.
  28. * @param exp pointer to the start of the current block of exponents.
  29. * constraints: align 16
  30. * @param num_reuse_blocks number of blocks that will reuse exponents from the current block.
  31. * constraints: range 0 to 5
  32. * @param nb_coefs number of frequency coefficients.
  33. */
  34. void (*ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
  35. /**
  36. * Calculate the maximum MSB of the absolute value of each element in an
  37. * array of int16_t.
  38. * @param src input array
  39. * constraints: align 16. values must be in range [-32767,32767]
  40. * @param len number of values in the array
  41. * constraints: multiple of 16 greater than 0
  42. * @return a value with the same MSB as max(abs(src[]))
  43. */
  44. int (*ac3_max_msb_abs_int16)(const int16_t *src, int len);
  45. /**
  46. * Left-shift each value in an array of int16_t by a specified amount.
  47. * @param src input array
  48. * constraints: align 16
  49. * @param len number of values in the array
  50. * constraints: multiple of 32 greater than 0
  51. * @param shift left shift amount
  52. * constraints: range [0,15]
  53. */
  54. void (*ac3_lshift_int16)(int16_t *src, unsigned int len, unsigned int shift);
  55. /**
  56. * Right-shift each value in an array of int32_t by a specified amount.
  57. * @param src input array
  58. * constraints: align 16
  59. * @param len number of values in the array
  60. * constraints: multiple of 16 greater than 0
  61. * @param shift right shift amount
  62. * constraints: range [0,31]
  63. */
  64. void (*ac3_rshift_int32)(int32_t *src, unsigned int len, unsigned int shift);
  65. /**
  66. * Convert an array of float in range [-1.0,1.0] to int32_t with range
  67. * [-(1<<24),(1<<24)]
  68. *
  69. * @param dst destination array of int32_t.
  70. * constraints: 16-byte aligned
  71. * @param src source array of float.
  72. * constraints: 16-byte aligned
  73. * @param len number of elements to convert.
  74. * constraints: multiple of 32 greater than zero
  75. */
  76. void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len);
  77. /**
  78. * Calculate bit allocation pointers.
  79. * The SNR is the difference between the masking curve and the signal. AC-3
  80. * uses this value for each frequency bin to allocate bits. The snroffset
  81. * parameter is a global adjustment to the SNR for all bins.
  82. *
  83. * @param[in] mask masking curve
  84. * @param[in] psd signal power for each frequency bin
  85. * @param[in] start starting bin location
  86. * @param[in] end ending bin location
  87. * @param[in] snr_offset SNR adjustment
  88. * @param[in] floor noise floor
  89. * @param[in] bap_tab look-up table for bit allocation pointers
  90. * @param[out] bap bit allocation pointers
  91. */
  92. void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end,
  93. int snr_offset, int floor,
  94. const uint8_t *bap_tab, uint8_t *bap);
  95. /**
  96. * Calculate the number of bits needed to encode a set of mantissas.
  97. */
  98. int (*compute_mantissa_size)(int mant_cnt[5], uint8_t *bap, int nb_coefs);
  99. void (*extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs);
  100. } AC3DSPContext;
  101. void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact);
  102. void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact);
  103. void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact);
  104. #endif /* AVCODEC_AC3DSP_H */