]> git.sesse.net Git - ffmpeg/blob - libavcodec/sipr.c
82d02675725e7012fe4dbf68f476733bf3827374
[ffmpeg] / libavcodec / sipr.c
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
24 #include <math.h>
25 #include <stdint.h>
26
27 #include "libavutil/mathematics.h"
28 #include "avcodec.h"
29 #define ALT_BITSTREAM_READER_LE
30 #include "get_bits.h"
31 #include "dsputil.h"
32
33 #include "lsp.h"
34 #include "celp_math.h"
35 #include "acelp_vectors.h"
36 #include "acelp_pitch_delay.h"
37 #include "acelp_filters.h"
38 #include "celp_filters.h"
39
40 #define LSFQ_DIFF_MIN        (0.0125 * M_PI)
41
42 #define LP_FILTER_ORDER      10
43
44 /** Number of past samples needed for excitation interpolation */
45 #define L_INTERPOL           (LP_FILTER_ORDER + 1)
46
47 /**  Subframe size for all modes except 16k */
48 #define SUBFR_SIZE           48
49
50 #define MAX_SUBFRAME_COUNT   5
51
52 #include "siprdata.h"
53
54 typedef enum {
55     MODE_16k,
56     MODE_8k5,
57     MODE_6k5,
58     MODE_5k0,
59     MODE_COUNT
60 } SiprMode;
61
62 typedef struct {
63     const char *mode_name;
64     uint16_t bits_per_frame;
65     uint8_t subframe_count;
66     uint8_t frames_per_packet;
67     float pitch_sharp_factor;
68
69     /* bitstream parameters */
70     uint8_t number_of_fc_indexes;
71
72     /** size in bits of the i-th stage vector of quantizer */
73     uint8_t vq_indexes_bits[5];
74
75     /** size in bits of the adaptive-codebook index for every subframe */
76     uint8_t pitch_delay_bits[5];
77
78     uint8_t gp_index_bits;
79     uint8_t fc_index_bits[10]; ///< size in bits of the fixed codebook indexes
80     uint8_t gc_index_bits;     ///< size in bits of the gain  codebook indexes
81 } SiprModeParam;
82
83 static const SiprModeParam modes[MODE_COUNT] = {
84     [MODE_8k5] = {
85         .mode_name          = "8k5",
86         .bits_per_frame     = 152,
87         .subframe_count     = 3,
88         .frames_per_packet  = 1,
89         .pitch_sharp_factor = 0.8,
90
91         .number_of_fc_indexes = 3,
92         .vq_indexes_bits      = {6, 7, 7, 7, 5},
93         .pitch_delay_bits     = {8, 5, 5},
94         .gp_index_bits        = 0,
95         .fc_index_bits        = {9, 9, 9},
96         .gc_index_bits        = 7
97     },
98
99     [MODE_6k5] = {
100         .mode_name          = "6k5",
101         .bits_per_frame     = 232,
102         .subframe_count     = 3,
103         .frames_per_packet  = 2,
104         .pitch_sharp_factor = 0.8,
105
106         .number_of_fc_indexes = 3,
107         .vq_indexes_bits      = {6, 7, 7, 7, 5},
108         .pitch_delay_bits     = {8, 5, 5},
109         .gp_index_bits        = 0,
110         .fc_index_bits        = {5, 5, 5},
111         .gc_index_bits        = 7
112     },
113
114     [MODE_5k0] = {
115         .mode_name          = "5k0",
116         .bits_per_frame     = 296,
117         .subframe_count     = 5,
118         .frames_per_packet  = 2,
119         .pitch_sharp_factor = 0.85,
120
121         .number_of_fc_indexes = 1,
122         .vq_indexes_bits      = {6, 7, 7, 7, 5},
123         .pitch_delay_bits     = {8, 5, 8, 5, 5},
124         .gp_index_bits        = 0,
125         .fc_index_bits        = {10},
126         .gc_index_bits        = 7
127     }
128 };
129
130 typedef struct {
131     AVCodecContext *avctx;
132     DSPContext dsp;
133
134     SiprMode mode;
135
136     float past_pitch_gain;
137     float lsf_history[LP_FILTER_ORDER];
138
139     float excitation[L_INTERPOL + PITCH_DELAY_MAX + 5*SUBFR_SIZE];
140
141     DECLARE_ALIGNED_16(float, synth_buf[LP_FILTER_ORDER + 5*SUBFR_SIZE + 6]);
142
143     float lsp_history[LP_FILTER_ORDER];
144     float gain_mem;
145     float energy_history[4];
146     float highpass_filt_mem[2];
147     float postfilter_mem[PITCH_DELAY_MAX + LP_FILTER_ORDER];
148
149     /* 5k0 */
150     float tilt_mem;
151     float postfilter_agc;
152     float postfilter_mem5k0[PITCH_DELAY_MAX + LP_FILTER_ORDER];
153     float postfilter_syn5k0[LP_FILTER_ORDER + SUBFR_SIZE*5];
154 } SiprContext;
155
156 typedef struct {
157     int vq_indexes[5];
158     int pitch_delay[5];        ///< pitch delay
159     int gp_index[5];           ///< adaptive-codebook gain indexes
160     int16_t fc_indexes[5][10]; ///< fixed-codebook indexes
161     int gc_index[5];           ///< fixed-codebook gain indexes
162 } SiprParameters;
163
164
165 static void dequant(float *out, const int *idx, const float *cbs[])
166 {
167     int i;
168     int stride  = 2;
169     int num_vec = 5;
170
171     for (i = 0; i < num_vec; i++)
172         memcpy(out + stride*i, cbs[i] + stride*idx[i], stride*sizeof(float));
173
174 }
175
176 static void lsf_decode_fp(float *lsfnew, float *lsf_history,
177                           const SiprParameters *parm)
178 {
179     int i;
180     float lsf_tmp[LP_FILTER_ORDER];
181
182     dequant(lsf_tmp, parm->vq_indexes, lsf_codebooks);
183
184     for (i = 0; i < LP_FILTER_ORDER; i++)
185         lsfnew[i] = lsf_history[i] * 0.33 + lsf_tmp[i] + mean_lsf[i];
186
187     ff_sort_nearly_sorted_floats(lsfnew, LP_FILTER_ORDER - 1);
188
189     /* Note that a minimum distance is not enforced between the last value and
190        the previous one, contrary to what is done in ff_acelp_reorder_lsf() */
191     ff_set_min_dist_lsf(lsfnew, LSFQ_DIFF_MIN, LP_FILTER_ORDER - 1);
192     lsfnew[9] = FFMIN(lsfnew[LP_FILTER_ORDER - 1], 1.3 * M_PI);
193
194     memcpy(lsf_history, lsf_tmp, LP_FILTER_ORDER * sizeof(*lsf_history));
195
196     for (i = 0; i < LP_FILTER_ORDER - 1; i++)
197         lsfnew[i] = cos(lsfnew[i]);
198     lsfnew[LP_FILTER_ORDER - 1] *= 6.153848 / M_PI;
199 }
200
201 /** Apply pitch lag to the fixed vector (AMR section 6.1.2). */
202 static void pitch_sharpening(int pitch_lag_int, float beta,
203                              float *fixed_vector)
204 {
205     int i;
206
207     for (i = pitch_lag_int; i < SUBFR_SIZE; i++)
208         fixed_vector[i] += beta * fixed_vector[i - pitch_lag_int];
209 }
210
211 /**
212  * Extracts decoding parameters from the input bitstream.
213  * @param parms          parameters structure
214  * @param pgb            pointer to initialized GetBitContext structure
215  */
216 static void decode_parameters(SiprParameters* parms, GetBitContext *pgb,
217                               const SiprModeParam *p)
218 {
219     int i, j;
220
221     for (i = 0; i < 5; i++)
222         parms->vq_indexes[i]        = get_bits(pgb, p->vq_indexes_bits[i]);
223
224     for (i = 0; i < p->subframe_count; i++) {
225         parms->pitch_delay[i]       = get_bits(pgb, p->pitch_delay_bits[i]);
226         parms->gp_index[i]          = get_bits(pgb, p->gp_index_bits);
227
228         for (j = 0; j < p->number_of_fc_indexes; j++)
229             parms->fc_indexes[i][j] = get_bits(pgb, p->fc_index_bits[j]);
230
231         parms->gc_index[i]          = get_bits(pgb, p->gc_index_bits);
232     }
233 }
234
235 static void lsp2lpc_sipr(const double *lsp, float *Az)
236 {
237     int lp_half_order = LP_FILTER_ORDER >> 1;
238     double buf[(LP_FILTER_ORDER >> 1) + 1];
239     double pa[(LP_FILTER_ORDER >> 1) + 1];
240     double *qa = buf + 1;
241     int i,j;
242
243     qa[-1] = 0.0;
244
245     ff_lsp2polyf(lsp    , pa, lp_half_order    );
246     ff_lsp2polyf(lsp + 1, qa, lp_half_order - 1);
247
248     for (i = 1, j = LP_FILTER_ORDER - 1; i < lp_half_order; i++, j--) {
249         double paf =  pa[i]            * (1 + lsp[LP_FILTER_ORDER - 1]);
250         double qaf = (qa[i] - qa[i-2]) * (1 - lsp[LP_FILTER_ORDER - 1]);
251         Az[i-1]  = (paf + qaf) * 0.5;
252         Az[j-1]  = (paf - qaf) * 0.5;
253     }
254
255     Az[lp_half_order - 1] = (1.0 + lsp[LP_FILTER_ORDER - 1]) *
256         pa[lp_half_order] * 0.5;
257
258     Az[LP_FILTER_ORDER - 1] = lsp[LP_FILTER_ORDER - 1];
259 }
260
261 static void sipr_decode_lp(float *lsfnew, const float *lsfold, float *Az,
262                            int num_subfr)
263 {
264     double lsfint[LP_FILTER_ORDER];
265     int i,j;
266     float t, t0 = 1.0 / num_subfr;
267
268     t = t0 * 0.5;
269     for (i = 0; i < num_subfr; i++) {
270         for (j = 0; j < LP_FILTER_ORDER; j++)
271             lsfint[j] = lsfold[j] * (1 - t) + t * lsfnew[j];
272
273         lsp2lpc_sipr(lsfint, Az);
274         Az += LP_FILTER_ORDER;
275         t += t0;
276     }
277 }
278
279 /**
280  * Evaluates the adaptative impulse response.
281  */
282 static void eval_ir(const float *Az, int pitch_lag, float *freq,
283                     float pitch_sharp_factor)
284 {
285     float tmp1[SUBFR_SIZE+1], tmp2[LP_FILTER_ORDER+1];
286     int i;
287
288     tmp1[0] = 1.;
289     for (i = 0; i < LP_FILTER_ORDER; i++) {
290         tmp1[i+1] = Az[i] * ff_pow_0_55[i];
291         tmp2[i  ] = Az[i] * ff_pow_0_7 [i];
292     }
293     memset(tmp1 + 11, 0, 37 * sizeof(float));
294
295     ff_celp_lp_synthesis_filterf(freq, tmp2, tmp1, SUBFR_SIZE,
296                                  LP_FILTER_ORDER);
297
298     pitch_sharpening(pitch_lag, pitch_sharp_factor, freq);
299 }
300
301 /**
302  * Evaluates the convolution of a vector with a sparse vector.
303  */
304 static void convolute_with_sparse(float *out, const AMRFixed *pulses,
305                                   const float *shape, int length)
306 {
307     int i, j;
308
309     memset(out, 0, length*sizeof(float));
310     for (i = 0; i < pulses->n; i++)
311         for (j = pulses->x[i]; j < length; j++)
312             out[j] += pulses->y[i] * shape[j - pulses->x[i]];
313 }
314
315 /**
316  * Apply postfilter, very similar to AMR one.
317  */
318 static void postfilter_5k0(SiprContext *ctx, const float *lpc, float *samples)
319 {
320     float buf[SUBFR_SIZE + LP_FILTER_ORDER];
321     float *pole_out = buf + LP_FILTER_ORDER;
322     float lpc_n[LP_FILTER_ORDER];
323     float lpc_d[LP_FILTER_ORDER];
324     int i;
325
326     for (i = 0; i < LP_FILTER_ORDER; i++) {
327         lpc_d[i] = lpc[i] * ff_pow_0_75[i];
328         lpc_n[i] = lpc[i] *    pow_0_5 [i];
329     };
330
331     memcpy(pole_out - LP_FILTER_ORDER, ctx->postfilter_mem,
332            LP_FILTER_ORDER*sizeof(float));
333
334     ff_celp_lp_synthesis_filterf(pole_out, lpc_d, samples, SUBFR_SIZE,
335                                  LP_FILTER_ORDER);
336
337     memcpy(ctx->postfilter_mem, pole_out + SUBFR_SIZE - LP_FILTER_ORDER,
338            LP_FILTER_ORDER*sizeof(float));
339
340     ff_tilt_compensation(&ctx->tilt_mem, 0.4, pole_out, SUBFR_SIZE);
341
342     memcpy(pole_out - LP_FILTER_ORDER, ctx->postfilter_mem5k0,
343            LP_FILTER_ORDER*sizeof(*pole_out));
344
345     memcpy(ctx->postfilter_mem5k0, pole_out + SUBFR_SIZE - LP_FILTER_ORDER,
346            LP_FILTER_ORDER*sizeof(*pole_out));
347
348     ff_celp_lp_zero_synthesis_filterf(samples, lpc_n, pole_out, SUBFR_SIZE,
349                                       LP_FILTER_ORDER);
350
351 }
352
353 static void decode_fixed_sparse(AMRFixed *fixed_sparse, const int16_t *pulses,
354                                 SiprMode mode, int low_gain)
355 {
356     int i;
357
358     switch (mode) {
359     case MODE_6k5:
360         for (i = 0; i < 3; i++) {
361             fixed_sparse->x[i] = 3 * (pulses[i] & 0xf) + i;
362             fixed_sparse->y[i] = pulses[i] & 0x10 ? -1 : 1;
363         }
364         fixed_sparse->n = 3;
365         break;
366     case MODE_8k5:
367         for (i = 0; i < 3; i++) {
368             fixed_sparse->x[2*i    ] = 3 * ((pulses[i] >> 4) & 0xf) + i;
369             fixed_sparse->x[2*i + 1] = 3 * ( pulses[i]       & 0xf) + i;
370
371             fixed_sparse->y[2*i    ] = (pulses[i] & 0x100) ? -1.0: 1.0;
372
373             fixed_sparse->y[2*i + 1] =
374                 (fixed_sparse->x[2*i + 1] < fixed_sparse->x[2*i]) ?
375                 -fixed_sparse->y[2*i    ] : fixed_sparse->y[2*i];
376         }
377
378         fixed_sparse->n = 6;
379         break;
380     case MODE_5k0:
381     default:
382         if (low_gain) {
383             int offset = (pulses[0] & 0x200) ? 2 : 0;
384             int val = pulses[0];
385
386             for (i = 0; i < 3; i++) {
387                 int index = (val & 0x7) * 6 + 4 - i*2;
388
389                 fixed_sparse->y[i] = (offset + index) & 0x3 ? -1 : 1;
390                 fixed_sparse->x[i] = index;
391
392                 val >>= 3;
393             }
394             fixed_sparse->n = 3;
395         } else {
396             int pulse_subset = (pulses[0] >> 8) & 1;
397
398             fixed_sparse->x[0] = ((pulses[0] >> 4) & 15) * 3 + pulse_subset;
399             fixed_sparse->x[1] = ( pulses[0]       & 15) * 3 + pulse_subset + 1;
400
401             fixed_sparse->y[0] = pulses[0] & 0x200 ? -1 : 1;
402             fixed_sparse->y[1] = -fixed_sparse->y[0];
403             fixed_sparse->n = 2;
404         }
405         break;
406     }
407 }
408
409 static void decode_frame(SiprContext *ctx, SiprParameters *params,
410                          float *out_data)
411 {
412     int i, j;
413     int subframe_count = modes[ctx->mode].subframe_count;
414     int frame_size = subframe_count * SUBFR_SIZE;
415     float Az[LP_FILTER_ORDER * MAX_SUBFRAME_COUNT];
416     float *excitation;
417     float ir_buf[SUBFR_SIZE + LP_FILTER_ORDER];
418     float lsf_new[LP_FILTER_ORDER];
419     float *impulse_response = ir_buf + LP_FILTER_ORDER;
420     float *synth = ctx->synth_buf + 16; // 16 instead of LP_FILTER_ORDER for
421                                         // memory alignment
422     int t0_first = 0;
423     AMRFixed fixed_cb;
424
425     memset(ir_buf, 0, LP_FILTER_ORDER * sizeof(float));
426     lsf_decode_fp(lsf_new, ctx->lsf_history, params);
427
428     sipr_decode_lp(lsf_new, ctx->lsp_history, Az, subframe_count);
429
430     memcpy(ctx->lsp_history, lsf_new, LP_FILTER_ORDER * sizeof(float));
431
432     excitation = ctx->excitation + PITCH_DELAY_MAX + L_INTERPOL;
433
434     for (i = 0; i < subframe_count; i++) {
435         float *pAz = Az + i*LP_FILTER_ORDER;
436         float fixed_vector[SUBFR_SIZE];
437         int T0,T0_frac;
438         float pitch_gain, gain_code, avg_energy;
439
440         ff_decode_pitch_lag(&T0, &T0_frac, params->pitch_delay[i], t0_first, i,
441                             ctx->mode == MODE_5k0, 6);
442
443         if (i == 0 || (i == 2 && ctx->mode == MODE_5k0))
444             t0_first = T0;
445
446         ff_acelp_interpolatef(excitation, excitation - T0 + (T0_frac <= 0),
447                               ff_b60_sinc, 6,
448                               2 * ((2 + T0_frac)%3 + 1), LP_FILTER_ORDER,
449                               SUBFR_SIZE);
450
451         decode_fixed_sparse(&fixed_cb, params->fc_indexes[i], ctx->mode,
452                             ctx->past_pitch_gain < 0.8);
453
454         eval_ir(pAz, T0, impulse_response, modes[ctx->mode].pitch_sharp_factor);
455
456         convolute_with_sparse(fixed_vector, &fixed_cb, impulse_response,
457                               SUBFR_SIZE);
458
459         avg_energy =
460             (0.01 + ff_dot_productf(fixed_vector, fixed_vector, SUBFR_SIZE))/
461                 SUBFR_SIZE;
462
463         ctx->past_pitch_gain = pitch_gain = gain_cb[params->gc_index[i]][0];
464
465         gain_code = ff_amr_set_fixed_gain(gain_cb[params->gc_index[i]][1],
466                                           avg_energy, ctx->energy_history,
467                                           34 - 15.0/(0.05*M_LN10/M_LN2),
468                                           pred);
469
470         ff_weighted_vector_sumf(excitation, excitation, fixed_vector,
471                                 pitch_gain, gain_code, SUBFR_SIZE);
472
473         pitch_gain *= 0.5 * pitch_gain;
474         pitch_gain = FFMIN(pitch_gain, 0.4);
475
476         ctx->gain_mem = 0.7 * ctx->gain_mem + 0.3 * pitch_gain;
477         ctx->gain_mem = FFMIN(ctx->gain_mem, pitch_gain);
478         gain_code *= ctx->gain_mem;
479
480         for (j = 0; j < SUBFR_SIZE; j++)
481             fixed_vector[j] = excitation[j] - gain_code * fixed_vector[j];
482
483         if (ctx->mode == MODE_5k0) {
484             postfilter_5k0(ctx, pAz, fixed_vector);
485
486             ff_celp_lp_synthesis_filterf(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i*SUBFR_SIZE,
487                                          pAz, excitation, SUBFR_SIZE,
488                                          LP_FILTER_ORDER);
489         }
490
491         ff_celp_lp_synthesis_filterf(synth + i*SUBFR_SIZE, pAz, fixed_vector,
492                                      SUBFR_SIZE, LP_FILTER_ORDER);
493
494         excitation += SUBFR_SIZE;
495     }
496
497     memcpy(synth - LP_FILTER_ORDER, synth + frame_size - LP_FILTER_ORDER,
498            LP_FILTER_ORDER * sizeof(float));
499
500     if (ctx->mode == MODE_5k0) {
501         for (i = 0; i < subframe_count; i++) {
502             float energy = ff_dot_productf(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i*SUBFR_SIZE,
503                                            ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i*SUBFR_SIZE,
504                                            SUBFR_SIZE);
505             ff_adaptative_gain_control(&synth[i * SUBFR_SIZE], energy,
506                                        SUBFR_SIZE, 0.9, &ctx->postfilter_agc);
507         }
508
509         memcpy(ctx->postfilter_syn5k0, ctx->postfilter_syn5k0 + frame_size,
510                LP_FILTER_ORDER*sizeof(float));
511     }
512     memcpy(ctx->excitation, excitation - PITCH_DELAY_MAX - L_INTERPOL,
513            (PITCH_DELAY_MAX + L_INTERPOL) * sizeof(float));
514
515     ff_acelp_apply_order_2_transfer_function(synth,
516                                              (const float[2]) {-1.99997   , 1.000000000},
517                                              (const float[2]) {-1.93307352, 0.935891986},
518                                              0.939805806,
519                                              ctx->highpass_filt_mem,
520                                              frame_size);
521
522     ctx->dsp.vector_clipf(out_data, synth, -1, 32767./(1<<15), frame_size);
523
524 }
525
526 static av_cold int sipr_decoder_init(AVCodecContext * avctx)
527 {
528     SiprContext *ctx = avctx->priv_data;
529     int i;
530
531     if      (avctx->bit_rate > 12200) ctx->mode = MODE_16k;
532     else if (avctx->bit_rate > 7500 ) ctx->mode = MODE_8k5;
533     else if (avctx->bit_rate > 5750 ) ctx->mode = MODE_6k5;
534     else                              ctx->mode = MODE_5k0;
535
536     av_log(avctx, AV_LOG_DEBUG, "Mode: %s\n", modes[ctx->mode].mode_name);
537
538     for (i = 0; i < LP_FILTER_ORDER; i++)
539         ctx->lsp_history[i] = cos((i+1) * M_PI / (LP_FILTER_ORDER + 1));
540
541     for (i = 0; i < 4; i++)
542         ctx->energy_history[i] = -14;
543
544     avctx->sample_fmt = SAMPLE_FMT_FLT;
545
546     if (ctx->mode == MODE_16k) {
547         av_log(avctx, AV_LOG_ERROR, "decoding 16kbps SIPR files is not "
548                                     "supported yet.\n");
549         return -1;
550     }
551
552     dsputil_init(&ctx->dsp, avctx);
553
554     return 0;
555 }
556
557 static int sipr_decode_frame(AVCodecContext *avctx, void *datap,
558                              int *data_size, AVPacket *avpkt)
559 {
560     SiprContext *ctx = avctx->priv_data;
561     const uint8_t *buf=avpkt->data;
562     SiprParameters parm;
563     const SiprModeParam *mode_par = &modes[ctx->mode];
564     GetBitContext gb;
565     float *data = datap;
566     int i;
567
568     ctx->avctx = avctx;
569     if (avpkt->size < (mode_par->bits_per_frame >> 3)) {
570         av_log(avctx, AV_LOG_ERROR,
571                "Error processing packet: packet size (%d) too small\n",
572                avpkt->size);
573
574         *data_size = 0;
575         return -1;
576     }
577     if (*data_size < SUBFR_SIZE * mode_par->subframe_count * sizeof(float)) {
578         av_log(avctx, AV_LOG_ERROR,
579                "Error processing packet: output buffer (%d) too small\n",
580                *data_size);
581
582         *data_size = 0;
583         return -1;
584     }
585
586     init_get_bits(&gb, buf, mode_par->bits_per_frame);
587
588     for (i = 0; i < mode_par->frames_per_packet; i++) {
589         decode_parameters(&parm, &gb, mode_par);
590         decode_frame(ctx, &parm, data);
591
592         data += SUBFR_SIZE * mode_par->subframe_count;
593     }
594
595     *data_size = mode_par->frames_per_packet * SUBFR_SIZE *
596         mode_par->subframe_count * sizeof(float);
597
598     return mode_par->bits_per_frame >> 3;
599 };
600
601 AVCodec sipr_decoder = {
602     "sipr",
603     CODEC_TYPE_AUDIO,
604     CODEC_ID_SIPR,
605     sizeof(SiprContext),
606     sipr_decoder_init,
607     NULL,
608     NULL,
609     sipr_decode_frame,
610     .long_name = NULL_IF_CONFIG_SMALL("RealAudio SIPR / ACELP.NET"),
611 };