35 #define DSS_SP_FRAME_SIZE 42
36 #define DSS_SP_SAMPLE_COUNT (66 * SUBFRAMES)
37 #define DSS_SP_FORMULA(a, b, c) ((int)((((a) * (1 << 15)) + (b) * (unsigned)(c)) + 0x4000) >> 15)
91 12, 13, 14, 15, 16, 17,
92 18, 19, 20, 21, 22, 23,
93 24, 25, 26, 27, 28, 29,
94 30, 31, 32, 33, 34, 35,
95 36, 37, 38, 39, 40, 41,
96 42, 43, 44, 45, 46, 47,
97 48, 49, 50, 51, 52, 53,
98 54, 55, 56, 57, 58, 59,
99 60, 61, 62, 63, 64, 65,
100 66, 67, 68, 69, 70, 71 },
102 15, 21, 28, 36, 45, 55,
103 66, 78, 91, 105, 120, 136,
104 153, 171, 190, 210, 231, 253,
105 276, 300, 325, 351, 378, 406,
106 435, 465, 496, 528, 561, 595,
107 630, 666, 703, 741, 780, 820,
108 861, 903, 946, 990, 1035, 1081,
109 1128, 1176, 1225, 1275, 1326, 1378,
110 1431, 1485, 1540, 1596, 1653, 1711,
111 1770, 1830, 1891, 1953, 2016, 2080,
112 2145, 2211, 2278, 2346, 2415, 2485 },
114 20, 35, 56, 84, 120, 165,
115 220, 286, 364, 455, 560, 680,
116 816, 969, 1140, 1330, 1540, 1771,
117 2024, 2300, 2600, 2925, 3276, 3654,
118 4060, 4495, 4960, 5456, 5984, 6545,
119 7140, 7770, 8436, 9139, 9880, 10660,
120 11480, 12341, 13244, 14190, 15180, 16215,
121 17296, 18424, 19600, 20825, 22100, 23426,
122 24804, 26235, 27720, 29260, 30856, 32509,
123 34220, 35990, 37820, 39711, 41664, 43680,
124 45760, 47905, 50116, 52394, 54740, 57155 },
126 15, 35, 70, 126, 210, 330,
127 495, 715, 1001, 1365, 1820, 2380,
128 3060, 3876, 4845, 5985, 7315, 8855,
129 10626, 12650, 14950, 17550, 20475, 23751,
130 27405, 31465, 35960, 40920, 46376, 52360,
131 58905, 66045, 73815, 82251, 91390, 101270,
132 111930, 123410, 135751, 148995, 163185, 178365,
133 194580, 211876, 230300, 249900, 270725, 292825,
134 316251, 341055, 367290, 395010, 424270, 455126,
135 487635, 521855, 557845, 595665, 635376, 677040,
136 720720, 766480, 814385, 864501, 916895, 971635 },
138 6, 21, 56, 126, 252, 462,
139 792, 1287, 2002, 3003, 4368, 6188,
140 8568, 11628, 15504, 20349, 26334, 33649,
141 42504, 53130, 65780, 80730, 98280, 118755,
142 142506, 169911, 201376, 237336, 278256, 324632,
143 376992, 435897, 501942, 575757, 658008, 749398,
144 850668, 962598, 1086008, 1221759, 1370754, 1533939,
145 1712304, 1906884, 2118760, 2349060, 2598960, 2869685,
146 3162510, 3478761, 3819816, 4187106, 4582116, 5006386,
147 5461512, 5949147, 6471002, 7028847, 7624512, 8259888,
148 8936928, 9657648, 10424128, 11238513, 12103014, 13019909 },
150 1, 7, 28, 84, 210, 462,
151 924, 1716, 3003, 5005, 8008, 12376,
152 18564, 27132, 38760, 54264, 74613, 100947,
153 134596, 177100, 230230, 296010, 376740, 475020,
154 593775, 736281, 906192, 1107568, 1344904, 1623160,
155 1947792, 2324784, 2760681, 3262623, 3838380, 4496388,
156 5245786, 6096454, 7059052, 8145060, 9366819, 10737573,
157 12271512, 13983816, 15890700, 18009460, 20358520, 22957480,
158 25827165, 28989675, 32468436, 36288252, 40475358, 45057474,
159 50063860, 55525372, 61474519, 67945521, 74974368, 82598880,
160 90858768, 99795696, 109453344, 119877472, 131115985, 143218999 },
162 0, 1, 8, 36, 120, 330,
163 792, 1716, 3432, 6435, 11440, 19448,
164 31824, 50388, 77520, 116280, 170544, 245157,
165 346104, 480700, 657800, 888030, 1184040, 1560780,
166 2035800, 2629575, 3365856, 4272048, 5379616, 6724520,
167 8347680, 10295472, 12620256, 15380937, 18643560, 22481940,
168 26978328, 32224114, 38320568, 45379620, 53524680, 62891499,
169 73629072, 85900584, 99884400, 115775100, 133784560, 154143080,
170 177100560, 202927725, 231917400, 264385836, 300674088, 341149446,
171 386206920, 436270780, 491796152, 553270671, 621216192, 696190560,
172 778789440, 869648208, 969443904, 1078897248, 1198774720, 1329890705 },
176 { -32653, -32587, -32515, -32438, -32341, -32216, -32062, -31881,
177 -31665, -31398, -31080, -30724, -30299, -29813, -29248, -28572,
178 -27674, -26439, -24666, -22466, -19433, -16133, -12218, -7783,
179 -2834, 1819, 6544, 11260, 16050, 20220, 24774, 28120 },
181 { -27503, -24509, -20644, -17496, -14187, -11277, -8420, -5595,
182 -3013, -624, 1711, 3880, 5844, 7774, 9739, 11592,
183 13364, 14903, 16426, 17900, 19250, 20586, 21803, 23006,
184 24142, 25249, 26275, 27300, 28359, 29249, 30118, 31183 },
186 { -27827, -24208, -20943, -17781, -14843, -11848, -9066, -6297,
187 -3660, -910, 1918, 5025, 8223, 11649, 15086, 18423,
188 0, 0, 0, 0, 0, 0, 0, 0,
189 0, 0, 0, 0, 0, 0, 0, 0 },
191 { -17128, -11975, -8270, -5123, -2296, 183, 2503, 4707,
192 6798, 8945, 11045, 13239, 15528, 18248, 21115, 24785,
193 0, 0, 0, 0, 0, 0, 0, 0,
194 0, 0, 0, 0, 0, 0, 0, 0 },
196 { -21557, -17280, -14286, -11644, -9268, -7087, -4939, -2831,
197 -691, 1407, 3536, 5721, 8125, 10677, 13721, 17731,
198 0, 0, 0, 0, 0, 0, 0, 0,
199 0, 0, 0, 0, 0, 0, 0, 0 },
201 { -15030, -10377, -7034, -4327, -1900, 364, 2458, 4450,
202 6422, 8374, 10374, 12486, 14714, 16997, 19626, 22954,
203 0, 0, 0, 0, 0, 0, 0, 0,
204 0, 0, 0, 0, 0, 0, 0, 0 },
206 { -16155, -12362, -9698, -7460, -5258, -3359, -1547, 219,
207 1916, 3599, 5299, 6994, 8963, 11226, 13716, 16982,
208 0, 0, 0, 0, 0, 0, 0, 0,
209 0, 0, 0, 0, 0, 0, 0, 0 },
211 { -14742, -9848, -6921, -4648, -2769, -1065, 499, 2083,
212 3633, 5219, 6857, 8580, 10410, 12672, 15561, 20101,
213 0, 0, 0, 0, 0, 0, 0, 0,
214 0, 0, 0, 0, 0, 0, 0, 0 },
216 { -11099, -7014, -3855, -1025, 1680, 4544, 7807, 11932,
217 0, 0, 0, 0, 0, 0, 0, 0,
218 0, 0, 0, 0, 0, 0, 0, 0,
219 0, 0, 0, 0, 0, 0, 0, 0 },
221 { -9060, -4570, -1381, 1419, 4034, 6728, 9865, 14149,
222 0, 0, 0, 0, 0, 0, 0, 0,
223 0, 0, 0, 0, 0, 0, 0, 0,
224 0, 0, 0, 0, 0, 0, 0, 0 },
226 { -12450, -7985, -4596, -1734, 961, 3629, 6865, 11142,
227 0, 0, 0, 0, 0, 0, 0, 0,
228 0, 0, 0, 0, 0, 0, 0, 0,
229 0, 0, 0, 0, 0, 0, 0, 0 },
231 { -11831, -7404, -4010, -1096, 1606, 4291, 7386, 11482,
232 0, 0, 0, 0, 0, 0, 0, 0,
233 0, 0, 0, 0, 0, 0, 0, 0,
234 0, 0, 0, 0, 0, 0, 0, 0 },
236 { -13404, -9250, -5995, -3312, -890, 1594, 4464, 8198,
237 0, 0, 0, 0, 0, 0, 0, 0,
238 0, 0, 0, 0, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0 },
241 { -11239, -7220, -4040, -1406, 971, 3321, 6006, 9697,
242 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, 0, 0, 0 },
248 0, 4, 8, 13, 17, 22, 26, 31,
249 35, 40, 44, 48, 53, 58, 63, 69,
250 76, 83, 91, 99, 109, 119, 130, 142,
251 155, 170, 185, 203, 222, 242, 265, 290,
252 317, 346, 378, 414, 452, 494, 540, 591,
253 646, 706, 771, 843, 922, 1007, 1101, 1204,
254 1316, 1438, 1572, 1719, 1879, 2053, 2244, 2453,
255 2682, 2931, 3204, 3502, 3828, 4184, 4574, 5000,
259 -31182, -22273, -13364, -4455, 4455, 13364, 22273, 31182
263 32767, 16384, 8192, 4096, 2048, 1024, 512, 256,
264 128, 64, 32, 16, 8, 4, 2,
268 32767, 26214, 20972, 16777, 13422, 10737, 8590, 6872,
269 5498, 4398, 3518, 2815, 2252, 1801, 1441,
273 102, 231, 360, 488, 617, 746, 875, 1004,
274 1133, 1261, 1390, 1519, 1648, 1777, 1905, 2034,
275 2163, 2292, 2421, 2550, 2678, 2807, 2936, 3065,
276 3194, 3323, 3451, 3580, 3709, 3838, 3967, 4096,
280 262, 293, 323, 348, 356, 336, 269, 139,
281 -67, -358, -733, -1178, -1668, -2162, -2607, -2940,
282 -3090, -2986, -2562, -1760, -541, 1110, 3187, 5651,
283 8435, 11446, 14568, 17670, 20611, 23251, 25460, 27125,
285 27125, 25460, 23251, 20611, 17670, 14568, 11446, 8435,
286 5651, 3187, 1110, -541, -1760, -2562, -2986, -3090,
287 -2940, -2607, -2162, -1668, -1178, -733, -358, -67,
288 139, 269, 336, 356, 348, 323, 293, 262,
312 uint32_t combined_pitch;
323 for (
i = 0;
i < 2;
i++)
330 for (subframe_idx = 0; subframe_idx < 4; subframe_idx++) {
337 for (
i = 0;
i < 7;
i++)
341 for (subframe_idx = 0; subframe_idx < 4; subframe_idx++) {
342 unsigned int C72_binomials[
PULSE_MAX] = {
343 72, 2556, 59640, 1028790, 13991544, 156238908, 1473109704,
346 unsigned int combined_pulse_pos =
350 if (combined_pulse_pos < C72_binomials[
PULSE_MAX - 1]) {
352 int pulse, pulse_idx;
362 for (
i = 0;
i < 7;
i++) {
368 combined_pulse_pos -=
380 for (
i = 71;
i >= 0;
i--) {
381 if (C72_binomials[
index] <= combined_pulse_pos) {
382 combined_pulse_pos -= C72_binomials[
index];
394 C72_binomials[
a + 1] -= C72_binomials[
a];
402 fparam->
pitch_lag[0] = (combined_pitch % 151) + 36;
404 combined_pitch /= 151;
408 combined_pitch /= 48;
410 if (combined_pitch > 47) {
418 if (pitch_lag > 162) {
421 tmp = pitch_lag - 23;
434 for (
i = 0;
i < 14;
i++)
443 for (
a = 0;
a < 14;
a++) {
445 coeffs[a_plus] = lpc_filter[
a] >> 2;
446 if (a_plus / 2 >= 1) {
447 for (
i = 1;
i <= a_plus / 2;
i++) {
448 int coeff_1, coeff_2,
tmp;
451 coeff_2 = coeffs[a_plus -
i];
468 for (
i = 0;
i < 7;
i++)
475 int pitch_lag,
int gain)
482 for (
i = 0;
i < 72;
i++)
483 vector[
i] = prev_exc[pitch_lag -
i % pitch_lag];
485 for (
i = 0;
i < 72;
i++)
486 vector[
i] = prev_exc[pitch_lag -
i];
488 for (
i = 0;
i < 72;
i++) {
489 int tmp = gain * vector[
i] >> 11;
503 vec[
i] = vec[
i] * (1 <<
bits);
510 for (
i = 114;
i > 0;
i--)
511 vector[
i + 72] = vector[
i];
513 for (
i = 0;
i < 72;
i++)
514 vector[72 -
i] = hist[
i];
522 for (
a = 0;
a < 72;
a++) {
525 tmp = dst[
a] * filter_buf[0];
527 for (
i = 14;
i > 0;
i--)
528 tmp -= error_buf[
i] * (
unsigned)filter_buf[
i];
530 for (
i = 14;
i > 0;
i--)
531 error_buf[
i] = error_buf[
i - 1];
546 for (
a = 0;
a < 72;
a++) {
549 audio_buf[0] = dst[
a];
551 for (
i = 14;
i >= 0;
i--)
552 tmp += audio_buf[
i] * filter_buf[
i];
554 for (
i = 14;
i > 0;
i--)
555 audio_buf[
i] = audio_buf[
i - 1];
570 for (
i = 1;
i < 15;
i++)
584 for (max_val = 0;
val <= 0x4000; ++max_val)
602 int bias, vsum_2 = 0, vsum_1 = 0, v36, normalize_bits;
608 if (vsum_1 > 0xFFFFF)
627 lpc_filter = lpc_filter >> 1;
632 for (
i =
size - 1;
i > 0;
i--) {
650 tmp = (vsum_1 << 11) / vsum_2;
654 bias = 409 *
tmp >> 15 << 15;
659 tmp = (bias + 32358 *
noise[
i - 1]) >> 15;
672 int i,
offset = 6, counter = 0,
a = 0;
674 for (
i = 0;
i < 6;
i++)
708 int16_t *abuf_dst,
const uint8_t *abuf_src)
727 for (
i = 0;
i < 72;
i++)
745 int *got_frame_ptr,
AVPacket *avpkt)
750 int buf_size = avpkt->
size;
758 "Expected %d bytes, got %d - skipping packet.\n",
static double val(void *priv, double ch)
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
audio channel layout utility functions
common internal and external API header
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static int dss_sp_vector_sum(DssSpContext *p, int size)
static void dss_sp_32to16bit(int16_t *dst, int32_t *src, int size)
static void dss_sp_shift_sq_sub(const int32_t *filter_buf, int32_t *error_buf, int32_t *dst)
static const int16_t dss_sp_filter_cb[14][32]
static const uint16_t dss_sp_adaptive_gain[]
static void dss_sp_shift_sq_add(const int32_t *filter_buf, int32_t *audio_buf, int32_t *dst)
static const uint16_t dss_sp_fixed_cb_gain[64]
static void dss_sp_add_pulses(int32_t *vector_buf, const struct DssSpSubframe *sf)
static const int32_t dss_sp_sinc[67]
#define DSS_SP_FRAME_SIZE
static void dss_sp_unpack_coeffs(DssSpContext *p, const uint8_t *src)
static const uint32_t dss_sp_combinatorial_table[PULSE_MAX][72]
static void dss_sp_update_buf(int32_t *hist, int32_t *vector)
AVCodec ff_dss_sp_decoder
static const uint16_t binary_decreasing_array[]
static void dss_sp_vec_mult(const int32_t *src, int32_t *dst, const int16_t *mult)
static void dss_sp_sf_synthesis(DssSpContext *p, int32_t lpc_filter, int32_t *dst, int size)
#define DSS_SP_SAMPLE_COUNT
static void dss_sp_unpack_filter(DssSpContext *p)
static int dss_sp_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static const int16_t dss_sp_pulse_val[8]
static void dss_sp_update_state(DssSpContext *p, int32_t *dst)
static int dss_sp_get_normalize_bits(int32_t *vector_buf, int16_t size)
static void dss_sp_convert_coeffs(int32_t *lpc_filter, int32_t *coeffs)
#define DSS_SP_FORMULA(a, b, c)
static av_cold int dss_sp_decode_init(AVCodecContext *avctx)
static int dss_sp_decode_one_frame(DssSpContext *p, int16_t *abuf_dst, const uint8_t *abuf_src)
static void dss_sp_scale_vector(int32_t *vec, int bits, int size)
static const uint16_t dss_sp_unc_decreasing_array[]
static void dss_sp_gen_exc(int32_t *vector, int32_t *prev_exc, int pitch_lag, int gain)
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_CH_LAYOUT_MONO
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
@ AV_SAMPLE_FMT_S16
signed 16 bits
static int16_t mult(Float11 *f1, Float11 *f2)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Memory handling functions.
static int noise(AVBSFContext *ctx, AVPacket *pkt)
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int sample_rate
samples per second
int channels
number of audio channels
uint64_t channel_layout
Audio channel layout.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
uint8_t bits[DSS_SP_FRAME_SIZE+AV_INPUT_BUFFER_PADDING_SIZE]
int32_t working_buffer[SUBFRAMES][72]
int32_t excitation[288+6]
int16_t pitch_lag[SUBFRAMES]
int16_t sf_adaptive_gain[SUBFRAMES]
struct DssSpSubframe sf[SUBFRAMES]
int32_t combined_pulse_pos
static const uint8_t offset[127][2]