wma.h 5.5 KB

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