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.

1569 lines
62KB

  1. /*
  2. * Windows Media Audio Voice decoder.
  3. * Copyright (c) 2009 Ronald S. Bultje
  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. /**
  22. * @file libavcodec/wmavoice.c
  23. * @brief Windows Media Audio Voice compatible decoder
  24. * @author Ronald S. Bultje <rsbultje@gmail.com>
  25. */
  26. #include <math.h>
  27. #include "avcodec.h"
  28. #include "get_bits.h"
  29. #include "put_bits.h"
  30. #include "wmavoice_data.h"
  31. #include "celp_math.h"
  32. #include "celp_filters.h"
  33. #include "acelp_vectors.h"
  34. #include "acelp_filters.h"
  35. #include "lsp.h"
  36. #include "libavutil/lzo.h"
  37. #define MAX_BLOCKS 8 ///< maximum number of blocks per frame
  38. #define MAX_LSPS 16 ///< maximum filter order
  39. #define MAX_FRAMES 3 ///< maximum number of frames per superframe
  40. #define MAX_FRAMESIZE 160 ///< maximum number of samples per frame
  41. #define MAX_SIGNAL_HISTORY 416 ///< maximum excitation signal history
  42. #define MAX_SFRAMESIZE (MAX_FRAMESIZE * MAX_FRAMES)
  43. ///< maximum number of samples per superframe
  44. #define SFRAME_CACHE_MAXSIZE 256 ///< maximum cache size for frame data that
  45. ///< was split over two packets
  46. #define VLC_NBITS 6 ///< number of bits to read per VLC iteration
  47. /**
  48. * Frame type VLC coding.
  49. */
  50. static VLC frame_type_vlc;
  51. /**
  52. * Adaptive codebook types.
  53. */
  54. enum {
  55. ACB_TYPE_NONE = 0, ///< no adaptive codebook (only hardcoded fixed)
  56. ACB_TYPE_ASYMMETRIC = 1, ///< adaptive codebook with per-frame pitch, which
  57. ///< we interpolate to get a per-sample pitch.
  58. ///< Signal is generated using an asymmetric sinc
  59. ///< window function
  60. ///< @note see #wmavoice_ipol1_coeffs
  61. ACB_TYPE_HAMMING = 2 ///< Per-block pitch with signal generation using
  62. ///< a Hamming sinc window function
  63. ///< @note see #wmavoice_ipol2_coeffs
  64. };
  65. /**
  66. * Fixed codebook types.
  67. */
  68. enum {
  69. FCB_TYPE_SILENCE = 0, ///< comfort noise during silence
  70. ///< generated from a hardcoded (fixed) codebook
  71. ///< with per-frame (low) gain values
  72. FCB_TYPE_HARDCODED = 1, ///< hardcoded (fixed) codebook with per-block
  73. ///< gain values
  74. FCB_TYPE_AW_PULSES = 2, ///< Pitch-adaptive window (AW) pulse signals,
  75. ///< used in particular for low-bitrate streams
  76. FCB_TYPE_EXC_PULSES = 3, ///< Innovation (fixed) codebook pulse sets in
  77. ///< combinations of either single pulses or
  78. ///< pulse pairs
  79. };
  80. /**
  81. * Description of frame types.
  82. */
  83. static const struct frame_type_desc {
  84. uint8_t n_blocks; ///< amount of blocks per frame (each block
  85. ///< (contains 160/#n_blocks samples)
  86. uint8_t log_n_blocks; ///< log2(#n_blocks)
  87. uint8_t acb_type; ///< Adaptive codebook type (ACB_TYPE_*)
  88. uint8_t fcb_type; ///< Fixed codebook type (FCB_TYPE_*)
  89. uint8_t dbl_pulses; ///< how many pulse vectors have pulse pairs
  90. ///< (rather than just one single pulse)
  91. ///< only if #fcb_type == #FCB_TYPE_EXC_PULSES
  92. uint16_t frame_size; ///< the amount of bits that make up the block
  93. ///< data (per frame)
  94. } frame_descs[17] = {
  95. { 1, 0, ACB_TYPE_NONE, FCB_TYPE_SILENCE, 0, 0 },
  96. { 2, 1, ACB_TYPE_NONE, FCB_TYPE_HARDCODED, 0, 28 },
  97. { 2, 1, ACB_TYPE_ASYMMETRIC, FCB_TYPE_AW_PULSES, 0, 46 },
  98. { 2, 1, ACB_TYPE_ASYMMETRIC, FCB_TYPE_EXC_PULSES, 2, 80 },
  99. { 2, 1, ACB_TYPE_ASYMMETRIC, FCB_TYPE_EXC_PULSES, 5, 104 },
  100. { 4, 2, ACB_TYPE_ASYMMETRIC, FCB_TYPE_EXC_PULSES, 0, 108 },
  101. { 4, 2, ACB_TYPE_ASYMMETRIC, FCB_TYPE_EXC_PULSES, 2, 132 },
  102. { 4, 2, ACB_TYPE_ASYMMETRIC, FCB_TYPE_EXC_PULSES, 5, 168 },
  103. { 2, 1, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 0, 64 },
  104. { 2, 1, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 2, 80 },
  105. { 2, 1, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 5, 104 },
  106. { 4, 2, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 0, 108 },
  107. { 4, 2, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 2, 132 },
  108. { 4, 2, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 5, 168 },
  109. { 8, 3, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 0, 176 },
  110. { 8, 3, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 2, 208 },
  111. { 8, 3, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 5, 256 }
  112. };
  113. /**
  114. * WMA Voice decoding context.
  115. */
  116. typedef struct {
  117. /**
  118. * @defgroup struct_global Global values
  119. * Global values, specified in the stream header / extradata or used
  120. * all over.
  121. * @{
  122. */
  123. GetBitContext gb; ///< packet bitreader. During decoder init,
  124. ///< it contains the extradata from the
  125. ///< demuxer. During decoding, it contains
  126. ///< packet data.
  127. int8_t vbm_tree[25]; ///< converts VLC codes to frame type
  128. int spillover_bitsize; ///< number of bits used to specify
  129. ///< #spillover_nbits in the packet header
  130. ///< = ceil(log2(ctx->block_align << 3))
  131. int history_nsamples; ///< number of samples in history for signal
  132. ///< prediction (through ACB)
  133. int do_apf; ///< whether to apply the averaged
  134. ///< projection filter (APF)
  135. int lsps; ///< number of LSPs per frame [10 or 16]
  136. int lsp_q_mode; ///< defines quantizer defaults [0, 1]
  137. int lsp_def_mode; ///< defines different sets of LSP defaults
  138. ///< [0, 1]
  139. int frame_lsp_bitsize; ///< size (in bits) of LSPs, when encoded
  140. ///< per-frame (independent coding)
  141. int sframe_lsp_bitsize; ///< size (in bits) of LSPs, when encoded
  142. ///< per superframe (residual coding)
  143. int min_pitch_val; ///< base value for pitch parsing code
  144. int max_pitch_val; ///< max value + 1 for pitch parsing
  145. int pitch_nbits; ///< number of bits used to specify the
  146. ///< pitch value in the frame header
  147. int block_pitch_nbits; ///< number of bits used to specify the
  148. ///< first block's pitch value
  149. int block_pitch_range; ///< range of the block pitch
  150. int block_delta_pitch_nbits; ///< number of bits used to specify the
  151. ///< delta pitch between this and the last
  152. ///< block's pitch value, used in all but
  153. ///< first block
  154. int block_delta_pitch_hrange; ///< 1/2 range of the delta (full range is
  155. ///< from -this to +this-1)
  156. uint16_t block_conv_table[4]; ///< boundaries for block pitch unit/scale
  157. ///< conversion
  158. /**
  159. * @}
  160. * @defgroup struct_packet Packet values
  161. * Packet values, specified in the packet header or related to a packet.
  162. * A packet is considered to be a single unit of data provided to this
  163. * decoder by the demuxer.
  164. * @{
  165. */
  166. int spillover_nbits; ///< number of bits of the previous packet's
  167. ///< last superframe preceeding this
  168. ///< packet's first full superframe (useful
  169. ///< for re-synchronization also)
  170. int has_residual_lsps; ///< if set, superframes contain one set of
  171. ///< LSPs that cover all frames, encoded as
  172. ///< independent and residual LSPs; if not
  173. ///< set, each frame contains its own, fully
  174. ///< independent, LSPs
  175. int skip_bits_next; ///< number of bits to skip at the next call
  176. ///< to #wmavoice_decode_packet() (since
  177. ///< they're part of the previous superframe)
  178. uint8_t sframe_cache[SFRAME_CACHE_MAXSIZE + FF_INPUT_BUFFER_PADDING_SIZE];
  179. ///< cache for superframe data split over
  180. ///< multiple packets
  181. int sframe_cache_size; ///< set to >0 if we have data from an
  182. ///< (incomplete) superframe from a previous
  183. ///< packet that spilled over in the current
  184. ///< packet; specifies the amount of bits in
  185. ///< #sframe_cache
  186. PutBitContext pb; ///< bitstream writer for #sframe_cache
  187. /**
  188. * @}
  189. * @defgroup struct_frame Frame and superframe values
  190. * Superframe and frame data - these can change from frame to frame,
  191. * although some of them do in that case serve as a cache / history for
  192. * the next frame or superframe.
  193. * @{
  194. */
  195. double prev_lsps[MAX_LSPS]; ///< LSPs of the last frame of the previous
  196. ///< superframe
  197. int last_pitch_val; ///< pitch value of the previous frame
  198. int last_acb_type; ///< frame type [0-2] of the previous frame
  199. int pitch_diff_sh16; ///< ((cur_pitch_val - #last_pitch_val)
  200. ///< << 16) / #MAX_FRAMESIZE
  201. float silence_gain; ///< set for use in blocks if #ACB_TYPE_NONE
  202. int aw_idx_is_ext; ///< whether the AW index was encoded in
  203. ///< 8 bits (instead of 6)
  204. int aw_pulse_range; ///< the range over which #aw_pulse_set1()
  205. ///< can apply the pulse, relative to the
  206. ///< value in aw_first_pulse_off. The exact
  207. ///< position of the first AW-pulse is within
  208. ///< [pulse_off, pulse_off + this], and
  209. ///< depends on bitstream values; [16 or 24]
  210. int aw_n_pulses[2]; ///< number of AW-pulses in each block; note
  211. ///< that this number can be negative (in
  212. ///< which case it basically means "zero")
  213. int aw_first_pulse_off[2]; ///< index of first sample to which to
  214. ///< apply AW-pulses, or -0xff if unset
  215. int aw_next_pulse_off_cache; ///< the position (relative to start of the
  216. ///< second block) at which pulses should
  217. ///< start to be positioned, serves as a
  218. ///< cache for pitch-adaptive window pulses
  219. ///< between blocks
  220. int frame_cntr; ///< current frame index [0 - 0xFFFE]; is
  221. ///< only used for comfort noise in #pRNG()
  222. float gain_pred_err[6]; ///< cache for gain prediction
  223. float excitation_history[MAX_SIGNAL_HISTORY];
  224. ///< cache of the signal of previous
  225. ///< superframes, used as a history for
  226. ///< signal generation
  227. float synth_history[MAX_LSPS]; ///< see #excitation_history
  228. /**
  229. * @}
  230. */
  231. } WMAVoiceContext;
  232. /**
  233. * Sets up the variable bit mode (VBM) tree from container extradata.
  234. * @param gb bit I/O context.
  235. * The bit context (s->gb) should be loaded with byte 23-46 of the
  236. * container extradata (i.e. the ones containing the VBM tree).
  237. * @param vbm_tree pointer to array to which the decoded VBM tree will be
  238. * written.
  239. * @return 0 on success, <0 on error.
  240. */
  241. static av_cold int decode_vbmtree(GetBitContext *gb, int8_t vbm_tree[25])
  242. {
  243. static const uint8_t bits[] = {
  244. 2, 2, 2, 4, 4, 4,
  245. 6, 6, 6, 8, 8, 8,
  246. 10, 10, 10, 12, 12, 12,
  247. 14, 14, 14, 14
  248. };
  249. static const uint16_t codes[] = {
  250. 0x0000, 0x0001, 0x0002, // 00/01/10
  251. 0x000c, 0x000d, 0x000e, // 11+00/01/10
  252. 0x003c, 0x003d, 0x003e, // 1111+00/01/10
  253. 0x00fc, 0x00fd, 0x00fe, // 111111+00/01/10
  254. 0x03fc, 0x03fd, 0x03fe, // 11111111+00/01/10
  255. 0x0ffc, 0x0ffd, 0x0ffe, // 1111111111+00/01/10
  256. 0x3ffc, 0x3ffd, 0x3ffe, 0x3fff // 111111111111+xx
  257. };
  258. int cntr[8], n, res;
  259. memset(vbm_tree, 0xff, sizeof(vbm_tree));
  260. memset(cntr, 0, sizeof(cntr));
  261. for (n = 0; n < 17; n++) {
  262. res = get_bits(gb, 3);
  263. if (cntr[res] > 3) // should be >= 3 + (res == 7))
  264. return -1;
  265. vbm_tree[res * 3 + cntr[res]++] = n;
  266. }
  267. INIT_VLC_STATIC(&frame_type_vlc, VLC_NBITS, sizeof(bits),
  268. bits, 1, 1, codes, 2, 2, 132);
  269. return 0;
  270. }
  271. /**
  272. * Set up decoder with parameters from demuxer (extradata etc.).
  273. */
  274. static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
  275. {
  276. int n, flags, pitch_range, lsp16_flag;
  277. WMAVoiceContext *s = ctx->priv_data;
  278. /**
  279. * Extradata layout:
  280. * - byte 0-18: WMAPro-in-WMAVoice extradata (see wmaprodec.c),
  281. * - byte 19-22: flags field (annoyingly in LE; see below for known
  282. * values),
  283. * - byte 23-46: variable bitmode tree (really just 17 * 3 bits,
  284. * rest is 0).
  285. */
  286. if (ctx->extradata_size != 46) {
  287. av_log(ctx, AV_LOG_ERROR,
  288. "Invalid extradata size %d (should be 46)\n",
  289. ctx->extradata_size);
  290. return -1;
  291. }
  292. flags = AV_RL32(ctx->extradata + 18);
  293. s->spillover_bitsize = 3 + av_ceil_log2(ctx->block_align);
  294. s->do_apf = flags & 0x1;
  295. s->lsp_q_mode = !!(flags & 0x2000);
  296. s->lsp_def_mode = !!(flags & 0x4000);
  297. lsp16_flag = flags & 0x1000;
  298. if (lsp16_flag) {
  299. s->lsps = 16;
  300. s->frame_lsp_bitsize = 34;
  301. s->sframe_lsp_bitsize = 60;
  302. } else {
  303. s->lsps = 10;
  304. s->frame_lsp_bitsize = 24;
  305. s->sframe_lsp_bitsize = 48;
  306. }
  307. for (n = 0; n < s->lsps; n++)
  308. s->prev_lsps[n] = M_PI * (n + 1.0) / (s->lsps + 1.0);
  309. init_get_bits(&s->gb, ctx->extradata + 22, (ctx->extradata_size - 22) << 3);
  310. if (decode_vbmtree(&s->gb, s->vbm_tree) < 0) {
  311. av_log(ctx, AV_LOG_ERROR, "Invalid VBM tree; broken extradata?\n");
  312. return -1;
  313. }
  314. s->min_pitch_val = ((ctx->sample_rate << 8) / 400 + 50) >> 8;
  315. s->max_pitch_val = ((ctx->sample_rate << 8) * 37 / 2000 + 50) >> 8;
  316. pitch_range = s->max_pitch_val - s->min_pitch_val;
  317. s->pitch_nbits = av_ceil_log2(pitch_range);
  318. s->last_pitch_val = 40;
  319. s->last_acb_type = ACB_TYPE_NONE;
  320. s->history_nsamples = s->max_pitch_val + 8;
  321. if (s->min_pitch_val < 1 || s->history_nsamples > MAX_SIGNAL_HISTORY) {
  322. int min_sr = ((((1 << 8) - 50) * 400) + 0xFF) >> 8,
  323. max_sr = ((((MAX_SIGNAL_HISTORY - 8) << 8) + 205) * 2000 / 37) >> 8;
  324. av_log(ctx, AV_LOG_ERROR,
  325. "Unsupported samplerate %d (min=%d, max=%d)\n",
  326. ctx->sample_rate, min_sr, max_sr); // 322-22097 Hz
  327. return -1;
  328. }
  329. s->block_conv_table[0] = s->min_pitch_val;
  330. s->block_conv_table[1] = (pitch_range * 25) >> 6;
  331. s->block_conv_table[2] = (pitch_range * 44) >> 6;
  332. s->block_conv_table[3] = s->max_pitch_val - 1;
  333. s->block_delta_pitch_hrange = (pitch_range >> 3) & ~0xF;
  334. s->block_delta_pitch_nbits = 1 + av_ceil_log2(s->block_delta_pitch_hrange);
  335. s->block_pitch_range = s->block_conv_table[2] +
  336. s->block_conv_table[3] + 1 +
  337. 2 * (s->block_conv_table[1] - 2 * s->min_pitch_val);
  338. s->block_pitch_nbits = av_ceil_log2(s->block_pitch_range);
  339. ctx->sample_fmt = SAMPLE_FMT_FLT;
  340. return 0;
  341. }
  342. /**
  343. * Dequantize LSPs
  344. * @param lsps output pointer to the array that will hold the LSPs
  345. * @param num number of LSPs to be dequantized
  346. * @param values quantized values, contains n_stages values
  347. * @param sizes range (i.e. max value) of each quantized value
  348. * @param n_stages number of dequantization runs
  349. * @param table dequantization table to be used
  350. * @param mul_q LSF multiplier
  351. * @param base_q base (lowest) LSF values
  352. */
  353. static void dequant_lsps(double *lsps, int num,
  354. const uint16_t *values,
  355. const uint16_t *sizes,
  356. int n_stages, const uint8_t *table,
  357. const double *mul_q,
  358. const double *base_q)
  359. {
  360. int n, m;
  361. memset(lsps, 0, num * sizeof(*lsps));
  362. for (n = 0; n < n_stages; n++) {
  363. const uint8_t *t_off = &table[values[n] * num];
  364. double base = base_q[n], mul = mul_q[n];
  365. for (m = 0; m < num; m++)
  366. lsps[m] += base + mul * t_off[m];
  367. table += sizes[n] * num;
  368. }
  369. }
  370. /**
  371. * @defgroup lsp_dequant LSP dequantization routines
  372. * LSP dequantization routines, for 10/16LSPs and independent/residual coding.
  373. * @note we assume enough bits are available, caller should check.
  374. * lsp10i() consumes 24 bits; lsp10r() consumes an additional 24 bits;
  375. * lsp16i() consumes 34 bits; lsp16r() consumes an additional 26 bits.
  376. * @{
  377. */
  378. /**
  379. * Parse 10 independently-coded LSPs.
  380. */
  381. static void dequant_lsp10i(GetBitContext *gb, double *lsps)
  382. {
  383. static const uint16_t vec_sizes[4] = { 256, 64, 32, 32 };
  384. static const double mul_lsf[4] = {
  385. 5.2187144800e-3, 1.4626986422e-3,
  386. 9.6179549166e-4, 1.1325736225e-3
  387. };
  388. static const double base_lsf[4] = {
  389. M_PI * -2.15522e-1, M_PI * -6.1646e-2,
  390. M_PI * -3.3486e-2, M_PI * -5.7408e-2
  391. };
  392. uint16_t v[4];
  393. v[0] = get_bits(gb, 8);
  394. v[1] = get_bits(gb, 6);
  395. v[2] = get_bits(gb, 5);
  396. v[3] = get_bits(gb, 5);
  397. dequant_lsps(lsps, 10, v, vec_sizes, 4, wmavoice_dq_lsp10i,
  398. mul_lsf, base_lsf);
  399. }
  400. /**
  401. * Parse 10 independently-coded LSPs, and then derive the tables to
  402. * generate LSPs for the other frames from them (residual coding).
  403. */
  404. static void dequant_lsp10r(GetBitContext *gb,
  405. double *i_lsps, const double *old,
  406. double *a1, double *a2, int q_mode)
  407. {
  408. static const uint16_t vec_sizes[3] = { 128, 64, 64 };
  409. static const double mul_lsf[3] = {
  410. 2.5807601174e-3, 1.2354460219e-3, 1.1763821673e-3
  411. };
  412. static const double base_lsf[3] = {
  413. M_PI * -1.07448e-1, M_PI * -5.2706e-2, M_PI * -5.1634e-2
  414. };
  415. const float (*ipol_tab)[2][10] = q_mode ?
  416. wmavoice_lsp10_intercoeff_b : wmavoice_lsp10_intercoeff_a;
  417. uint16_t interpol, v[3];
  418. int n;
  419. dequant_lsp10i(gb, i_lsps);
  420. interpol = get_bits(gb, 5);
  421. v[0] = get_bits(gb, 7);
  422. v[1] = get_bits(gb, 6);
  423. v[2] = get_bits(gb, 6);
  424. for (n = 0; n < 10; n++) {
  425. double delta = old[n] - i_lsps[n];
  426. a1[n] = ipol_tab[interpol][0][n] * delta + i_lsps[n];
  427. a1[10 + n] = ipol_tab[interpol][1][n] * delta + i_lsps[n];
  428. }
  429. dequant_lsps(a2, 20, v, vec_sizes, 3, wmavoice_dq_lsp10r,
  430. mul_lsf, base_lsf);
  431. }
  432. /**
  433. * Parse 16 independently-coded LSPs.
  434. */
  435. static void dequant_lsp16i(GetBitContext *gb, double *lsps)
  436. {
  437. static const uint16_t vec_sizes[5] = { 256, 64, 128, 64, 128 };
  438. static const double mul_lsf[5] = {
  439. 3.3439586280e-3, 6.9908173703e-4,
  440. 3.3216608306e-3, 1.0334960326e-3,
  441. 3.1899104283e-3
  442. };
  443. static const double base_lsf[5] = {
  444. M_PI * -1.27576e-1, M_PI * -2.4292e-2,
  445. M_PI * -1.28094e-1, M_PI * -3.2128e-2,
  446. M_PI * -1.29816e-1
  447. };
  448. uint16_t v[5];
  449. v[0] = get_bits(gb, 8);
  450. v[1] = get_bits(gb, 6);
  451. v[2] = get_bits(gb, 7);
  452. v[3] = get_bits(gb, 6);
  453. v[4] = get_bits(gb, 7);
  454. dequant_lsps( lsps, 5, v, vec_sizes, 2,
  455. wmavoice_dq_lsp16i1, mul_lsf, base_lsf);
  456. dequant_lsps(&lsps[5], 5, &v[2], &vec_sizes[2], 2,
  457. wmavoice_dq_lsp16i2, &mul_lsf[2], &base_lsf[2]);
  458. dequant_lsps(&lsps[10], 6, &v[4], &vec_sizes[4], 1,
  459. wmavoice_dq_lsp16i3, &mul_lsf[4], &base_lsf[4]);
  460. }
  461. /**
  462. * Parse 16 independently-coded LSPs, and then derive the tables to
  463. * generate LSPs for the other frames from them (residual coding).
  464. */
  465. static void dequant_lsp16r(GetBitContext *gb,
  466. double *i_lsps, const double *old,
  467. double *a1, double *a2, int q_mode)
  468. {
  469. static const uint16_t vec_sizes[3] = { 128, 128, 128 };
  470. static const double mul_lsf[3] = {
  471. 1.2232979501e-3, 1.4062241527e-3, 1.6114744851e-3
  472. };
  473. static const double base_lsf[3] = {
  474. M_PI * -5.5830e-2, M_PI * -5.2908e-2, M_PI * -5.4776e-2
  475. };
  476. const float (*ipol_tab)[2][16] = q_mode ?
  477. wmavoice_lsp16_intercoeff_b : wmavoice_lsp16_intercoeff_a;
  478. uint16_t interpol, v[3];
  479. int n;
  480. dequant_lsp16i(gb, i_lsps);
  481. interpol = get_bits(gb, 5);
  482. v[0] = get_bits(gb, 7);
  483. v[1] = get_bits(gb, 7);
  484. v[2] = get_bits(gb, 7);
  485. for (n = 0; n < 16; n++) {
  486. double delta = old[n] - i_lsps[n];
  487. a1[n] = ipol_tab[interpol][0][n] * delta + i_lsps[n];
  488. a1[16 + n] = ipol_tab[interpol][1][n] * delta + i_lsps[n];
  489. }
  490. dequant_lsps( a2, 10, v, vec_sizes, 1,
  491. wmavoice_dq_lsp16r1, mul_lsf, base_lsf);
  492. dequant_lsps(&a2[10], 10, &v[1], &vec_sizes[1], 1,
  493. wmavoice_dq_lsp16r2, &mul_lsf[1], &base_lsf[1]);
  494. dequant_lsps(&a2[20], 12, &v[2], &vec_sizes[2], 1,
  495. wmavoice_dq_lsp16r3, &mul_lsf[2], &base_lsf[2]);
  496. }
  497. /**
  498. * @}
  499. * @defgroup aw Pitch-adaptive window coding functions
  500. * The next few functions are for pitch-adaptive window coding.
  501. * @{
  502. */
  503. /**
  504. * Parse the offset of the first pitch-adaptive window pulses, and
  505. * the distribution of pulses between the two blocks in this frame.
  506. * @param s WMA Voice decoding context private data
  507. * @param gb bit I/O context
  508. * @param pitch pitch for each block in this frame
  509. */
  510. static void aw_parse_coords(WMAVoiceContext *s, GetBitContext *gb,
  511. const int *pitch)
  512. {
  513. static const int16_t start_offset[94] = {
  514. -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11,
  515. 13, 15, 18, 17, 19, 20, 21, 22, 23, 24, 25, 26,
  516. 27, 28, 29, 30, 31, 32, 33, 35, 37, 39, 41, 43,
  517. 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67,
  518. 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91,
  519. 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115,
  520. 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139,
  521. 141, 143, 145, 147, 149, 151, 153, 155, 157, 159
  522. };
  523. int bits, offset;
  524. /* position of pulse */
  525. s->aw_idx_is_ext = 0;
  526. if ((bits = get_bits(gb, 6)) >= 54) {
  527. s->aw_idx_is_ext = 1;
  528. bits += (bits - 54) * 3 + get_bits(gb, 2);
  529. }
  530. /* for a repeated pulse at pulse_off with a pitch_lag of pitch[], count
  531. * the distribution of the pulses in each block contained in this frame. */
  532. s->aw_pulse_range = FFMIN(pitch[0], pitch[1]) > 32 ? 24 : 16;
  533. for (offset = start_offset[bits]; offset < 0; offset += pitch[0]) ;
  534. s->aw_n_pulses[0] = (pitch[0] - 1 + MAX_FRAMESIZE / 2 - offset) / pitch[0];
  535. s->aw_first_pulse_off[0] = offset - s->aw_pulse_range / 2;
  536. offset += s->aw_n_pulses[0] * pitch[0];
  537. s->aw_n_pulses[1] = (pitch[1] - 1 + MAX_FRAMESIZE - offset) / pitch[1];
  538. s->aw_first_pulse_off[1] = offset - (MAX_FRAMESIZE + s->aw_pulse_range) / 2;
  539. /* if continuing from a position before the block, reset position to
  540. * start of block (when corrected for the range over which it can be
  541. * spread in aw_pulse_set1()). */
  542. if (start_offset[bits] < MAX_FRAMESIZE / 2) {
  543. while (s->aw_first_pulse_off[1] - pitch[1] + s->aw_pulse_range > 0)
  544. s->aw_first_pulse_off[1] -= pitch[1];
  545. if (start_offset[bits] < 0)
  546. while (s->aw_first_pulse_off[0] - pitch[0] + s->aw_pulse_range > 0)
  547. s->aw_first_pulse_off[0] -= pitch[0];
  548. }
  549. }
  550. /**
  551. * Apply second set of pitch-adaptive window pulses.
  552. * @param s WMA Voice decoding context private data
  553. * @param gb bit I/O context
  554. * @param block_idx block index in frame [0, 1]
  555. * @param fcb structure containing fixed codebook vector info
  556. */
  557. static void aw_pulse_set2(WMAVoiceContext *s, GetBitContext *gb,
  558. int block_idx, AMRFixed *fcb)
  559. {
  560. uint16_t use_mask[7]; // only 5 are used, rest is padding
  561. /* in this function, idx is the index in the 80-bit (+ padding) use_mask
  562. * bit-array. Since use_mask consists of 16-bit values, the lower 4 bits
  563. * of idx are the position of the bit within a particular item in the
  564. * array (0 being the most significant bit, and 15 being the least
  565. * significant bit), and the remainder (>> 4) is the index in the
  566. * use_mask[]-array. This is faster and uses less memory than using a
  567. * 80-byte/80-int array. */
  568. int pulse_off = s->aw_first_pulse_off[block_idx],
  569. pulse_start, n, idx, range, aidx, start_off = 0;
  570. /* set offset of first pulse to within this block */
  571. if (s->aw_n_pulses[block_idx] > 0)
  572. while (pulse_off + s->aw_pulse_range < 1)
  573. pulse_off += fcb->pitch_lag;
  574. /* find range per pulse */
  575. if (s->aw_n_pulses[0] > 0) {
  576. if (block_idx == 0) {
  577. range = 32;
  578. } else /* block_idx = 1 */ {
  579. range = 8;
  580. if (s->aw_n_pulses[block_idx] > 0)
  581. pulse_off = s->aw_next_pulse_off_cache;
  582. }
  583. } else
  584. range = 16;
  585. pulse_start = s->aw_n_pulses[block_idx] > 0 ? pulse_off - range / 2 : 0;
  586. /* aw_pulse_set1() already applies pulses around pulse_off (to be exactly,
  587. * in the range of [pulse_off, pulse_off + s->aw_pulse_range], and thus
  588. * we exclude that range from being pulsed again in this function. */
  589. memset( use_mask, -1, 5 * sizeof(use_mask[0]));
  590. memset(&use_mask[5], 0, 2 * sizeof(use_mask[0]));
  591. if (s->aw_n_pulses[block_idx] > 0)
  592. for (idx = pulse_off; idx < MAX_FRAMESIZE / 2; idx += fcb->pitch_lag) {
  593. int excl_range = s->aw_pulse_range; // always 16 or 24
  594. uint16_t *use_mask_ptr = &use_mask[idx >> 4];
  595. int first_sh = 16 - (idx & 15);
  596. *use_mask_ptr++ &= 0xFFFF << first_sh;
  597. excl_range -= first_sh;
  598. if (excl_range >= 16) {
  599. *use_mask_ptr++ = 0;
  600. *use_mask_ptr &= 0xFFFF >> (excl_range - 16);
  601. } else
  602. *use_mask_ptr &= 0xFFFF >> excl_range;
  603. }
  604. /* find the 'aidx'th offset that is not excluded */
  605. aidx = get_bits(gb, s->aw_n_pulses[0] > 0 ? 5 - 2 * block_idx : 4);
  606. for (n = 0; n <= aidx; pulse_start++) {
  607. for (idx = pulse_start; idx < 0; idx += fcb->pitch_lag) ;
  608. if (idx >= MAX_FRAMESIZE / 2) { // find from zero
  609. if (use_mask[0]) idx = 0x0F;
  610. else if (use_mask[1]) idx = 0x1F;
  611. else if (use_mask[2]) idx = 0x2F;
  612. else if (use_mask[3]) idx = 0x3F;
  613. else if (use_mask[4]) idx = 0x4F;
  614. else return;
  615. idx -= av_log2_16bit(use_mask[idx >> 4]);
  616. }
  617. if (use_mask[idx >> 4] & (0x8000 >> (idx & 15))) {
  618. use_mask[idx >> 4] &= ~(0x8000 >> (idx & 15));
  619. n++;
  620. start_off = idx;
  621. }
  622. }
  623. fcb->x[fcb->n] = start_off;
  624. fcb->y[fcb->n] = get_bits1(gb) ? -1.0 : 1.0;
  625. fcb->n++;
  626. /* set offset for next block, relative to start of that block */
  627. n = (MAX_FRAMESIZE / 2 - start_off) % fcb->pitch_lag;
  628. s->aw_next_pulse_off_cache = n ? fcb->pitch_lag - n : 0;
  629. }
  630. /**
  631. * Apply first set of pitch-adaptive window pulses.
  632. * @param s WMA Voice decoding context private data
  633. * @param gb bit I/O context
  634. * @param block_idx block index in frame [0, 1]
  635. * @param fcb storage location for fixed codebook pulse info
  636. */
  637. static void aw_pulse_set1(WMAVoiceContext *s, GetBitContext *gb,
  638. int block_idx, AMRFixed *fcb)
  639. {
  640. int val = get_bits(gb, 12 - 2 * (s->aw_idx_is_ext && !block_idx));
  641. float v;
  642. if (s->aw_n_pulses[block_idx] > 0) {
  643. int n, v_mask, i_mask, sh, n_pulses;
  644. if (s->aw_pulse_range == 24) { // 3 pulses, 1:sign + 3:index each
  645. n_pulses = 3;
  646. v_mask = 8;
  647. i_mask = 7;
  648. sh = 4;
  649. } else { // 4 pulses, 1:sign + 2:index each
  650. n_pulses = 4;
  651. v_mask = 4;
  652. i_mask = 3;
  653. sh = 3;
  654. }
  655. for (n = n_pulses - 1; n >= 0; n--, val >>= sh) {
  656. fcb->y[fcb->n] = (val & v_mask) ? -1.0 : 1.0;
  657. fcb->x[fcb->n] = (val & i_mask) * n_pulses + n +
  658. s->aw_first_pulse_off[block_idx];
  659. while (fcb->x[fcb->n] < 0)
  660. fcb->x[fcb->n] += fcb->pitch_lag;
  661. if (fcb->x[fcb->n] < MAX_FRAMESIZE / 2)
  662. fcb->n++;
  663. }
  664. } else {
  665. int num2 = (val & 0x1FF) >> 1, delta, idx;
  666. if (num2 < 1 * 79) { delta = 1; idx = num2 + 1; }
  667. else if (num2 < 2 * 78) { delta = 3; idx = num2 + 1 - 1 * 77; }
  668. else if (num2 < 3 * 77) { delta = 5; idx = num2 + 1 - 2 * 76; }
  669. else { delta = 7; idx = num2 + 1 - 3 * 75; }
  670. v = (val & 0x200) ? -1.0 : 1.0;
  671. fcb->no_repeat_mask |= 3 << fcb->n;
  672. fcb->x[fcb->n] = idx - delta;
  673. fcb->y[fcb->n] = v;
  674. fcb->x[fcb->n + 1] = idx;
  675. fcb->y[fcb->n + 1] = (val & 1) ? -v : v;
  676. fcb->n += 2;
  677. }
  678. }
  679. /**
  680. * @}
  681. *
  682. * Generate a random number from frame_cntr and block_idx, which will lief
  683. * in the range [0, 1000 - block_size] (so it can be used as an index in a
  684. * table of size 1000 of which you want to read block_size entries).
  685. *
  686. * @param frame_cntr current frame number
  687. * @param block_num current block index
  688. * @param block_size amount of entries we want to read from a table
  689. * that has 1000 entries
  690. * @returns a (non-)random number in the [0, 1000 - block_size] range.
  691. */
  692. static int pRNG(int frame_cntr, int block_num, int block_size)
  693. {
  694. /* array to simplify the calculation of z:
  695. * y = (x % 9) * 5 + 6;
  696. * z = (49995 * x) / y;
  697. * Since y only has 9 values, we can remove the division by using a
  698. * LUT and using FASTDIV-style divisions. For each of the 9 values
  699. * of y, we can rewrite z as:
  700. * z = x * (49995 / y) + x * ((49995 % y) / y)
  701. * In this table, each col represents one possible value of y, the
  702. * first number is 49995 / y, and the second is the FASTDIV variant
  703. * of 49995 % y / y. */
  704. static const unsigned int div_tbl[9][2] = {
  705. { 8332, 3 * 715827883U }, // y = 6
  706. { 4545, 0 * 390451573U }, // y = 11
  707. { 3124, 11 * 268435456U }, // y = 16
  708. { 2380, 15 * 204522253U }, // y = 21
  709. { 1922, 23 * 165191050U }, // y = 26
  710. { 1612, 23 * 138547333U }, // y = 31
  711. { 1388, 27 * 119304648U }, // y = 36
  712. { 1219, 16 * 104755300U }, // y = 41
  713. { 1086, 39 * 93368855U } // y = 46
  714. };
  715. unsigned int z, y, x = MUL16(block_num, 1877) + frame_cntr;
  716. if (x >= 0xFFFF) x -= 0xFFFF; // max value of x is 8*1877+0xFFFE=0x13AA6,
  717. // so this is effectively a modulo (%)
  718. y = x - 9 * MULH(477218589, x); // x % 9
  719. z = (uint16_t) (x * div_tbl[y][0] + UMULH(x, div_tbl[y][1]));
  720. // z = x * 49995 / (y * 5 + 6)
  721. return z % (1000 - block_size);
  722. }
  723. /**
  724. * Parse hardcoded signal for a single block.
  725. * @note see #synth_block().
  726. */
  727. static void synth_block_hardcoded(WMAVoiceContext *s, GetBitContext *gb,
  728. int block_idx, int size,
  729. const struct frame_type_desc *frame_desc,
  730. float *excitation)
  731. {
  732. float gain;
  733. int n, r_idx;
  734. assert(size <= MAX_FRAMESIZE);
  735. /* Set the offset from which we start reading wmavoice_std_codebook */
  736. if (frame_desc->fcb_type == FCB_TYPE_SILENCE) {
  737. r_idx = pRNG(s->frame_cntr, block_idx, size);
  738. gain = s->silence_gain;
  739. } else /* FCB_TYPE_HARDCODED */ {
  740. r_idx = get_bits(gb, 8);
  741. gain = wmavoice_gain_universal[get_bits(gb, 6)];
  742. }
  743. /* Clear gain prediction parameters */
  744. memset(s->gain_pred_err, 0, sizeof(s->gain_pred_err));
  745. /* Apply gain to hardcoded codebook and use that as excitation signal */
  746. for (n = 0; n < size; n++)
  747. excitation[n] = wmavoice_std_codebook[r_idx + n] * gain;
  748. }
  749. /**
  750. * Parse FCB/ACB signal for a single block.
  751. * @note see #synth_block().
  752. */
  753. static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb,
  754. int block_idx, int size,
  755. int block_pitch_sh2,
  756. const struct frame_type_desc *frame_desc,
  757. float *excitation)
  758. {
  759. static const float gain_coeff[6] = {
  760. 0.8169, -0.06545, 0.1726, 0.0185, -0.0359, 0.0458
  761. };
  762. float pulses[MAX_FRAMESIZE / 2], pred_err, acb_gain, fcb_gain;
  763. int n, idx, gain_weight;
  764. AMRFixed fcb;
  765. assert(size <= MAX_FRAMESIZE / 2);
  766. memset(pulses, 0, sizeof(*pulses) * size);
  767. fcb.pitch_lag = block_pitch_sh2 >> 2;
  768. fcb.pitch_fac = 1.0;
  769. fcb.no_repeat_mask = 0;
  770. fcb.n = 0;
  771. /* For the other frame types, this is where we apply the innovation
  772. * (fixed) codebook pulses of the speech signal. */
  773. if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) {
  774. aw_pulse_set1(s, gb, block_idx, &fcb);
  775. aw_pulse_set2(s, gb, block_idx, &fcb);
  776. } else /* FCB_TYPE_EXC_PULSES */ {
  777. int offset_nbits = 5 - frame_desc->log_n_blocks;
  778. fcb.no_repeat_mask = -1;
  779. /* similar to ff_decode_10_pulses_35bits(), but with single pulses
  780. * (instead of double) for a subset of pulses */
  781. for (n = 0; n < 5; n++) {
  782. float sign;
  783. int pos1, pos2;
  784. sign = get_bits1(gb) ? 1.0 : -1.0;
  785. pos1 = get_bits(gb, offset_nbits);
  786. fcb.x[fcb.n] = n + 5 * pos1;
  787. fcb.y[fcb.n++] = sign;
  788. if (n < frame_desc->dbl_pulses) {
  789. pos2 = get_bits(gb, offset_nbits);
  790. fcb.x[fcb.n] = n + 5 * pos2;
  791. fcb.y[fcb.n++] = (pos1 < pos2) ? -sign : sign;
  792. }
  793. }
  794. }
  795. ff_set_fixed_vector(pulses, &fcb, 1.0, size);
  796. /* Calculate gain for adaptive & fixed codebook signal.
  797. * see ff_amr_set_fixed_gain(). */
  798. idx = get_bits(gb, 7);
  799. fcb_gain = expf(ff_dot_productf(s->gain_pred_err, gain_coeff, 6) -
  800. 5.2409161640 + wmavoice_gain_codebook_fcb[idx]);
  801. acb_gain = wmavoice_gain_codebook_acb[idx];
  802. pred_err = av_clipf(wmavoice_gain_codebook_fcb[idx],
  803. -2.9957322736 /* log(0.05) */,
  804. 1.6094379124 /* log(5.0) */);
  805. gain_weight = 8 >> frame_desc->log_n_blocks;
  806. memmove(&s->gain_pred_err[gain_weight], s->gain_pred_err,
  807. sizeof(*s->gain_pred_err) * (6 - gain_weight));
  808. for (n = 0; n < gain_weight; n++)
  809. s->gain_pred_err[n] = pred_err;
  810. /* Calculation of adaptive codebook */
  811. if (frame_desc->acb_type == ACB_TYPE_ASYMMETRIC) {
  812. int len;
  813. for (n = 0; n < size; n += len) {
  814. int next_idx_sh16;
  815. int abs_idx = block_idx * size + n;
  816. int pitch_sh16 = (s->last_pitch_val << 16) +
  817. s->pitch_diff_sh16 * abs_idx;
  818. int pitch = (pitch_sh16 + 0x6FFF) >> 16;
  819. int idx_sh16 = ((pitch << 16) - pitch_sh16) * 8 + 0x58000;
  820. idx = idx_sh16 >> 16;
  821. if (s->pitch_diff_sh16) {
  822. if (s->pitch_diff_sh16 > 0) {
  823. next_idx_sh16 = (idx_sh16) &~ 0xFFFF;
  824. } else
  825. next_idx_sh16 = (idx_sh16 + 0x10000) &~ 0xFFFF;
  826. len = av_clip((idx_sh16 - next_idx_sh16) / s->pitch_diff_sh16 / 8,
  827. 1, size - n);
  828. } else
  829. len = size;
  830. ff_acelp_interpolatef(&excitation[n], &excitation[n - pitch],
  831. wmavoice_ipol1_coeffs, 17,
  832. idx, 9, len);
  833. }
  834. } else /* ACB_TYPE_HAMMING */ {
  835. int block_pitch = block_pitch_sh2 >> 2;
  836. idx = block_pitch_sh2 & 3;
  837. if (idx) {
  838. ff_acelp_interpolatef(excitation, &excitation[-block_pitch],
  839. wmavoice_ipol2_coeffs, 4,
  840. idx, 8, size);
  841. } else
  842. av_memcpy_backptr(excitation, sizeof(float) * block_pitch,
  843. sizeof(float) * size);
  844. }
  845. /* Interpolate ACB/FCB and use as excitation signal */
  846. ff_weighted_vector_sumf(excitation, excitation, pulses,
  847. acb_gain, fcb_gain, size);
  848. }
  849. /**
  850. * Parse data in a single block.
  851. * @note we assume enough bits are available, caller should check.
  852. *
  853. * @param s WMA Voice decoding context private data
  854. * @param gb bit I/O context
  855. * @param block_idx index of the to-be-read block
  856. * @param size amount of samples to be read in this block
  857. * @param block_pitch_sh2 pitch for this block << 2
  858. * @param lsps LSPs for (the end of) this frame
  859. * @param prev_lsps LSPs for the last frame
  860. * @param frame_desc frame type descriptor
  861. * @param excitation target memory for the ACB+FCB interpolated signal
  862. * @param synth target memory for the speech synthesis filter output
  863. * @return 0 on success, <0 on error.
  864. */
  865. static void synth_block(WMAVoiceContext *s, GetBitContext *gb,
  866. int block_idx, int size,
  867. int block_pitch_sh2,
  868. const double *lsps, const double *prev_lsps,
  869. const struct frame_type_desc *frame_desc,
  870. float *excitation, float *synth)
  871. {
  872. double i_lsps[MAX_LSPS];
  873. float lpcs[MAX_LSPS];
  874. float fac;
  875. int n;
  876. if (frame_desc->acb_type == ACB_TYPE_NONE)
  877. synth_block_hardcoded(s, gb, block_idx, size, frame_desc, excitation);
  878. else
  879. synth_block_fcb_acb(s, gb, block_idx, size, block_pitch_sh2,
  880. frame_desc, excitation);
  881. /* convert interpolated LSPs to LPCs */
  882. fac = (block_idx + 0.5) / frame_desc->n_blocks;
  883. for (n = 0; n < s->lsps; n++) // LSF -> LSP
  884. i_lsps[n] = cos(prev_lsps[n] + fac * (lsps[n] - prev_lsps[n]));
  885. ff_acelp_lspd2lpc(i_lsps, lpcs, s->lsps >> 1);
  886. /* Speech synthesis */
  887. ff_celp_lp_synthesis_filterf(synth, lpcs, excitation, size, s->lsps);
  888. }
  889. /**
  890. * Synthesize output samples for a single frame.
  891. * @note we assume enough bits are available, caller should check.
  892. *
  893. * @param ctx WMA Voice decoder context
  894. * @param gb bit I/O context (s->gb or one for cross-packet superframes)
  895. * @param samples pointer to output sample buffer, has space for at least 160
  896. * samples
  897. * @param lsps LSP array
  898. * @param prev_lsps array of previous frame's LSPs
  899. * @param excitation target buffer for excitation signal
  900. * @param synth target buffer for synthesized speech data
  901. * @return 0 on success, <0 on error.
  902. */
  903. static int synth_frame(AVCodecContext *ctx, GetBitContext *gb,
  904. float *samples,
  905. const double *lsps, const double *prev_lsps,
  906. float *excitation, float *synth)
  907. {
  908. WMAVoiceContext *s = ctx->priv_data;
  909. int n, n_blocks_x2, log_n_blocks_x2, cur_pitch_val;
  910. int pitch[MAX_BLOCKS], last_block_pitch;
  911. /* Parse frame type ("frame header"), see frame_descs */
  912. int bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)],
  913. block_nsamples = MAX_FRAMESIZE / frame_descs[bd_idx].n_blocks;
  914. if (bd_idx < 0) {
  915. av_log(ctx, AV_LOG_ERROR,
  916. "Invalid frame type VLC code, skipping\n");
  917. return -1;
  918. }
  919. /* Pitch calculation for ACB_TYPE_ASYMMETRIC ("pitch-per-frame") */
  920. if (frame_descs[bd_idx].acb_type == ACB_TYPE_ASYMMETRIC) {
  921. /* Pitch is provided per frame, which is interpreted as the pitch of
  922. * the last sample of the last block of this frame. We can interpolate
  923. * the pitch of other blocks (and even pitch-per-sample) by gradually
  924. * incrementing/decrementing prev_frame_pitch to cur_pitch_val. */
  925. n_blocks_x2 = frame_descs[bd_idx].n_blocks << 1;
  926. log_n_blocks_x2 = frame_descs[bd_idx].log_n_blocks + 1;
  927. cur_pitch_val = s->min_pitch_val + get_bits(gb, s->pitch_nbits);
  928. cur_pitch_val = FFMIN(cur_pitch_val, s->max_pitch_val - 1);
  929. if (s->last_acb_type == ACB_TYPE_NONE ||
  930. 20 * abs(cur_pitch_val - s->last_pitch_val) >
  931. (cur_pitch_val + s->last_pitch_val))
  932. s->last_pitch_val = cur_pitch_val;
  933. /* pitch per block */
  934. for (n = 0; n < frame_descs[bd_idx].n_blocks; n++) {
  935. int fac = n * 2 + 1;
  936. pitch[n] = (MUL16(fac, cur_pitch_val) +
  937. MUL16((n_blocks_x2 - fac), s->last_pitch_val) +
  938. frame_descs[bd_idx].n_blocks) >> log_n_blocks_x2;
  939. }
  940. /* "pitch-diff-per-sample" for calculation of pitch per sample */
  941. s->pitch_diff_sh16 =
  942. ((cur_pitch_val - s->last_pitch_val) << 16) / MAX_FRAMESIZE;
  943. }
  944. /* Global gain (if silence) and pitch-adaptive window coordinates */
  945. switch (frame_descs[bd_idx].fcb_type) {
  946. case FCB_TYPE_SILENCE:
  947. s->silence_gain = wmavoice_gain_silence[get_bits(gb, 8)];
  948. break;
  949. case FCB_TYPE_AW_PULSES:
  950. aw_parse_coords(s, gb, pitch);
  951. break;
  952. }
  953. for (n = 0; n < frame_descs[bd_idx].n_blocks; n++) {
  954. int bl_pitch_sh2;
  955. /* Pitch calculation for ACB_TYPE_HAMMING ("pitch-per-block") */
  956. switch (frame_descs[bd_idx].acb_type) {
  957. case ACB_TYPE_HAMMING: {
  958. /* Pitch is given per block. Per-block pitches are encoded as an
  959. * absolute value for the first block, and then delta values
  960. * relative to this value) for all subsequent blocks. The scale of
  961. * this pitch value is semi-logaritmic compared to its use in the
  962. * decoder, so we convert it to normal scale also. */
  963. int block_pitch,
  964. t1 = (s->block_conv_table[1] - s->block_conv_table[0]) << 2,
  965. t2 = (s->block_conv_table[2] - s->block_conv_table[1]) << 1,
  966. t3 = s->block_conv_table[3] - s->block_conv_table[2] + 1;
  967. if (n == 0) {
  968. block_pitch = get_bits(gb, s->block_pitch_nbits);
  969. } else
  970. block_pitch = last_block_pitch - s->block_delta_pitch_hrange +
  971. get_bits(gb, s->block_delta_pitch_nbits);
  972. /* Convert last_ so that any next delta is within _range */
  973. last_block_pitch = av_clip(block_pitch,
  974. s->block_delta_pitch_hrange,
  975. s->block_pitch_range -
  976. s->block_delta_pitch_hrange);
  977. /* Convert semi-log-style scale back to normal scale */
  978. if (block_pitch < t1) {
  979. bl_pitch_sh2 = (s->block_conv_table[0] << 2) + block_pitch;
  980. } else {
  981. block_pitch -= t1;
  982. if (block_pitch < t2) {
  983. bl_pitch_sh2 =
  984. (s->block_conv_table[1] << 2) + (block_pitch << 1);
  985. } else {
  986. block_pitch -= t2;
  987. if (block_pitch < t3) {
  988. bl_pitch_sh2 =
  989. (s->block_conv_table[2] + block_pitch) << 2;
  990. } else
  991. bl_pitch_sh2 = s->block_conv_table[3] << 2;
  992. }
  993. }
  994. pitch[n] = bl_pitch_sh2 >> 2;
  995. break;
  996. }
  997. case ACB_TYPE_ASYMMETRIC: {
  998. bl_pitch_sh2 = pitch[n] << 2;
  999. break;
  1000. }
  1001. default: // ACB_TYPE_NONE has no pitch
  1002. bl_pitch_sh2 = 0;
  1003. break;
  1004. }
  1005. synth_block(s, gb, n, block_nsamples, bl_pitch_sh2,
  1006. lsps, prev_lsps, &frame_descs[bd_idx],
  1007. &excitation[n * block_nsamples],
  1008. &synth[n * block_nsamples]);
  1009. }
  1010. /* Averaging projection filter, if applicable. Else, just copy samples
  1011. * from synthesis buffer */
  1012. if (s->do_apf) {
  1013. // FIXME this is where APF would take place, currently not implemented
  1014. av_log_missing_feature(ctx, "APF", 0);
  1015. s->do_apf = 0;
  1016. } //else
  1017. for (n = 0; n < 160; n++)
  1018. samples[n] = av_clipf(synth[n], -1.0, 1.0);
  1019. /* Cache values for next frame */
  1020. s->frame_cntr++;
  1021. if (s->frame_cntr >= 0xFFFF) s->frame_cntr -= 0xFFFF; // i.e. modulo (%)
  1022. s->last_acb_type = frame_descs[bd_idx].acb_type;
  1023. switch (frame_descs[bd_idx].acb_type) {
  1024. case ACB_TYPE_NONE:
  1025. s->last_pitch_val = 0;
  1026. break;
  1027. case ACB_TYPE_ASYMMETRIC:
  1028. s->last_pitch_val = cur_pitch_val;
  1029. break;
  1030. case ACB_TYPE_HAMMING:
  1031. s->last_pitch_val = pitch[frame_descs[bd_idx].n_blocks - 1];
  1032. break;
  1033. }
  1034. return 0;
  1035. }
  1036. /**
  1037. * Ensure minimum value for first item, maximum value for last value,
  1038. * proper spacing between each value and proper ordering.
  1039. *
  1040. * @param lsps array of LSPs
  1041. * @param num size of LSP array
  1042. *
  1043. * @note basically a double version of #ff_acelp_reorder_lsf(), might be
  1044. * useful to put in a generic location later on. Parts are also
  1045. * present in #ff_set_min_dist_lsf() + #ff_sort_nearly_sorted_floats(),
  1046. * which is in float.
  1047. */
  1048. static void stabilize_lsps(double *lsps, int num)
  1049. {
  1050. int n, m, l;
  1051. /* set minimum value for first, maximum value for last and minimum
  1052. * spacing between LSF values.
  1053. * Very similar to ff_set_min_dist_lsf(), but in double. */
  1054. lsps[0] = FFMAX(lsps[0], 0.0015 * M_PI);
  1055. for (n = 1; n < num; n++)
  1056. lsps[n] = FFMAX(lsps[n], lsps[n - 1] + 0.0125 * M_PI);
  1057. lsps[num - 1] = FFMIN(lsps[num - 1], 0.9985 * M_PI);
  1058. /* reorder (looks like one-time / non-recursed bubblesort).
  1059. * Very similar to ff_sort_nearly_sorted_floats(), but in double. */
  1060. for (n = 1; n < num; n++) {
  1061. if (lsps[n] < lsps[n - 1]) {
  1062. for (m = 1; m < num; m++) {
  1063. double tmp = lsps[m];
  1064. for (l = m - 1; l >= 0; l--) {
  1065. if (lsps[l] <= tmp) break;
  1066. lsps[l + 1] = lsps[l];
  1067. }
  1068. lsps[l + 1] = tmp;
  1069. }
  1070. break;
  1071. }
  1072. }
  1073. }
  1074. /**
  1075. * Test if there's enough bits to read 1 superframe.
  1076. *
  1077. * @param orig_gb bit I/O context used for reading. This function
  1078. * does not modify the state of the bitreader; it
  1079. * only uses it to copy the current stream position
  1080. * @param s WMA Voice decoding context private data
  1081. * @returns -1 if unsupported, 1 on not enough bits or 0 if OK.
  1082. */
  1083. static int check_bits_for_superframe(GetBitContext *orig_gb,
  1084. WMAVoiceContext *s)
  1085. {
  1086. GetBitContext s_gb, *gb = &s_gb;
  1087. int n, need_bits, bd_idx;
  1088. const struct frame_type_desc *frame_desc;
  1089. /* initialize a copy */
  1090. init_get_bits(gb, orig_gb->buffer, orig_gb->size_in_bits);
  1091. skip_bits_long(gb, get_bits_count(orig_gb));
  1092. assert(get_bits_left(gb) == get_bits_left(orig_gb));
  1093. /* superframe header */
  1094. if (get_bits_left(gb) < 14)
  1095. return 1;
  1096. if (!get_bits1(gb))
  1097. return -1; // WMAPro-in-WMAVoice superframe
  1098. if (get_bits1(gb)) skip_bits(gb, 12); // number of samples in superframe
  1099. if (s->has_residual_lsps) { // residual LSPs (for all frames)
  1100. if (get_bits_left(gb) < s->sframe_lsp_bitsize)
  1101. return 1;
  1102. skip_bits_long(gb, s->sframe_lsp_bitsize);
  1103. }
  1104. /* frames */
  1105. for (n = 0; n < MAX_FRAMES; n++) {
  1106. int aw_idx_is_ext = 0;
  1107. if (!s->has_residual_lsps) { // independent LSPs (per-frame)
  1108. if (get_bits_left(gb) < s->frame_lsp_bitsize) return 1;
  1109. skip_bits_long(gb, s->frame_lsp_bitsize);
  1110. }
  1111. bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)];
  1112. if (bd_idx < 0)
  1113. return -1; // invalid frame type VLC code
  1114. frame_desc = &frame_descs[bd_idx];
  1115. if (frame_desc->acb_type == ACB_TYPE_ASYMMETRIC) {
  1116. if (get_bits_left(gb) < s->pitch_nbits)
  1117. return 1;
  1118. skip_bits_long(gb, s->pitch_nbits);
  1119. }
  1120. if (frame_desc->fcb_type == FCB_TYPE_SILENCE) {
  1121. skip_bits(gb, 8);
  1122. } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) {
  1123. int tmp = get_bits(gb, 6);
  1124. if (tmp >= 0x36) {
  1125. skip_bits(gb, 2);
  1126. aw_idx_is_ext = 1;
  1127. }
  1128. }
  1129. /* blocks */
  1130. if (frame_desc->acb_type == ACB_TYPE_HAMMING) {
  1131. need_bits = s->block_pitch_nbits +
  1132. (frame_desc->n_blocks - 1) * s->block_delta_pitch_nbits;
  1133. } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) {
  1134. need_bits = 2 * !aw_idx_is_ext;
  1135. } else
  1136. need_bits = 0;
  1137. need_bits += frame_desc->frame_size;
  1138. if (get_bits_left(gb) < need_bits)
  1139. return 1;
  1140. skip_bits_long(gb, need_bits);
  1141. }
  1142. return 0;
  1143. }
  1144. /**
  1145. * Synthesize output samples for a single superframe. If we have any data
  1146. * cached in s->sframe_cache, that will be used instead of whatever is loaded
  1147. * in s->gb.
  1148. *
  1149. * WMA Voice superframes contain 3 frames, each containing 160 audio samples,
  1150. * to give a total of 480 samples per frame. See #synth_frame() for frame
  1151. * parsing. In addition to 3 frames, superframes can also contain the LSPs
  1152. * (if these are globally specified for all frames (residually); they can
  1153. * also be specified individually per-frame. See the s->has_residual_lsps
  1154. * option), and can specify the number of samples encoded in this superframe
  1155. * (if less than 480), usually used to prevent blanks at track boundaries.
  1156. *
  1157. * @param ctx WMA Voice decoder context
  1158. * @param samples pointer to output buffer for voice samples
  1159. * @param data_size pointer containing the size of #samples on input, and the
  1160. * amount of #samples filled on output
  1161. * @return 0 on success, <0 on error or 1 if there was not enough data to
  1162. * fully parse the superframe
  1163. */
  1164. static int synth_superframe(AVCodecContext *ctx,
  1165. float *samples, int *data_size)
  1166. {
  1167. WMAVoiceContext *s = ctx->priv_data;
  1168. GetBitContext *gb = &s->gb, s_gb;
  1169. int n, res, n_samples = 480;
  1170. double lsps[MAX_FRAMES][MAX_LSPS];
  1171. const double *mean_lsf = s->lsps == 16 ?
  1172. wmavoice_mean_lsf16[s->lsp_def_mode] : wmavoice_mean_lsf10[s->lsp_def_mode];
  1173. float excitation[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE + 12];
  1174. float synth[MAX_LSPS + MAX_SFRAMESIZE];
  1175. memcpy(synth, s->synth_history,
  1176. s->lsps * sizeof(*synth));
  1177. memcpy(excitation, s->excitation_history,
  1178. s->history_nsamples * sizeof(*excitation));
  1179. if (s->sframe_cache_size > 0) {
  1180. gb = &s_gb;
  1181. init_get_bits(gb, s->sframe_cache, s->sframe_cache_size);
  1182. s->sframe_cache_size = 0;
  1183. }
  1184. if ((res = check_bits_for_superframe(gb, s)) == 1) return 1;
  1185. /* First bit is speech/music bit, it differentiates between WMAVoice
  1186. * speech samples (the actual codec) and WMAVoice music samples, which
  1187. * are really WMAPro-in-WMAVoice-superframes. I've never seen those in
  1188. * the wild yet. */
  1189. if (!get_bits1(gb)) {
  1190. av_log_missing_feature(ctx, "WMAPro-in-WMAVoice support", 1);
  1191. return -1;
  1192. }
  1193. /* (optional) nr. of samples in superframe; always <= 480 and >= 0 */
  1194. if (get_bits1(gb)) {
  1195. if ((n_samples = get_bits(gb, 12)) > 480) {
  1196. av_log(ctx, AV_LOG_ERROR,
  1197. "Superframe encodes >480 samples (%d), not allowed\n",
  1198. n_samples);
  1199. return -1;
  1200. }
  1201. }
  1202. /* Parse LSPs, if global for the superframe (can also be per-frame). */
  1203. if (s->has_residual_lsps) {
  1204. double prev_lsps[MAX_LSPS], a1[MAX_LSPS * 2], a2[MAX_LSPS * 2];
  1205. for (n = 0; n < s->lsps; n++)
  1206. prev_lsps[n] = s->prev_lsps[n] - mean_lsf[n];
  1207. if (s->lsps == 10) {
  1208. dequant_lsp10r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);
  1209. } else /* s->lsps == 16 */
  1210. dequant_lsp16r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);
  1211. for (n = 0; n < s->lsps; n++) {
  1212. lsps[0][n] = mean_lsf[n] + (a1[n] - a2[n * 2]);
  1213. lsps[1][n] = mean_lsf[n] + (a1[s->lsps + n] - a2[n * 2 + 1]);
  1214. lsps[2][n] += mean_lsf[n];
  1215. }
  1216. for (n = 0; n < 3; n++)
  1217. stabilize_lsps(lsps[n], s->lsps);
  1218. }
  1219. /* Parse frames, optionally preceeded by per-frame (independent) LSPs. */
  1220. for (n = 0; n < 3; n++) {
  1221. if (!s->has_residual_lsps) {
  1222. int m;
  1223. if (s->lsps == 10) {
  1224. dequant_lsp10i(gb, lsps[n]);
  1225. } else /* s->lsps == 16 */
  1226. dequant_lsp16i(gb, lsps[n]);
  1227. for (m = 0; m < s->lsps; m++)
  1228. lsps[n][m] += mean_lsf[m];
  1229. stabilize_lsps(lsps[n], s->lsps);
  1230. }
  1231. if ((res = synth_frame(ctx, gb,
  1232. &samples[n * MAX_FRAMESIZE],
  1233. lsps[n], n == 0 ? s->prev_lsps : lsps[n - 1],
  1234. &excitation[s->history_nsamples + n * MAX_FRAMESIZE],
  1235. &synth[s->lsps + n * MAX_FRAMESIZE])))
  1236. return res;
  1237. }
  1238. /* Statistics? FIXME - we don't check for length, a slight overrun
  1239. * will be caught by internal buffer padding, and anything else
  1240. * will be skipped, not read. */
  1241. if (get_bits1(gb)) {
  1242. res = get_bits(gb, 4);
  1243. skip_bits(gb, 10 * (res + 1));
  1244. }
  1245. /* Specify nr. of output samples */
  1246. *data_size = n_samples * sizeof(float);
  1247. /* Update history */
  1248. memcpy(s->prev_lsps, lsps[2],
  1249. s->lsps * sizeof(*s->prev_lsps));
  1250. memcpy(s->synth_history, &synth[MAX_SFRAMESIZE],
  1251. s->lsps * sizeof(*synth));
  1252. memcpy(s->excitation_history, &excitation[MAX_SFRAMESIZE],
  1253. s->history_nsamples * sizeof(*excitation));
  1254. return 0;
  1255. }
  1256. /**
  1257. * Parse the packet header at the start of each packet (input data to this
  1258. * decoder).
  1259. *
  1260. * @param s WMA Voice decoding context private data
  1261. * @returns 1 if not enough bits were available, or 0 on success.
  1262. */
  1263. static int parse_packet_header(WMAVoiceContext *s)
  1264. {
  1265. GetBitContext *gb = &s->gb;
  1266. unsigned int res;
  1267. if (get_bits_left(gb) < 11)
  1268. return 1;
  1269. skip_bits(gb, 4); // packet sequence number
  1270. s->has_residual_lsps = get_bits1(gb);
  1271. do {
  1272. res = get_bits(gb, 6); // number of superframes per packet
  1273. // (minus first one if there is spillover)
  1274. if (get_bits_left(gb) < 6 * (res == 0x3F) + s->spillover_bitsize)
  1275. return 1;
  1276. } while (res == 0x3F);
  1277. s->spillover_nbits = get_bits(gb, s->spillover_bitsize);
  1278. return 0;
  1279. }
  1280. /**
  1281. * Copy (unaligned) bits from gb/data/size to pb.
  1282. *
  1283. * @param pb target buffer to copy bits into
  1284. * @param data source buffer to copy bits from
  1285. * @param size size of the source data, in bytes
  1286. * @param gb bit I/O context specifying the current position in the source.
  1287. * data. This function might use this to align the bit position to
  1288. * a whole-byte boundary before calling #ff_copy_bits() on aligned
  1289. * source data
  1290. * @param nbits the amount of bits to copy from source to target
  1291. *
  1292. * @note after calling this function, the current position in the input bit
  1293. * I/O context is undefined.
  1294. */
  1295. static void copy_bits(PutBitContext *pb,
  1296. const uint8_t *data, int size,
  1297. GetBitContext *gb, int nbits)
  1298. {
  1299. int rmn_bytes, rmn_bits;
  1300. rmn_bits = rmn_bytes = get_bits_left(gb);
  1301. if (rmn_bits < nbits)
  1302. return;
  1303. rmn_bits &= 7; rmn_bytes >>= 3;
  1304. if ((rmn_bits = FFMIN(rmn_bits, nbits)) > 0)
  1305. put_bits(pb, rmn_bits, get_bits(gb, rmn_bits));
  1306. ff_copy_bits(pb, data + size - rmn_bytes,
  1307. FFMIN(nbits - rmn_bits, rmn_bytes << 3));
  1308. }
  1309. /**
  1310. * Packet decoding: a packet is anything that the (ASF) demuxer contains,
  1311. * and we expect that the demuxer / application provides it to us as such
  1312. * (else you'll probably get garbage as output). Every packet has a size of
  1313. * ctx->block_align bytes, starts with a packet header (see
  1314. * #parse_packet_header()), and then a series of superframes. Superframe
  1315. * boundaries may exceed packets, i.e. superframes can split data over
  1316. * multiple (two) packets.
  1317. *
  1318. * For more information about frames, see #synth_superframe().
  1319. */
  1320. static int wmavoice_decode_packet(AVCodecContext *ctx, void *data,
  1321. int *data_size, AVPacket *avpkt)
  1322. {
  1323. WMAVoiceContext *s = ctx->priv_data;
  1324. GetBitContext *gb = &s->gb;
  1325. int size, res, pos;
  1326. if (*data_size < 480 * sizeof(float)) {
  1327. av_log(ctx, AV_LOG_ERROR,
  1328. "Output buffer too small (%d given - %lu needed)\n",
  1329. *data_size, 480 * sizeof(float));
  1330. return -1;
  1331. }
  1332. *data_size = 0;
  1333. /* Packets are sometimes a multiple of ctx->block_align, with a packet
  1334. * header at each ctx->block_align bytes. However, FFmpeg's ASF demuxer
  1335. * feeds us ASF packets, which may concatenate multiple "codec" packets
  1336. * in a single "muxer" packet, so we artificially emulate that by
  1337. * capping the packet size at ctx->block_align. */
  1338. for (size = avpkt->size; size > ctx->block_align; size -= ctx->block_align);
  1339. if (!size)
  1340. return 0;
  1341. init_get_bits(&s->gb, avpkt->data, size << 3);
  1342. /* size == ctx->block_align is used to indicate whether we are dealing with
  1343. * a new packet or a packet of which we already read the packet header
  1344. * previously. */
  1345. if (size == ctx->block_align) { // new packet header
  1346. if ((res = parse_packet_header(s)) < 0)
  1347. return res;
  1348. /* If the packet header specifies a s->spillover_nbits, then we want
  1349. * to push out all data of the previous packet (+ spillover) before
  1350. * continuing to parse new superframes in the current packet. */
  1351. if (s->spillover_nbits > 0) {
  1352. if (s->sframe_cache_size > 0) {
  1353. int cnt = get_bits_count(gb);
  1354. copy_bits(&s->pb, avpkt->data, size, gb, s->spillover_nbits);
  1355. flush_put_bits(&s->pb);
  1356. s->sframe_cache_size += s->spillover_nbits;
  1357. if ((res = synth_superframe(ctx, data, data_size)) == 0 &&
  1358. *data_size > 0) {
  1359. cnt += s->spillover_nbits;
  1360. s->skip_bits_next = cnt & 7;
  1361. return cnt >> 3;
  1362. } else
  1363. skip_bits_long (gb, s->spillover_nbits - cnt +
  1364. get_bits_count(gb)); // resync
  1365. } else
  1366. skip_bits_long(gb, s->spillover_nbits); // resync
  1367. }
  1368. } else if (s->skip_bits_next)
  1369. skip_bits(gb, s->skip_bits_next);
  1370. /* Try parsing superframes in current packet */
  1371. s->sframe_cache_size = 0;
  1372. s->skip_bits_next = 0;
  1373. pos = get_bits_left(gb);
  1374. if ((res = synth_superframe(ctx, data, data_size)) < 0) {
  1375. return res;
  1376. } else if (*data_size > 0) {
  1377. int cnt = get_bits_count(gb);
  1378. s->skip_bits_next = cnt & 7;
  1379. return cnt >> 3;
  1380. } else if ((s->sframe_cache_size = pos) > 0) {
  1381. /* rewind bit reader to start of last (incomplete) superframe... */
  1382. init_get_bits(gb, avpkt->data, size << 3);
  1383. skip_bits_long(gb, (size << 3) - pos);
  1384. assert(get_bits_left(gb) == pos);
  1385. /* ...and cache it for spillover in next packet */
  1386. init_put_bits(&s->pb, s->sframe_cache, SFRAME_CACHE_MAXSIZE);
  1387. copy_bits(&s->pb, avpkt->data, size, gb, s->sframe_cache_size);
  1388. // FIXME bad - just copy bytes as whole and add use the
  1389. // skip_bits_next field
  1390. }
  1391. return size;
  1392. }
  1393. static av_cold void wmavoice_flush(AVCodecContext *ctx)
  1394. {
  1395. WMAVoiceContext *s = ctx->priv_data;
  1396. int n;
  1397. s->sframe_cache_size = 0;
  1398. s->skip_bits_next = 0;
  1399. for (n = 0; n < s->lsps; n++)
  1400. s->prev_lsps[n] = M_PI * (n + 1.0) / (s->lsps + 1.0);
  1401. memset(s->excitation_history, 0,
  1402. sizeof(*s->excitation_history) * MAX_SIGNAL_HISTORY);
  1403. memset(s->synth_history, 0,
  1404. sizeof(*s->synth_history) * MAX_LSPS);
  1405. memset(s->gain_pred_err, 0,
  1406. sizeof(s->gain_pred_err));
  1407. }
  1408. AVCodec wmavoice_decoder = {
  1409. "wmavoice",
  1410. CODEC_TYPE_AUDIO,
  1411. CODEC_ID_WMAVOICE,
  1412. sizeof(WMAVoiceContext),
  1413. wmavoice_decode_init,
  1414. NULL,
  1415. NULL,
  1416. wmavoice_decode_packet,
  1417. CODEC_CAP_SUBFRAMES,
  1418. .flush = wmavoice_flush,
  1419. .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Voice"),
  1420. };