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.

612 lines
19KB

  1. /*
  2. * SIPR / ACELP.NET decoder
  3. *
  4. * Copyright (c) 2008 Vladimir Voroshilov
  5. * Copyright (c) 2009 Vitor Sessak
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include <math.h>
  24. #include <stdint.h>
  25. #include "libavutil/mathematics.h"
  26. #include "avcodec.h"
  27. #define ALT_BITSTREAM_READER_LE
  28. #include "get_bits.h"
  29. #include "dsputil.h"
  30. #include "lsp.h"
  31. #include "celp_math.h"
  32. #include "acelp_vectors.h"
  33. #include "acelp_pitch_delay.h"
  34. #include "acelp_filters.h"
  35. #include "celp_filters.h"
  36. #define LSFQ_DIFF_MIN (0.0125 * M_PI)
  37. #define LP_FILTER_ORDER 10
  38. /** Number of past samples needed for excitation interpolation */
  39. #define L_INTERPOL (LP_FILTER_ORDER + 1)
  40. /** Subframe size for all modes except 16k */
  41. #define SUBFR_SIZE 48
  42. #define MAX_SUBFRAME_COUNT 5
  43. #include "siprdata.h"
  44. typedef enum {
  45. MODE_16k,
  46. MODE_8k5,
  47. MODE_6k5,
  48. MODE_5k0,
  49. MODE_COUNT
  50. } SiprMode;
  51. typedef struct {
  52. const char *mode_name;
  53. uint16_t bits_per_frame;
  54. uint8_t subframe_count;
  55. uint8_t frames_per_packet;
  56. float pitch_sharp_factor;
  57. /* bitstream parameters */
  58. uint8_t number_of_fc_indexes;
  59. /** size in bits of the i-th stage vector of quantizer */
  60. uint8_t vq_indexes_bits[5];
  61. /** size in bits of the adaptive-codebook index for every subframe */
  62. uint8_t pitch_delay_bits[5];
  63. uint8_t gp_index_bits;
  64. uint8_t fc_index_bits[10]; ///< size in bits of the fixed codebook indexes
  65. uint8_t gc_index_bits; ///< size in bits of the gain codebook indexes
  66. } SiprModeParam;
  67. static const SiprModeParam modes[MODE_COUNT] = {
  68. [MODE_8k5] = {
  69. .mode_name = "8k5",
  70. .bits_per_frame = 152,
  71. .subframe_count = 3,
  72. .frames_per_packet = 1,
  73. .pitch_sharp_factor = 0.8,
  74. .number_of_fc_indexes = 3,
  75. .vq_indexes_bits = {6, 7, 7, 7, 5},
  76. .pitch_delay_bits = {8, 5, 5},
  77. .gp_index_bits = 0,
  78. .fc_index_bits = {9, 9, 9},
  79. .gc_index_bits = 7
  80. },
  81. [MODE_6k5] = {
  82. .mode_name = "6k5",
  83. .bits_per_frame = 232,
  84. .subframe_count = 3,
  85. .frames_per_packet = 2,
  86. .pitch_sharp_factor = 0.8,
  87. .number_of_fc_indexes = 3,
  88. .vq_indexes_bits = {6, 7, 7, 7, 5},
  89. .pitch_delay_bits = {8, 5, 5},
  90. .gp_index_bits = 0,
  91. .fc_index_bits = {5, 5, 5},
  92. .gc_index_bits = 7
  93. },
  94. [MODE_5k0] = {
  95. .mode_name = "5k0",
  96. .bits_per_frame = 296,
  97. .subframe_count = 5,
  98. .frames_per_packet = 2,
  99. .pitch_sharp_factor = 0.85,
  100. .number_of_fc_indexes = 1,
  101. .vq_indexes_bits = {6, 7, 7, 7, 5},
  102. .pitch_delay_bits = {8, 5, 8, 5, 5},
  103. .gp_index_bits = 0,
  104. .fc_index_bits = {10},
  105. .gc_index_bits = 7
  106. }
  107. };
  108. typedef struct {
  109. AVCodecContext *avctx;
  110. DSPContext dsp;
  111. SiprMode mode;
  112. float past_pitch_gain;
  113. float lsf_history[LP_FILTER_ORDER];
  114. float excitation[L_INTERPOL + PITCH_DELAY_MAX + 5*SUBFR_SIZE];
  115. DECLARE_ALIGNED_16(float, synth_buf[LP_FILTER_ORDER + 5*SUBFR_SIZE + 6]);
  116. float lsp_history[LP_FILTER_ORDER];
  117. float gain_mem;
  118. float energy_history[4];
  119. float highpass_filt_mem[2];
  120. float postfilter_mem[PITCH_DELAY_MAX + LP_FILTER_ORDER];
  121. /* 5k0 */
  122. float tilt_mem;
  123. float postfilter_agc;
  124. float postfilter_mem5k0[PITCH_DELAY_MAX + LP_FILTER_ORDER];
  125. float postfilter_syn5k0[LP_FILTER_ORDER + SUBFR_SIZE*5];
  126. } SiprContext;
  127. typedef struct {
  128. int vq_indexes[5];
  129. int pitch_delay[5]; ///< pitch delay
  130. int gp_index[5]; ///< adaptive-codebook gain indexes
  131. int16_t fc_indexes[5][10]; ///< fixed-codebook indexes
  132. int gc_index[5]; ///< fixed-codebook gain indexes
  133. } SiprParameters;
  134. static void dequant(float *out, const int *idx, const float *cbs[])
  135. {
  136. int i;
  137. int stride = 2;
  138. int num_vec = 5;
  139. for (i = 0; i < num_vec; i++)
  140. memcpy(out + stride*i, cbs[i] + stride*idx[i], stride*sizeof(float));
  141. }
  142. static void lsf_decode_fp(float *lsfnew, float *lsf_history,
  143. const SiprParameters *parm)
  144. {
  145. int i;
  146. float lsf_tmp[LP_FILTER_ORDER];
  147. dequant(lsf_tmp, parm->vq_indexes, lsf_codebooks);
  148. for (i = 0; i < LP_FILTER_ORDER; i++)
  149. lsfnew[i] = lsf_history[i] * 0.33 + lsf_tmp[i] + mean_lsf[i];
  150. ff_sort_nearly_sorted_floats(lsfnew, LP_FILTER_ORDER - 1);
  151. /* Note that a minimum distance is not enforced between the last value and
  152. the previous one, contrary to what is done in ff_acelp_reorder_lsf() */
  153. ff_set_min_dist_lsf(lsfnew, LSFQ_DIFF_MIN, LP_FILTER_ORDER - 1);
  154. lsfnew[9] = FFMIN(lsfnew[LP_FILTER_ORDER - 1], 1.3 * M_PI);
  155. memcpy(lsf_history, lsf_tmp, LP_FILTER_ORDER * sizeof(*lsf_history));
  156. for (i = 0; i < LP_FILTER_ORDER - 1; i++)
  157. lsfnew[i] = cos(lsfnew[i]);
  158. lsfnew[LP_FILTER_ORDER - 1] *= 6.153848 / M_PI;
  159. }
  160. /** Apply pitch lag to the fixed vector (AMR section 6.1.2). */
  161. static void pitch_sharpening(int pitch_lag_int, float beta,
  162. float *fixed_vector)
  163. {
  164. int i;
  165. for (i = pitch_lag_int; i < SUBFR_SIZE; i++)
  166. fixed_vector[i] += beta * fixed_vector[i - pitch_lag_int];
  167. }
  168. /**
  169. * Extracts decoding parameters from the input bitstream.
  170. * @param parms parameters structure
  171. * @param pgb pointer to initialized GetBitContext structure
  172. */
  173. static void decode_parameters(SiprParameters* parms, GetBitContext *pgb,
  174. const SiprModeParam *p)
  175. {
  176. int i, j;
  177. for (i = 0; i < 5; i++)
  178. parms->vq_indexes[i] = get_bits(pgb, p->vq_indexes_bits[i]);
  179. for (i = 0; i < p->subframe_count; i++) {
  180. parms->pitch_delay[i] = get_bits(pgb, p->pitch_delay_bits[i]);
  181. parms->gp_index[i] = get_bits(pgb, p->gp_index_bits);
  182. for (j = 0; j < p->number_of_fc_indexes; j++)
  183. parms->fc_indexes[i][j] = get_bits(pgb, p->fc_index_bits[j]);
  184. parms->gc_index[i] = get_bits(pgb, p->gc_index_bits);
  185. }
  186. }
  187. static void lsp2lpc_sipr(const double *lsp, float *Az)
  188. {
  189. int lp_half_order = LP_FILTER_ORDER >> 1;
  190. double buf[(LP_FILTER_ORDER >> 1) + 1];
  191. double pa[(LP_FILTER_ORDER >> 1) + 1];
  192. double *qa = buf + 1;
  193. int i,j;
  194. qa[-1] = 0.0;
  195. ff_lsp2polyf(lsp , pa, lp_half_order );
  196. ff_lsp2polyf(lsp + 1, qa, lp_half_order - 1);
  197. for (i = 1, j = LP_FILTER_ORDER - 1; i < lp_half_order; i++, j--) {
  198. double paf = pa[i] * (1 + lsp[LP_FILTER_ORDER - 1]);
  199. double qaf = (qa[i] - qa[i-2]) * (1 - lsp[LP_FILTER_ORDER - 1]);
  200. Az[i-1] = (paf + qaf) * 0.5;
  201. Az[j-1] = (paf - qaf) * 0.5;
  202. }
  203. Az[lp_half_order - 1] = (1.0 + lsp[LP_FILTER_ORDER - 1]) *
  204. pa[lp_half_order] * 0.5;
  205. Az[LP_FILTER_ORDER - 1] = lsp[LP_FILTER_ORDER - 1];
  206. }
  207. static void sipr_decode_lp(float *lsfnew, const float *lsfold, float *Az,
  208. int num_subfr)
  209. {
  210. double lsfint[LP_FILTER_ORDER];
  211. int i,j;
  212. float t, t0 = 1.0 / num_subfr;
  213. t = t0 * 0.5;
  214. for (i = 0; i < num_subfr; i++) {
  215. for (j = 0; j < LP_FILTER_ORDER; j++)
  216. lsfint[j] = lsfold[j] * (1 - t) + t * lsfnew[j];
  217. lsp2lpc_sipr(lsfint, Az);
  218. Az += LP_FILTER_ORDER;
  219. t += t0;
  220. }
  221. }
  222. /**
  223. * Evaluates the adaptative impulse response.
  224. */
  225. static void eval_ir(const float *Az, int pitch_lag, float *freq,
  226. float pitch_sharp_factor)
  227. {
  228. float tmp1[SUBFR_SIZE+1], tmp2[LP_FILTER_ORDER+1];
  229. int i;
  230. tmp1[0] = 1.;
  231. for (i = 0; i < LP_FILTER_ORDER; i++) {
  232. tmp1[i+1] = Az[i] * ff_pow_0_55[i];
  233. tmp2[i ] = Az[i] * ff_pow_0_7 [i];
  234. }
  235. memset(tmp1 + 11, 0, 37 * sizeof(float));
  236. ff_celp_lp_synthesis_filterf(freq, tmp2, tmp1, SUBFR_SIZE,
  237. LP_FILTER_ORDER);
  238. pitch_sharpening(pitch_lag, pitch_sharp_factor, freq);
  239. }
  240. /**
  241. * Evaluates the convolution of a vector with a sparse vector.
  242. */
  243. static void convolute_with_sparse(float *out, const AMRFixed *pulses,
  244. const float *shape, int length)
  245. {
  246. int i, j;
  247. memset(out, 0, length*sizeof(float));
  248. for (i = 0; i < pulses->n; i++)
  249. for (j = pulses->x[i]; j < length; j++)
  250. out[j] += pulses->y[i] * shape[j - pulses->x[i]];
  251. }
  252. /**
  253. * Apply postfilter, very similar to AMR one.
  254. */
  255. static void postfilter_5k0(SiprContext *ctx, const float *lpc, float *samples)
  256. {
  257. float buf[SUBFR_SIZE + LP_FILTER_ORDER];
  258. float *pole_out = buf + LP_FILTER_ORDER;
  259. float lpc_n[LP_FILTER_ORDER];
  260. float lpc_d[LP_FILTER_ORDER];
  261. int i;
  262. for (i = 0; i < LP_FILTER_ORDER; i++) {
  263. lpc_d[i] = lpc[i] * ff_pow_0_75[i];
  264. lpc_n[i] = lpc[i] * pow_0_5 [i];
  265. };
  266. memcpy(pole_out - LP_FILTER_ORDER, ctx->postfilter_mem,
  267. LP_FILTER_ORDER*sizeof(float));
  268. ff_celp_lp_synthesis_filterf(pole_out, lpc_d, samples, SUBFR_SIZE,
  269. LP_FILTER_ORDER);
  270. memcpy(ctx->postfilter_mem, pole_out + SUBFR_SIZE - LP_FILTER_ORDER,
  271. LP_FILTER_ORDER*sizeof(float));
  272. ff_tilt_compensation(&ctx->tilt_mem, 0.4, pole_out, SUBFR_SIZE);
  273. memcpy(pole_out - LP_FILTER_ORDER, ctx->postfilter_mem5k0,
  274. LP_FILTER_ORDER*sizeof(*pole_out));
  275. memcpy(ctx->postfilter_mem5k0, pole_out + SUBFR_SIZE - LP_FILTER_ORDER,
  276. LP_FILTER_ORDER*sizeof(*pole_out));
  277. ff_celp_lp_zero_synthesis_filterf(samples, lpc_n, pole_out, SUBFR_SIZE,
  278. LP_FILTER_ORDER);
  279. }
  280. static void decode_fixed_sparse(AMRFixed *fixed_sparse, const int16_t *pulses,
  281. SiprMode mode, int low_gain)
  282. {
  283. int i;
  284. switch (mode) {
  285. case MODE_6k5:
  286. for (i = 0; i < 3; i++) {
  287. fixed_sparse->x[i] = 3 * (pulses[i] & 0xf) + i;
  288. fixed_sparse->y[i] = pulses[i] & 0x10 ? -1 : 1;
  289. }
  290. fixed_sparse->n = 3;
  291. break;
  292. case MODE_8k5:
  293. for (i = 0; i < 3; i++) {
  294. fixed_sparse->x[2*i ] = 3 * ((pulses[i] >> 4) & 0xf) + i;
  295. fixed_sparse->x[2*i + 1] = 3 * ( pulses[i] & 0xf) + i;
  296. fixed_sparse->y[2*i ] = (pulses[i] & 0x100) ? -1.0: 1.0;
  297. fixed_sparse->y[2*i + 1] =
  298. (fixed_sparse->x[2*i + 1] < fixed_sparse->x[2*i]) ?
  299. -fixed_sparse->y[2*i ] : fixed_sparse->y[2*i];
  300. }
  301. fixed_sparse->n = 6;
  302. break;
  303. case MODE_5k0:
  304. default:
  305. if (low_gain) {
  306. int offset = (pulses[0] & 0x200) ? 2 : 0;
  307. int val = pulses[0];
  308. for (i = 0; i < 3; i++) {
  309. int index = (val & 0x7) * 6 + 4 - i*2;
  310. fixed_sparse->y[i] = (offset + index) & 0x3 ? -1 : 1;
  311. fixed_sparse->x[i] = index;
  312. val >>= 3;
  313. }
  314. fixed_sparse->n = 3;
  315. } else {
  316. int pulse_subset = (pulses[0] >> 8) & 1;
  317. fixed_sparse->x[0] = ((pulses[0] >> 4) & 15) * 3 + pulse_subset;
  318. fixed_sparse->x[1] = ( pulses[0] & 15) * 3 + pulse_subset + 1;
  319. fixed_sparse->y[0] = pulses[0] & 0x200 ? -1 : 1;
  320. fixed_sparse->y[1] = -fixed_sparse->y[0];
  321. fixed_sparse->n = 2;
  322. }
  323. break;
  324. }
  325. }
  326. static void decode_frame(SiprContext *ctx, SiprParameters *params,
  327. float *out_data)
  328. {
  329. int i, j;
  330. int subframe_count = modes[ctx->mode].subframe_count;
  331. int frame_size = subframe_count * SUBFR_SIZE;
  332. float Az[LP_FILTER_ORDER * MAX_SUBFRAME_COUNT];
  333. float *excitation;
  334. float ir_buf[SUBFR_SIZE + LP_FILTER_ORDER];
  335. float lsf_new[LP_FILTER_ORDER];
  336. float *impulse_response = ir_buf + LP_FILTER_ORDER;
  337. float *synth = ctx->synth_buf + 16; // 16 instead of LP_FILTER_ORDER for
  338. // memory alignment
  339. int t0_first = 0;
  340. AMRFixed fixed_cb;
  341. memset(ir_buf, 0, LP_FILTER_ORDER * sizeof(float));
  342. lsf_decode_fp(lsf_new, ctx->lsf_history, params);
  343. sipr_decode_lp(lsf_new, ctx->lsp_history, Az, subframe_count);
  344. memcpy(ctx->lsp_history, lsf_new, LP_FILTER_ORDER * sizeof(float));
  345. excitation = ctx->excitation + PITCH_DELAY_MAX + L_INTERPOL;
  346. for (i = 0; i < subframe_count; i++) {
  347. float *pAz = Az + i*LP_FILTER_ORDER;
  348. float fixed_vector[SUBFR_SIZE];
  349. int T0,T0_frac;
  350. float pitch_gain, gain_code, avg_energy;
  351. ff_decode_pitch_lag(&T0, &T0_frac, params->pitch_delay[i], t0_first, i,
  352. ctx->mode == MODE_5k0, 6);
  353. if (i == 0 || (i == 2 && ctx->mode == MODE_5k0))
  354. t0_first = T0;
  355. ff_acelp_interpolatef(excitation, excitation - T0 + (T0_frac <= 0),
  356. ff_b60_sinc, 6,
  357. 2 * ((2 + T0_frac)%3 + 1), LP_FILTER_ORDER,
  358. SUBFR_SIZE);
  359. decode_fixed_sparse(&fixed_cb, params->fc_indexes[i], ctx->mode,
  360. ctx->past_pitch_gain < 0.8);
  361. eval_ir(pAz, T0, impulse_response, modes[ctx->mode].pitch_sharp_factor);
  362. convolute_with_sparse(fixed_vector, &fixed_cb, impulse_response,
  363. SUBFR_SIZE);
  364. avg_energy =
  365. (0.01 + ff_dot_productf(fixed_vector, fixed_vector, SUBFR_SIZE))/
  366. SUBFR_SIZE;
  367. ctx->past_pitch_gain = pitch_gain = gain_cb[params->gc_index[i]][0];
  368. gain_code = ff_amr_set_fixed_gain(gain_cb[params->gc_index[i]][1],
  369. avg_energy, ctx->energy_history,
  370. 34 - 15.0/(0.05*M_LN10/M_LN2),
  371. pred);
  372. ff_weighted_vector_sumf(excitation, excitation, fixed_vector,
  373. pitch_gain, gain_code, SUBFR_SIZE);
  374. pitch_gain *= 0.5 * pitch_gain;
  375. pitch_gain = FFMIN(pitch_gain, 0.4);
  376. ctx->gain_mem = 0.7 * ctx->gain_mem + 0.3 * pitch_gain;
  377. ctx->gain_mem = FFMIN(ctx->gain_mem, pitch_gain);
  378. gain_code *= ctx->gain_mem;
  379. for (j = 0; j < SUBFR_SIZE; j++)
  380. fixed_vector[j] = excitation[j] - gain_code * fixed_vector[j];
  381. if (ctx->mode == MODE_5k0) {
  382. postfilter_5k0(ctx, pAz, fixed_vector);
  383. ff_celp_lp_synthesis_filterf(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i*SUBFR_SIZE,
  384. pAz, excitation, SUBFR_SIZE,
  385. LP_FILTER_ORDER);
  386. }
  387. ff_celp_lp_synthesis_filterf(synth + i*SUBFR_SIZE, pAz, fixed_vector,
  388. SUBFR_SIZE, LP_FILTER_ORDER);
  389. excitation += SUBFR_SIZE;
  390. }
  391. memcpy(synth - LP_FILTER_ORDER, synth + frame_size - LP_FILTER_ORDER,
  392. LP_FILTER_ORDER * sizeof(float));
  393. if (ctx->mode == MODE_5k0) {
  394. for (i = 0; i < subframe_count; i++) {
  395. float energy = ff_dot_productf(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i*SUBFR_SIZE,
  396. ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i*SUBFR_SIZE,
  397. SUBFR_SIZE);
  398. ff_adaptative_gain_control(&synth[i * SUBFR_SIZE], energy,
  399. SUBFR_SIZE, 0.9, &ctx->postfilter_agc);
  400. }
  401. memcpy(ctx->postfilter_syn5k0, ctx->postfilter_syn5k0 + frame_size,
  402. LP_FILTER_ORDER*sizeof(float));
  403. }
  404. memcpy(ctx->excitation, excitation - PITCH_DELAY_MAX - L_INTERPOL,
  405. (PITCH_DELAY_MAX + L_INTERPOL) * sizeof(float));
  406. ff_acelp_apply_order_2_transfer_function(synth,
  407. (const float[2]) {-1.99997 , 1.000000000},
  408. (const float[2]) {-1.93307352, 0.935891986},
  409. 0.939805806,
  410. ctx->highpass_filt_mem,
  411. frame_size);
  412. ctx->dsp.vector_clipf(out_data, synth, -1, 32767./(1<<15), frame_size);
  413. }
  414. static av_cold int sipr_decoder_init(AVCodecContext * avctx)
  415. {
  416. SiprContext *ctx = avctx->priv_data;
  417. int i;
  418. if (avctx->bit_rate > 12200) ctx->mode = MODE_16k;
  419. else if (avctx->bit_rate > 7500 ) ctx->mode = MODE_8k5;
  420. else if (avctx->bit_rate > 5750 ) ctx->mode = MODE_6k5;
  421. else ctx->mode = MODE_5k0;
  422. av_log(avctx, AV_LOG_DEBUG, "Mode: %s\n", modes[ctx->mode].mode_name);
  423. for (i = 0; i < LP_FILTER_ORDER; i++)
  424. ctx->lsp_history[i] = cos((i+1) * M_PI / (LP_FILTER_ORDER + 1));
  425. for (i = 0; i < 4; i++)
  426. ctx->energy_history[i] = -14;
  427. avctx->sample_fmt = SAMPLE_FMT_FLT;
  428. if (ctx->mode == MODE_16k) {
  429. av_log(avctx, AV_LOG_ERROR, "decoding 16kbps SIPR files is not "
  430. "supported yet.\n");
  431. return -1;
  432. }
  433. dsputil_init(&ctx->dsp, avctx);
  434. return 0;
  435. }
  436. static int sipr_decode_frame(AVCodecContext *avctx, void *datap,
  437. int *data_size, AVPacket *avpkt)
  438. {
  439. SiprContext *ctx = avctx->priv_data;
  440. const uint8_t *buf=avpkt->data;
  441. SiprParameters parm;
  442. const SiprModeParam *mode_par = &modes[ctx->mode];
  443. GetBitContext gb;
  444. float *data = datap;
  445. int i;
  446. ctx->avctx = avctx;
  447. if (avpkt->size < (mode_par->bits_per_frame >> 3)) {
  448. av_log(avctx, AV_LOG_ERROR,
  449. "Error processing packet: packet size (%d) too small\n",
  450. avpkt->size);
  451. *data_size = 0;
  452. return -1;
  453. }
  454. if (*data_size < SUBFR_SIZE * mode_par->subframe_count * sizeof(float)) {
  455. av_log(avctx, AV_LOG_ERROR,
  456. "Error processing packet: output buffer (%d) too small\n",
  457. *data_size);
  458. *data_size = 0;
  459. return -1;
  460. }
  461. init_get_bits(&gb, buf, mode_par->bits_per_frame);
  462. for (i = 0; i < mode_par->frames_per_packet; i++) {
  463. decode_parameters(&parm, &gb, mode_par);
  464. decode_frame(ctx, &parm, data);
  465. data += SUBFR_SIZE * mode_par->subframe_count;
  466. }
  467. *data_size = mode_par->frames_per_packet * SUBFR_SIZE *
  468. mode_par->subframe_count * sizeof(float);
  469. return mode_par->bits_per_frame >> 3;
  470. };
  471. AVCodec sipr_decoder = {
  472. "sipr",
  473. CODEC_TYPE_AUDIO,
  474. CODEC_ID_SIPR,
  475. sizeof(SiprContext),
  476. sipr_decoder_init,
  477. NULL,
  478. NULL,
  479. sipr_decode_frame,
  480. .long_name = NULL_IF_CONFIG_SMALL("RealAudio SIPR / ACELP.NET"),
  481. };