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.

158 lines
6.1KB

  1. /*
  2. * WMA compatible codec
  3. * Copyright (c) 2002-2007 The Libav Project
  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_WMA_H
  22. #define AVCODEC_WMA_H
  23. #include "libavutil/float_dsp.h"
  24. #include "fft.h"
  25. #include "get_bits.h"
  26. #include "put_bits.h"
  27. /* size of blocks */
  28. #define BLOCK_MIN_BITS 7
  29. #define BLOCK_MAX_BITS 11
  30. #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
  31. #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
  32. /* XXX: find exact max size */
  33. #define HIGH_BAND_MAX_SIZE 16
  34. #define NB_LSP_COEFS 10
  35. /* XXX: is it a suitable value ? */
  36. #define MAX_CODED_SUPERFRAME_SIZE 16384
  37. #define MAX_CHANNELS 2
  38. #define NOISE_TAB_SIZE 8192
  39. #define LSP_POW_BITS 7
  40. // FIXME should be in wmadec
  41. #define VLCBITS 9
  42. #define VLCMAX ((22 + VLCBITS - 1) / VLCBITS)
  43. typedef float WMACoef; ///< type for decoded coefficients, int16_t would be enough for wma 1/2
  44. typedef struct CoefVLCTable {
  45. int n; ///< total number of codes
  46. int max_level;
  47. const uint32_t *huffcodes; ///< VLC bit values
  48. const uint8_t *huffbits; ///< VLC bit size
  49. const uint16_t *levels; ///< table to build run/level tables
  50. } CoefVLCTable;
  51. typedef struct WMACodecContext {
  52. AVCodecContext *avctx;
  53. GetBitContext gb;
  54. PutBitContext pb;
  55. int version; ///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
  56. int use_bit_reservoir;
  57. int use_variable_block_len;
  58. int use_exp_vlc; ///< exponent coding: 0 = lsp, 1 = vlc + delta
  59. int use_noise_coding; ///< true if perceptual noise is added
  60. int byte_offset_bits;
  61. VLC exp_vlc;
  62. int exponent_sizes[BLOCK_NB_SIZES];
  63. uint16_t exponent_bands[BLOCK_NB_SIZES][25];
  64. int high_band_start[BLOCK_NB_SIZES]; ///< index of first coef in high band
  65. int coefs_start; ///< first coded coef
  66. int coefs_end[BLOCK_NB_SIZES]; ///< max number of coded coefficients
  67. int exponent_high_sizes[BLOCK_NB_SIZES];
  68. int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
  69. VLC hgain_vlc;
  70. /* coded values in high bands */
  71. int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
  72. int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
  73. /* there are two possible tables for spectral coefficients */
  74. // FIXME the following 3 tables should be shared between decoders
  75. VLC coef_vlc[2];
  76. uint16_t *run_table[2];
  77. float *level_table[2];
  78. uint16_t *int_table[2];
  79. const CoefVLCTable *coef_vlcs[2];
  80. /* frame info */
  81. int frame_len; ///< frame length in samples
  82. int frame_len_bits; ///< frame_len = 1 << frame_len_bits
  83. int nb_block_sizes; ///< number of block sizes
  84. /* block info */
  85. int reset_block_lengths;
  86. int block_len_bits; ///< log2 of current block length
  87. int next_block_len_bits; ///< log2 of next block length
  88. int prev_block_len_bits; ///< log2 of prev block length
  89. int block_len; ///< block length in samples
  90. int block_num; ///< block number in current frame
  91. int block_pos; ///< current position in frame
  92. uint8_t ms_stereo; ///< true if mid/side stereo mode
  93. uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded
  94. int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length
  95. DECLARE_ALIGNED(32, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE];
  96. float max_exponent[MAX_CHANNELS];
  97. WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
  98. DECLARE_ALIGNED(32, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
  99. DECLARE_ALIGNED(32, FFTSample, output)[BLOCK_MAX_SIZE * 2];
  100. FFTContext mdct_ctx[BLOCK_NB_SIZES];
  101. float *windows[BLOCK_NB_SIZES];
  102. /* output buffer for one frame and the last for IMDCT windowing */
  103. DECLARE_ALIGNED(32, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
  104. /* last frame info */
  105. uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; /* padding added */
  106. int last_bitoffset;
  107. int last_superframe_len;
  108. float noise_table[NOISE_TAB_SIZE];
  109. int noise_index;
  110. float noise_mult; /* XXX: suppress that and integrate it in the noise array */
  111. /* lsp_to_curve tables */
  112. float lsp_cos_table[BLOCK_MAX_SIZE];
  113. float lsp_pow_e_table[256];
  114. float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
  115. float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
  116. AVFloatDSPContext fdsp;
  117. #ifdef TRACE
  118. int frame_count;
  119. #endif /* TRACE */
  120. } WMACodecContext;
  121. extern const uint16_t ff_wma_hgain_huffcodes[37];
  122. extern const uint8_t ff_wma_hgain_huffbits[37];
  123. extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
  124. extern const uint32_t ff_aac_scalefactor_code[121];
  125. extern const uint8_t ff_aac_scalefactor_bits[121];
  126. int ff_wma_init(AVCodecContext *avctx, int flags2);
  127. int ff_wma_total_gain_to_bits(int total_gain);
  128. int ff_wma_end(AVCodecContext *avctx);
  129. unsigned int ff_wma_get_large_val(GetBitContext *gb);
  130. int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb,
  131. VLC *vlc, const float *level_table,
  132. const uint16_t *run_table, int version,
  133. WMACoef *ptr, int offset, int num_coefs,
  134. int block_len, int frame_len_bits,
  135. int coef_nb_bits);
  136. #endif /* AVCODEC_WMA_H */