annotate sipr.c @ 11123:d59349627f52 libavcodec

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