wmadec.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * WMA compatible decoder
  3. * Copyright (c) 2002 The FFmpeg Project.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef _WMADEC_H
  20. #define _WMADEC_H
  21. #include "asf.h"
  22. #include "wmabitstream.h" /* For GetBitContext */
  23. #include "types.h"
  24. //#define TRACE
  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 M_PI 3.14159265358979323846
  36. #define M_PI_F 0x3243f // in fixed 32 format
  37. #define TWO_M_PI_F 0x6487f //in fixed 32
  38. #define MAX_CHANNELS 2
  39. #define NOISE_TAB_SIZE 8192
  40. #define LSP_POW_BITS 7
  41. /*define IRAM for targets with 48k/80k IRAM split*/
  42. #ifndef IBSS_ATTR_WMA_LARGE_IRAM
  43. #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
  44. /* PP5022/24 and MCF5250 have 128KB of IRAM, but only PP5022+ have 80KB allocated for codecs */
  45. #define IBSS_ATTR_WMA_LARGE_IRAM IBSS_ATTR
  46. #else
  47. /* other PP's and MCF5249 have 96KB of IRAM */
  48. #define IBSS_ATTR_WMA_LARGE_IRAM
  49. #endif
  50. #endif
  51. typedef struct WMADecodeContext
  52. {
  53. GetBitContext gb;
  54. int nb_block_sizes; /* number of block sizes */
  55. int sample_rate;
  56. int nb_channels;
  57. int bit_rate;
  58. int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
  59. int block_align;
  60. int use_bit_reservoir;
  61. int use_variable_block_len;
  62. int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */
  63. int use_noise_coding; /* true if perceptual noise is added */
  64. int byte_offset_bits;
  65. VLC exp_vlc;
  66. int exponent_sizes[BLOCK_NB_SIZES];
  67. uint16_t exponent_bands[BLOCK_NB_SIZES][25];
  68. int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
  69. int coefs_start; /* first coded coef */
  70. int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
  71. int exponent_high_sizes[BLOCK_NB_SIZES];
  72. int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
  73. VLC hgain_vlc;
  74. /* coded values in high bands */
  75. int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
  76. int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
  77. /* there are two possible tables for spectral coefficients */
  78. VLC coef_vlc[2];
  79. uint16_t *run_table[2];
  80. uint16_t *level_table[2];
  81. /* frame info */
  82. int frame_len; /* frame length in samples */
  83. int frame_len_bits; /* frame_len = 1 << frame_len_bits */
  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. fixed32 exponents[MAX_CHANNELS][BLOCK_MAX_SIZE];
  96. fixed32 max_exponent[MAX_CHANNELS];
  97. int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
  98. fixed32 (*coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
  99. fixed32 *windows[BLOCK_NB_SIZES];
  100. /* output buffer for one frame and the last for IMDCT windowing */
  101. fixed32 (*frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE*2];
  102. /* last frame info */
  103. uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
  104. int last_bitoffset;
  105. int last_superframe_len;
  106. fixed32 *noise_table;
  107. int noise_index;
  108. fixed32 noise_mult; /* XXX: suppress that and integrate it in the noise array */
  109. /* lsp_to_curve tables */
  110. fixed32 lsp_cos_table[BLOCK_MAX_SIZE];
  111. fixed64 lsp_pow_e_table[256];
  112. fixed32 lsp_pow_m_table1[(1 << LSP_POW_BITS)];
  113. fixed32 lsp_pow_m_table2[(1 << LSP_POW_BITS)];
  114. /* State of current superframe decoding */
  115. int bit_offset;
  116. int nb_frames;
  117. int current_frame;
  118. #ifdef TRACE
  119. int frame_count;
  120. #endif
  121. } WMADecodeContext;
  122. int wma_decode_init(WMADecodeContext* s, asf_waveformatex_t *wfx);
  123. int wma_decode_superframe_init(WMADecodeContext* s, const uint8_t *buf, int buf_size);
  124. int wma_decode_superframe_frame(WMADecodeContext* s, int32_t *samples, const uint8_t *buf, int buf_size);
  125. #endif