annotate qdm2.c @ 10883:4701b9355d93 libavcodec

Add forgotten include of h264_mvpred.h to h264.h. This could have caused the linking failure of pred_pskip_motion() missing if a compiler included never used static functions.
author michael
date Fri, 15 Jan 2010 03:42:56 +0000
parents 899237b1961f
children 34a65026fa06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1 /*
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2 * QDM2 compatible decoder
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
3 * Copyright (c) 2003 Ewald Snel
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
4 * Copyright (c) 2005 Benjamin Larsson
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
5 * Copyright (c) 2005 Alex Beregszaszi
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
6 * Copyright (c) 2005 Roberto Togni
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
7 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3333
diff changeset
8 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3333
diff changeset
9 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3333
diff changeset
10 * FFmpeg is free software; you can redistribute it and/or
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
11 * modify it under the terms of the GNU Lesser General Public
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
12 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3333
diff changeset
13 * version 2.1 of the License, or (at your option) any later version.
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
14 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3333
diff changeset
15 * FFmpeg is distributed in the hope that it will be useful,
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
18 * Lesser General Public License for more details.
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
19 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
20 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3333
diff changeset
21 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
23 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
24
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
25 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8695
diff changeset
26 * @file libavcodec/qdm2.c
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
27 * QDM2 decoder
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
28 * @author Ewald Snel, Benjamin Larsson, Alex Beregszaszi, Roberto Togni
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
29 * The decoder is not perfect yet, there are still some distortions
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
30 * especially on files encoded with 16 or 8 subbands.
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
31 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
32
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
33 #include <math.h>
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
34 #include <stddef.h>
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
35 #include <stdio.h>
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
36
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
37 #define ALT_BITSTREAM_READER_LE
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
38 #include "avcodec.h"
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 9355
diff changeset
39 #include "get_bits.h"
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
40 #include "dsputil.h"
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
41 #include "mpegaudio.h"
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
42
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
43 #include "qdm2data.h"
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
44
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
45 #undef NDEBUG
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
46 #include <assert.h>
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
47
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
48
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
49 #define SOFTCLIP_THRESHOLD 27600
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
50 #define HARDCLIP_THRESHOLD 35716
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
51
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
52
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
53 #define QDM2_LIST_ADD(list, size, packet) \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
54 do { \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
55 if (size > 0) { \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
56 list[size - 1].next = &list[size]; \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
57 } \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
58 list[size].packet = packet; \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
59 list[size].next = NULL; \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
60 size++; \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
61 } while(0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
62
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
63 // Result is 8, 16 or 30
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
64 #define QDM2_SB_USED(sub_sampling) (((sub_sampling) >= 2) ? 30 : 8 << (sub_sampling))
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
65
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
66 #define FIX_NOISE_IDX(noise_idx) \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
67 if ((noise_idx) >= 3840) \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
68 (noise_idx) -= 3840; \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
69
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
70 #define SB_DITHERING_NOISE(sb,noise_idx) (noise_table[(noise_idx)++] * sb_noise_attenuation[(sb)])
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
71
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
72 #define BITS_LEFT(length,gb) ((length) - get_bits_count ((gb)))
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
73
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
74 #define SAMPLES_NEEDED \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
75 av_log (NULL,AV_LOG_INFO,"This file triggers some untested code. Please contact the developers.\n");
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
76
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
77 #define SAMPLES_NEEDED_2(why) \
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
78 av_log (NULL,AV_LOG_INFO,"This file triggers some missing code. Please contact the developers.\nPosition: %s\n",why);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
79
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
80
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
81 typedef int8_t sb_int8_array[2][30][64];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
82
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
83 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
84 * Subpacket
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
85 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
86 typedef struct {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
87 int type; ///< subpacket type
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
88 unsigned int size; ///< subpacket size
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
89 const uint8_t *data; ///< pointer to subpacket data (points to input data buffer, it's not a private copy)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
90 } QDM2SubPacket;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
91
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
92 /**
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
93 * A node in the subpacket list
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
94 */
6122
61f95f3a62e0 Rename two structures, identifiers starting with _[A-Z] are reserved.
diego
parents: 5215
diff changeset
95 typedef struct QDM2SubPNode {
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
96 QDM2SubPacket *packet; ///< packet
6122
61f95f3a62e0 Rename two structures, identifiers starting with _[A-Z] are reserved.
diego
parents: 5215
diff changeset
97 struct QDM2SubPNode *next; ///< pointer to next packet in the list, NULL if leaf node
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
98 } QDM2SubPNode;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
99
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
100 typedef struct {
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
101 float re;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
102 float im;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
103 } QDM2Complex;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
104
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
105 typedef struct {
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
106 float level;
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
107 QDM2Complex *complex;
6273
michael
parents: 6122
diff changeset
108 const float *table;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
109 int phase;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
110 int phase_shift;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
111 int duration;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
112 short time_index;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
113 short cutoff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
114 } FFTTone;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
115
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
116 typedef struct {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
117 int16_t sub_packet;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
118 uint8_t channel;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
119 int16_t offset;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
120 int16_t exp;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
121 uint8_t phase;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
122 } FFTCoefficient;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
123
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
124 typedef struct {
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
125 DECLARE_ALIGNED_16(QDM2Complex, complex[MPA_MAX_CHANNELS][256]);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
126 } QDM2FFT;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
127
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
128 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
129 * QDM2 decoder context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
130 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
131 typedef struct {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
132 /// Parameters from codec header, do not change during playback
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
133 int nb_channels; ///< number of channels
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
134 int channels; ///< number of channels
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
135 int group_size; ///< size of frame group (16 frames per group)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
136 int fft_size; ///< size of FFT, in complex numbers
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
137 int checksum_size; ///< size of data block, used also for checksum
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
138
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
139 /// Parameters built from header parameters, do not change during playback
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
140 int group_order; ///< order of frame group
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
141 int fft_order; ///< order of FFT (actually fftorder+1)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
142 int fft_frame_size; ///< size of fft frame, in components (1 comples = re + im)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
143 int frame_size; ///< size of data frame
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
144 int frequency_range;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
145 int sub_sampling; ///< subsampling: 0=25%, 1=50%, 2=100% */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
146 int coeff_per_sb_select; ///< selector for "num. of coeffs. per subband" tables. Can be 0, 1, 2
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
147 int cm_table_select; ///< selector for "coding method" tables. Can be 0, 1 (from init: 0-4)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
148
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
149 /// Packets and packet lists
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
150 QDM2SubPacket sub_packets[16]; ///< the packets themselves
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
151 QDM2SubPNode sub_packet_list_A[16]; ///< list of all packets
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
152 QDM2SubPNode sub_packet_list_B[16]; ///< FFT packets B are on list
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
153 int sub_packets_B; ///< number of packets on 'B' list
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
154 QDM2SubPNode sub_packet_list_C[16]; ///< packets with errors?
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
155 QDM2SubPNode sub_packet_list_D[16]; ///< DCT packets
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
156
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
157 /// FFT and tones
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
158 FFTTone fft_tones[1000];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
159 int fft_tone_start;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
160 int fft_tone_end;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
161 FFTCoefficient fft_coefs[1000];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
162 int fft_coefs_index;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
163 int fft_coefs_min_index[5];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
164 int fft_coefs_max_index[5];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
165 int fft_level_exp[6];
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
166 RDFTContext rdft_ctx;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
167 QDM2FFT fft;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
168
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
169 /// I/O data
6273
michael
parents: 6122
diff changeset
170 const uint8_t *compressed_data;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
171 int compressed_size;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
172 float output_buffer[1024];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
173
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
174 /// Synthesis filter
5009
4d10df33e823 Use DECLARE_ALIGNED to ease porting
reimar
parents: 4364
diff changeset
175 DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512*2]);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
176 int synth_buf_offset[MPA_MAX_CHANNELS];
5009
4d10df33e823 Use DECLARE_ALIGNED to ease porting
reimar
parents: 4364
diff changeset
177 DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][128][SBLIMIT]);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
178
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
179 /// Mixed temporary data used in decoding
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
180 float tone_level[MPA_MAX_CHANNELS][30][64];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
181 int8_t coding_method[MPA_MAX_CHANNELS][30][64];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
182 int8_t quantized_coeffs[MPA_MAX_CHANNELS][10][8];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
183 int8_t tone_level_idx_base[MPA_MAX_CHANNELS][30][8];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
184 int8_t tone_level_idx_hi1[MPA_MAX_CHANNELS][3][8][8];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
185 int8_t tone_level_idx_mid[MPA_MAX_CHANNELS][26][8];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
186 int8_t tone_level_idx_hi2[MPA_MAX_CHANNELS][26];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
187 int8_t tone_level_idx[MPA_MAX_CHANNELS][30][64];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
188 int8_t tone_level_idx_temp[MPA_MAX_CHANNELS][30][64];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
189
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
190 // Flags
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
191 int has_errors; ///< packet has errors
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
192 int superblocktype_2_3; ///< select fft tables and some algorithm based on superblock type
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
193 int do_synth_filter; ///< used to perform or skip synthesis filter
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
194
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
195 int sub_packet;
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
196 int noise_idx; ///< index for dithering noise table
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
197 } QDM2Context;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
198
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
199
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
200 static uint8_t empty_buffer[FF_INPUT_BUFFER_PADDING_SIZE];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
201
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
202 static VLC vlc_tab_level;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
203 static VLC vlc_tab_diff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
204 static VLC vlc_tab_run;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
205 static VLC fft_level_exp_alt_vlc;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
206 static VLC fft_level_exp_vlc;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
207 static VLC fft_stereo_exp_vlc;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
208 static VLC fft_stereo_phase_vlc;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
209 static VLC vlc_tab_tone_level_idx_hi1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
210 static VLC vlc_tab_tone_level_idx_mid;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
211 static VLC vlc_tab_tone_level_idx_hi2;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
212 static VLC vlc_tab_type30;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
213 static VLC vlc_tab_type34;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
214 static VLC vlc_tab_fft_tone_offset[5];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
215
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
216 static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
217 static float noise_table[4096];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
218 static uint8_t random_dequant_index[256][5];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
219 static uint8_t random_dequant_type24[128][3];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
220 static float noise_samples[128];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
221
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
222
9007
043574c5c153 Add missing av_cold in static init/close functions.
stefano
parents: 8718
diff changeset
223 static av_cold void softclip_table_init(void) {
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
224 int i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
225 double dfl = SOFTCLIP_THRESHOLD - 32767;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
226 float delta = 1.0 / -dfl;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
227 for (i = 0; i < HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1; i++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
228 softclip_table[i] = SOFTCLIP_THRESHOLD - ((int)(sin((float)i * delta) * dfl) & 0x0000FFFF);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
229 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
230
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
231
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
232 // random generated table
9007
043574c5c153 Add missing av_cold in static init/close functions.
stefano
parents: 8718
diff changeset
233 static av_cold void rnd_table_init(void) {
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
234 int i,j;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
235 uint32_t ldw,hdw;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
236 uint64_t tmp64_1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
237 uint64_t random_seed = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
238 float delta = 1.0 / 16384.0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
239 for(i = 0; i < 4096 ;i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
240 random_seed = random_seed * 214013 + 2531011;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
241 noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
242 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
243
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
244 for (i = 0; i < 256 ;i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
245 random_seed = 81;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
246 ldw = i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
247 for (j = 0; j < 5 ;j++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
248 random_dequant_index[i][j] = (uint8_t)((ldw / random_seed) & 0xFF);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
249 ldw = (uint32_t)ldw % (uint32_t)random_seed;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
250 tmp64_1 = (random_seed * 0x55555556);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
251 hdw = (uint32_t)(tmp64_1 >> 32);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
252 random_seed = (uint64_t)(hdw + (ldw >> 31));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
253 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
254 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
255 for (i = 0; i < 128 ;i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
256 random_seed = 25;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
257 ldw = i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
258 for (j = 0; j < 3 ;j++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
259 random_dequant_type24[i][j] = (uint8_t)((ldw / random_seed) & 0xFF);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
260 ldw = (uint32_t)ldw % (uint32_t)random_seed;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
261 tmp64_1 = (random_seed * 0x66666667);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
262 hdw = (uint32_t)(tmp64_1 >> 33);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
263 random_seed = hdw + (ldw >> 31);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
264 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
265 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
266 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
267
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
268
9007
043574c5c153 Add missing av_cold in static init/close functions.
stefano
parents: 8718
diff changeset
269 static av_cold void init_noise_samples(void) {
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
270 int i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
271 int random_seed = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
272 float delta = 1.0 / 16384.0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
273 for (i = 0; i < 128;i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
274 random_seed = random_seed * 214013 + 2531011;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
275 noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
276 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
277 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
278
9664
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
279 static const uint16_t qdm2_vlc_offs[] = {
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
280 0,260,566,598,894,1166,1230,1294,1678,1950,2214,2278,2310,2570,2834,3124,3448,3838,
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
281 };
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
282
9007
043574c5c153 Add missing av_cold in static init/close functions.
stefano
parents: 8718
diff changeset
283 static av_cold void qdm2_init_vlc(void)
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
284 {
9664
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
285 static int vlcs_initialized = 0;
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
286 static VLC_TYPE qdm2_table[3838][2];
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
287
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
288 if (!vlcs_initialized) {
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
289
9665
banan
parents: 9664
diff changeset
290 vlc_tab_level.table = &qdm2_table[qdm2_vlc_offs[0]];
banan
parents: 9664
diff changeset
291 vlc_tab_level.table_allocated = qdm2_vlc_offs[1] - qdm2_vlc_offs[0];
banan
parents: 9664
diff changeset
292 init_vlc (&vlc_tab_level, 8, 24,
banan
parents: 9664
diff changeset
293 vlc_tab_level_huffbits, 1, 1,
banan
parents: 9664
diff changeset
294 vlc_tab_level_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
295
9665
banan
parents: 9664
diff changeset
296 vlc_tab_diff.table = &qdm2_table[qdm2_vlc_offs[1]];
banan
parents: 9664
diff changeset
297 vlc_tab_diff.table_allocated = qdm2_vlc_offs[2] - qdm2_vlc_offs[1];
banan
parents: 9664
diff changeset
298 init_vlc (&vlc_tab_diff, 8, 37,
banan
parents: 9664
diff changeset
299 vlc_tab_diff_huffbits, 1, 1,
banan
parents: 9664
diff changeset
300 vlc_tab_diff_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
301
9665
banan
parents: 9664
diff changeset
302 vlc_tab_run.table = &qdm2_table[qdm2_vlc_offs[2]];
banan
parents: 9664
diff changeset
303 vlc_tab_run.table_allocated = qdm2_vlc_offs[3] - qdm2_vlc_offs[2];
banan
parents: 9664
diff changeset
304 init_vlc (&vlc_tab_run, 5, 6,
banan
parents: 9664
diff changeset
305 vlc_tab_run_huffbits, 1, 1,
banan
parents: 9664
diff changeset
306 vlc_tab_run_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
307
9665
banan
parents: 9664
diff changeset
308 fft_level_exp_alt_vlc.table = &qdm2_table[qdm2_vlc_offs[3]];
banan
parents: 9664
diff changeset
309 fft_level_exp_alt_vlc.table_allocated = qdm2_vlc_offs[4] - qdm2_vlc_offs[3];
banan
parents: 9664
diff changeset
310 init_vlc (&fft_level_exp_alt_vlc, 8, 28,
banan
parents: 9664
diff changeset
311 fft_level_exp_alt_huffbits, 1, 1,
banan
parents: 9664
diff changeset
312 fft_level_exp_alt_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
9664
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
313
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
314
9665
banan
parents: 9664
diff changeset
315 fft_level_exp_vlc.table = &qdm2_table[qdm2_vlc_offs[4]];
banan
parents: 9664
diff changeset
316 fft_level_exp_vlc.table_allocated = qdm2_vlc_offs[5] - qdm2_vlc_offs[4];
banan
parents: 9664
diff changeset
317 init_vlc (&fft_level_exp_vlc, 8, 20,
banan
parents: 9664
diff changeset
318 fft_level_exp_huffbits, 1, 1,
banan
parents: 9664
diff changeset
319 fft_level_exp_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
320
9665
banan
parents: 9664
diff changeset
321 fft_stereo_exp_vlc.table = &qdm2_table[qdm2_vlc_offs[5]];
banan
parents: 9664
diff changeset
322 fft_stereo_exp_vlc.table_allocated = qdm2_vlc_offs[6] - qdm2_vlc_offs[5];
banan
parents: 9664
diff changeset
323 init_vlc (&fft_stereo_exp_vlc, 6, 7,
banan
parents: 9664
diff changeset
324 fft_stereo_exp_huffbits, 1, 1,
banan
parents: 9664
diff changeset
325 fft_stereo_exp_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
326
9665
banan
parents: 9664
diff changeset
327 fft_stereo_phase_vlc.table = &qdm2_table[qdm2_vlc_offs[6]];
banan
parents: 9664
diff changeset
328 fft_stereo_phase_vlc.table_allocated = qdm2_vlc_offs[7] - qdm2_vlc_offs[6];
banan
parents: 9664
diff changeset
329 init_vlc (&fft_stereo_phase_vlc, 6, 9,
banan
parents: 9664
diff changeset
330 fft_stereo_phase_huffbits, 1, 1,
banan
parents: 9664
diff changeset
331 fft_stereo_phase_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
332
9665
banan
parents: 9664
diff changeset
333 vlc_tab_tone_level_idx_hi1.table = &qdm2_table[qdm2_vlc_offs[7]];
banan
parents: 9664
diff changeset
334 vlc_tab_tone_level_idx_hi1.table_allocated = qdm2_vlc_offs[8] - qdm2_vlc_offs[7];
banan
parents: 9664
diff changeset
335 init_vlc (&vlc_tab_tone_level_idx_hi1, 8, 20,
banan
parents: 9664
diff changeset
336 vlc_tab_tone_level_idx_hi1_huffbits, 1, 1,
banan
parents: 9664
diff changeset
337 vlc_tab_tone_level_idx_hi1_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
338
9665
banan
parents: 9664
diff changeset
339 vlc_tab_tone_level_idx_mid.table = &qdm2_table[qdm2_vlc_offs[8]];
banan
parents: 9664
diff changeset
340 vlc_tab_tone_level_idx_mid.table_allocated = qdm2_vlc_offs[9] - qdm2_vlc_offs[8];
banan
parents: 9664
diff changeset
341 init_vlc (&vlc_tab_tone_level_idx_mid, 8, 24,
banan
parents: 9664
diff changeset
342 vlc_tab_tone_level_idx_mid_huffbits, 1, 1,
banan
parents: 9664
diff changeset
343 vlc_tab_tone_level_idx_mid_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
344
9665
banan
parents: 9664
diff changeset
345 vlc_tab_tone_level_idx_hi2.table = &qdm2_table[qdm2_vlc_offs[9]];
banan
parents: 9664
diff changeset
346 vlc_tab_tone_level_idx_hi2.table_allocated = qdm2_vlc_offs[10] - qdm2_vlc_offs[9];
banan
parents: 9664
diff changeset
347 init_vlc (&vlc_tab_tone_level_idx_hi2, 8, 24,
banan
parents: 9664
diff changeset
348 vlc_tab_tone_level_idx_hi2_huffbits, 1, 1,
banan
parents: 9664
diff changeset
349 vlc_tab_tone_level_idx_hi2_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
350
9665
banan
parents: 9664
diff changeset
351 vlc_tab_type30.table = &qdm2_table[qdm2_vlc_offs[10]];
banan
parents: 9664
diff changeset
352 vlc_tab_type30.table_allocated = qdm2_vlc_offs[11] - qdm2_vlc_offs[10];
banan
parents: 9664
diff changeset
353 init_vlc (&vlc_tab_type30, 6, 9,
banan
parents: 9664
diff changeset
354 vlc_tab_type30_huffbits, 1, 1,
banan
parents: 9664
diff changeset
355 vlc_tab_type30_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
356
9665
banan
parents: 9664
diff changeset
357 vlc_tab_type34.table = &qdm2_table[qdm2_vlc_offs[11]];
banan
parents: 9664
diff changeset
358 vlc_tab_type34.table_allocated = qdm2_vlc_offs[12] - qdm2_vlc_offs[11];
banan
parents: 9664
diff changeset
359 init_vlc (&vlc_tab_type34, 5, 10,
banan
parents: 9664
diff changeset
360 vlc_tab_type34_huffbits, 1, 1,
banan
parents: 9664
diff changeset
361 vlc_tab_type34_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
362
9665
banan
parents: 9664
diff changeset
363 vlc_tab_fft_tone_offset[0].table = &qdm2_table[qdm2_vlc_offs[12]];
banan
parents: 9664
diff changeset
364 vlc_tab_fft_tone_offset[0].table_allocated = qdm2_vlc_offs[13] - qdm2_vlc_offs[12];
banan
parents: 9664
diff changeset
365 init_vlc (&vlc_tab_fft_tone_offset[0], 8, 23,
banan
parents: 9664
diff changeset
366 vlc_tab_fft_tone_offset_0_huffbits, 1, 1,
banan
parents: 9664
diff changeset
367 vlc_tab_fft_tone_offset_0_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
368
9665
banan
parents: 9664
diff changeset
369 vlc_tab_fft_tone_offset[1].table = &qdm2_table[qdm2_vlc_offs[13]];
banan
parents: 9664
diff changeset
370 vlc_tab_fft_tone_offset[1].table_allocated = qdm2_vlc_offs[14] - qdm2_vlc_offs[13];
banan
parents: 9664
diff changeset
371 init_vlc (&vlc_tab_fft_tone_offset[1], 8, 28,
banan
parents: 9664
diff changeset
372 vlc_tab_fft_tone_offset_1_huffbits, 1, 1,
banan
parents: 9664
diff changeset
373 vlc_tab_fft_tone_offset_1_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
374
9665
banan
parents: 9664
diff changeset
375 vlc_tab_fft_tone_offset[2].table = &qdm2_table[qdm2_vlc_offs[14]];
banan
parents: 9664
diff changeset
376 vlc_tab_fft_tone_offset[2].table_allocated = qdm2_vlc_offs[15] - qdm2_vlc_offs[14];
banan
parents: 9664
diff changeset
377 init_vlc (&vlc_tab_fft_tone_offset[2], 8, 32,
banan
parents: 9664
diff changeset
378 vlc_tab_fft_tone_offset_2_huffbits, 1, 1,
banan
parents: 9664
diff changeset
379 vlc_tab_fft_tone_offset_2_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
380
9665
banan
parents: 9664
diff changeset
381 vlc_tab_fft_tone_offset[3].table = &qdm2_table[qdm2_vlc_offs[15]];
banan
parents: 9664
diff changeset
382 vlc_tab_fft_tone_offset[3].table_allocated = qdm2_vlc_offs[16] - qdm2_vlc_offs[15];
banan
parents: 9664
diff changeset
383 init_vlc (&vlc_tab_fft_tone_offset[3], 8, 35,
banan
parents: 9664
diff changeset
384 vlc_tab_fft_tone_offset_3_huffbits, 1, 1,
banan
parents: 9664
diff changeset
385 vlc_tab_fft_tone_offset_3_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
386
9665
banan
parents: 9664
diff changeset
387 vlc_tab_fft_tone_offset[4].table = &qdm2_table[qdm2_vlc_offs[16]];
banan
parents: 9664
diff changeset
388 vlc_tab_fft_tone_offset[4].table_allocated = qdm2_vlc_offs[17] - qdm2_vlc_offs[16];
banan
parents: 9664
diff changeset
389 init_vlc (&vlc_tab_fft_tone_offset[4], 8, 38,
banan
parents: 9664
diff changeset
390 vlc_tab_fft_tone_offset_4_huffbits, 1, 1,
banan
parents: 9664
diff changeset
391 vlc_tab_fft_tone_offset_4_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
9664
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
392
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
393 vlcs_initialized=1;
df1875099613 Switch from INIT_VLC_USE_STATIC to INIT_VLC_USE_NEW_STATIC in qdm2.
banan
parents: 9538
diff changeset
394 }
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
395 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
396
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
397
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
398 /* for floating point to fixed point conversion */
7129
322023e630a6 mark read-only data as const
stefang
parents: 7040
diff changeset
399 static const float f2i_scale = (float) (1 << (FRAC_BITS - 15));
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
400
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
401
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
402 static int qdm2_get_vlc (GetBitContext *gb, VLC *vlc, int flag, int depth)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
403 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
404 int value;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
405
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
406 value = get_vlc2(gb, vlc->table, vlc->bits, depth);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
407
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
408 /* stage-2, 3 bits exponent escape sequence */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
409 if (value-- == 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
410 value = get_bits (gb, get_bits (gb, 3) + 1);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
411
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
412 /* stage-3, optional */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
413 if (flag) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
414 int tmp = vlc_stage3_values[value];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
415
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
416 if ((value & ~3) > 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
417 tmp += get_bits (gb, (value >> 2));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
418 value = tmp;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
419 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
420
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
421 return value;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
422 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
423
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
424
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
425 static int qdm2_get_se_vlc (VLC *vlc, GetBitContext *gb, int depth)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
426 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
427 int value = qdm2_get_vlc (gb, vlc, 0, depth);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
428
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
429 return (value & 1) ? ((value + 1) >> 1) : -(value >> 1);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
430 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
431
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
432
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
433 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
434 * QDM2 checksum
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
435 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
436 * @param data pointer to data to be checksum'ed
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
437 * @param length data length
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
438 * @param value checksum value
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
439 *
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
440 * @return 0 if checksum is OK
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
441 */
6273
michael
parents: 6122
diff changeset
442 static uint16_t qdm2_packet_checksum (const uint8_t *data, int length, int value) {
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
443 int i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
444
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
445 for (i=0; i < length; i++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
446 value -= data[i];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
447
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
448 return (uint16_t)(value & 0xffff);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
449 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
450
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
451
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
452 /**
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
453 * Fills a QDM2SubPacket structure with packet type, size, and data pointer.
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
454 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
455 * @param gb bitreader context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
456 * @param sub_packet packet under analysis
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
457 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
458 static void qdm2_decode_sub_packet_header (GetBitContext *gb, QDM2SubPacket *sub_packet)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
459 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
460 sub_packet->type = get_bits (gb, 8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
461
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
462 if (sub_packet->type == 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
463 sub_packet->size = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
464 sub_packet->data = NULL;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
465 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
466 sub_packet->size = get_bits (gb, 8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
467
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
468 if (sub_packet->type & 0x80) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
469 sub_packet->size <<= 8;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
470 sub_packet->size |= get_bits (gb, 8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
471 sub_packet->type &= 0x7f;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
472 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
473
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
474 if (sub_packet->type == 0x7f)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
475 sub_packet->type |= (get_bits (gb, 8) << 8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
476
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
477 sub_packet->data = &gb->buffer[get_bits_count(gb) / 8]; // FIXME: this depends on bitreader internal data
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
478 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
479
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
480 av_log(NULL,AV_LOG_DEBUG,"Subpacket: type=%d size=%d start_offs=%x\n",
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
481 sub_packet->type, sub_packet->size, get_bits_count(gb) / 8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
482 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
483
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
484
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
485 /**
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
486 * Return node pointer to first packet of requested type in list.
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
487 *
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
488 * @param list list of subpackets to be scanned
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
489 * @param type type of searched subpacket
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
490 * @return node pointer for subpacket if found, else NULL
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
491 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
492 static QDM2SubPNode* qdm2_search_subpacket_type_in_list (QDM2SubPNode *list, int type)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
493 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
494 while (list != NULL && list->packet != NULL) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
495 if (list->packet->type == type)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
496 return list;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
497 list = list->next;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
498 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
499 return NULL;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
500 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
501
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
502
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
503 /**
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
504 * Replaces 8 elements with their average value.
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
505 * Called by qdm2_decode_superblock before starting subblock decoding.
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
506 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
507 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
508 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
509 static void average_quantized_coeffs (QDM2Context *q)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
510 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
511 int i, j, n, ch, sum;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
512
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
513 n = coeff_per_sb_for_avg[q->coeff_per_sb_select][QDM2_SB_USED(q->sub_sampling) - 1] + 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
514
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
515 for (ch = 0; ch < q->nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
516 for (i = 0; i < n; i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
517 sum = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
518
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
519 for (j = 0; j < 8; j++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
520 sum += q->quantized_coeffs[ch][i][j];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
521
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
522 sum /= 8;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
523 if (sum > 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
524 sum--;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
525
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
526 for (j=0; j < 8; j++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
527 q->quantized_coeffs[ch][i][j] = sum;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
528 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
529 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
530
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
531
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
532 /**
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
533 * Build subband samples with noise weighted by q->tone_level.
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
534 * Called by synthfilt_build_sb_samples.
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
535 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
536 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
537 * @param sb subband index
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
538 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
539 static void build_sb_samples_from_noise (QDM2Context *q, int sb)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
540 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
541 int ch, j;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
542
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
543 FIX_NOISE_IDX(q->noise_idx);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
544
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
545 if (!q->nb_channels)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
546 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
547
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
548 for (ch = 0; ch < q->nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
549 for (j = 0; j < 64; j++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
550 q->sb_samples[ch][j * 2][sb] = (int32_t)(f2i_scale * SB_DITHERING_NOISE(sb,q->noise_idx) * q->tone_level[ch][sb][j] + .5);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
551 q->sb_samples[ch][j * 2 + 1][sb] = (int32_t)(f2i_scale * SB_DITHERING_NOISE(sb,q->noise_idx) * q->tone_level[ch][sb][j] + .5);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
552 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
553 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
554
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
555
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
556 /**
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
557 * Called while processing data from subpackets 11 and 12.
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
558 * Used after making changes to coding_method array.
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
559 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
560 * @param sb subband index
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
561 * @param channels number of channels
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
562 * @param coding_method q->coding_method[0][0][0]
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
563 */
3076
50d80b04f150 add static keyword to some functions
mru
parents: 3043
diff changeset
564 static void fix_coding_method_array (int sb, int channels, sb_int8_array coding_method)
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
565 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
566 int j,k;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
567 int ch;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
568 int run, case_val;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
569 int switchtable[23] = {0,5,1,5,5,5,5,5,2,5,5,5,5,5,5,5,3,5,5,5,5,5,4};
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
570
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
571 for (ch = 0; ch < channels; ch++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
572 for (j = 0; j < 64; ) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
573 if((coding_method[ch][sb][j] - 8) > 22) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
574 run = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
575 case_val = 8;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
576 } else {
3333
6bfe6c09d837 Fixed a possible bug, checked against the assembly.
banan
parents: 3320
diff changeset
577 switch (switchtable[coding_method[ch][sb][j]-8]) {
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
578 case 0: run = 10; case_val = 10; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
579 case 1: run = 1; case_val = 16; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
580 case 2: run = 5; case_val = 24; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
581 case 3: run = 3; case_val = 30; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
582 case 4: run = 1; case_val = 30; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
583 case 5: run = 1; case_val = 8; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
584 default: run = 1; case_val = 8; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
585 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
586 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
587 for (k = 0; k < run; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
588 if (j + k < 128)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
589 if (coding_method[ch][sb + (j + k) / 64][(j + k) % 64] > coding_method[ch][sb][j])
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
590 if (k > 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
591 SAMPLES_NEEDED
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
592 //not debugged, almost never used
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
593 memset(&coding_method[ch][sb][j + k], case_val, k * sizeof(int8_t));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
594 memset(&coding_method[ch][sb][j + k], case_val, 3 * sizeof(int8_t));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
595 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
596 j += run;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
597 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
598 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
599 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
600
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
601
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
602 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
603 * Related to synthesis filter
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
604 * Called by process_subpacket_10
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
605 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
606 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
607 * @param flag 1 if called after getting data from subpacket 10, 0 if no subpacket 10
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
608 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
609 static void fill_tone_level_array (QDM2Context *q, int flag)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
610 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
611 int i, sb, ch, sb_used;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
612 int tmp, tab;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
613
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
614 // This should never happen
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
615 if (q->nb_channels <= 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
616 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
617
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
618 for (ch = 0; ch < q->nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
619 for (sb = 0; sb < 30; sb++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
620 for (i = 0; i < 8; i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
621 if ((tab=coeff_per_sb_for_dequant[q->coeff_per_sb_select][sb]) < (last_coeff[q->coeff_per_sb_select] - 1))
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
622 tmp = q->quantized_coeffs[ch][tab + 1][i] * dequant_table[q->coeff_per_sb_select][tab + 1][sb]+
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
623 q->quantized_coeffs[ch][tab][i] * dequant_table[q->coeff_per_sb_select][tab][sb];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
624 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
625 tmp = q->quantized_coeffs[ch][tab][i] * dequant_table[q->coeff_per_sb_select][tab][sb];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
626 if(tmp < 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
627 tmp += 0xff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
628 q->tone_level_idx_base[ch][sb][i] = (tmp / 256) & 0xff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
629 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
630
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
631 sb_used = QDM2_SB_USED(q->sub_sampling);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
632
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
633 if ((q->superblocktype_2_3 != 0) && !flag) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
634 for (sb = 0; sb < sb_used; sb++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
635 for (ch = 0; ch < q->nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
636 for (i = 0; i < 64; i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
637 q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
638 if (q->tone_level_idx[ch][sb][i] < 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
639 q->tone_level[ch][sb][i] = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
640 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
641 q->tone_level[ch][sb][i] = fft_tone_level_table[0][q->tone_level_idx[ch][sb][i] & 0x3f];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
642 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
643 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
644 tab = q->superblocktype_2_3 ? 0 : 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
645 for (sb = 0; sb < sb_used; sb++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
646 if ((sb >= 4) && (sb <= 23)) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
647 for (ch = 0; ch < q->nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
648 for (i = 0; i < 64; i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
649 tmp = q->tone_level_idx_base[ch][sb][i / 8] -
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
650 q->tone_level_idx_hi1[ch][sb / 8][i / 8][i % 8] -
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
651 q->tone_level_idx_mid[ch][sb - 4][i / 8] -
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
652 q->tone_level_idx_hi2[ch][sb - 4];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
653 q->tone_level_idx[ch][sb][i] = tmp & 0xff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
654 if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
655 q->tone_level[ch][sb][i] = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
656 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
657 q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
658 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
659 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
660 if (sb > 4) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
661 for (ch = 0; ch < q->nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
662 for (i = 0; i < 64; i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
663 tmp = q->tone_level_idx_base[ch][sb][i / 8] -
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
664 q->tone_level_idx_hi1[ch][2][i / 8][i % 8] -
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
665 q->tone_level_idx_hi2[ch][sb - 4];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
666 q->tone_level_idx[ch][sb][i] = tmp & 0xff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
667 if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
668 q->tone_level[ch][sb][i] = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
669 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
670 q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
671 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
672 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
673 for (ch = 0; ch < q->nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
674 for (i = 0; i < 64; i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
675 tmp = q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
676 if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
677 q->tone_level[ch][sb][i] = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
678 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
679 q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
680 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
681 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
682 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
683 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
684 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
685
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
686 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
687 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
688
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
689
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
690 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
691 * Related to synthesis filter
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
692 * Called by process_subpacket_11
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
693 * c is built with data from subpacket 11
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
694 * Most of this function is used only if superblock_type_2_3 == 0, never seen it in samples
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
695 *
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
696 * @param tone_level_idx
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
697 * @param tone_level_idx_temp
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
698 * @param coding_method q->coding_method[0][0][0]
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
699 * @param nb_channels number of channels
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
700 * @param c coming from subpacket 11, passed as 8*c
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
701 * @param superblocktype_2_3 flag based on superblock packet type
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
702 * @param cm_table_select q->cm_table_select
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
703 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
704 static void fill_coding_method_array (sb_int8_array tone_level_idx, sb_int8_array tone_level_idx_temp,
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
705 sb_int8_array coding_method, int nb_channels,
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
706 int c, int superblocktype_2_3, int cm_table_select)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
707 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
708 int ch, sb, j;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
709 int tmp, acc, esp_40, comp;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
710 int add1, add2, add3, add4;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
711 int64_t multres;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
712
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
713 // This should never happen
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
714 if (nb_channels <= 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
715 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
716
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
717 if (!superblocktype_2_3) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
718 /* This case is untested, no samples available */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
719 SAMPLES_NEEDED
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
720 for (ch = 0; ch < nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
721 for (sb = 0; sb < 30; sb++) {
7326
fe8a7f5905e4 Prevent the qdm2 code from overreading/overflowing. Fixes Coverity ID 112 run 2
banan
parents: 7323
diff changeset
722 for (j = 1; j < 63; j++) { // The loop only iterates to 63 so the code doesn't overflow the buffer
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
723 add1 = tone_level_idx[ch][sb][j] - 10;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
724 if (add1 < 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
725 add1 = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
726 add2 = add3 = add4 = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
727 if (sb > 1) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
728 add2 = tone_level_idx[ch][sb - 2][j] + tone_level_idx_offset_table[sb][0] - 6;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
729 if (add2 < 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
730 add2 = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
731 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
732 if (sb > 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
733 add3 = tone_level_idx[ch][sb - 1][j] + tone_level_idx_offset_table[sb][1] - 6;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
734 if (add3 < 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
735 add3 = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
736 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
737 if (sb < 29) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
738 add4 = tone_level_idx[ch][sb + 1][j] + tone_level_idx_offset_table[sb][3] - 6;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
739 if (add4 < 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
740 add4 = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
741 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
742 tmp = tone_level_idx[ch][sb][j + 1] * 2 - add4 - add3 - add2 - add1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
743 if (tmp < 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
744 tmp = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
745 tone_level_idx_temp[ch][sb][j + 1] = tmp & 0xff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
746 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
747 tone_level_idx_temp[ch][sb][0] = tone_level_idx_temp[ch][sb][1];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
748 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
749 acc = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
750 for (ch = 0; ch < nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
751 for (sb = 0; sb < 30; sb++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
752 for (j = 0; j < 64; j++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
753 acc += tone_level_idx_temp[ch][sb][j];
9538
b76f2d264edb Remove redundant code, found by CSA
banan
parents: 9428
diff changeset
754
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
755 multres = 0x66666667 * (acc * 10);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
756 esp_40 = (multres >> 32) / 8 + ((multres & 0xffffffff) >> 31);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
757 for (ch = 0; ch < nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
758 for (sb = 0; sb < 30; sb++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
759 for (j = 0; j < 64; j++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
760 comp = tone_level_idx_temp[ch][sb][j]* esp_40 * 10;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
761 if (comp < 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
762 comp += 0xff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
763 comp /= 256; // signed shift
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
764 switch(sb) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
765 case 0:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
766 if (comp < 30)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
767 comp = 30;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
768 comp += 15;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
769 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
770 case 1:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
771 if (comp < 24)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
772 comp = 24;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
773 comp += 10;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
774 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
775 case 2:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
776 case 3:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
777 case 4:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
778 if (comp < 16)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
779 comp = 16;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
780 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
781 if (comp <= 5)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
782 tmp = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
783 else if (comp <= 10)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
784 tmp = 10;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
785 else if (comp <= 16)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
786 tmp = 16;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
787 else if (comp <= 24)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
788 tmp = -1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
789 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
790 tmp = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
791 coding_method[ch][sb][j] = ((tmp & 0xfffa) + 30 )& 0xff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
792 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
793 for (sb = 0; sb < 30; sb++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
794 fix_coding_method_array(sb, nb_channels, coding_method);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
795 for (ch = 0; ch < nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
796 for (sb = 0; sb < 30; sb++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
797 for (j = 0; j < 64; j++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
798 if (sb >= 10) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
799 if (coding_method[ch][sb][j] < 10)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
800 coding_method[ch][sb][j] = 10;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
801 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
802 if (sb >= 2) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
803 if (coding_method[ch][sb][j] < 16)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
804 coding_method[ch][sb][j] = 16;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
805 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
806 if (coding_method[ch][sb][j] < 30)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
807 coding_method[ch][sb][j] = 30;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
808 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
809 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
810 } else { // superblocktype_2_3 != 0
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
811 for (ch = 0; ch < nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
812 for (sb = 0; sb < 30; sb++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
813 for (j = 0; j < 64; j++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
814 coding_method[ch][sb][j] = coding_method_table[cm_table_select][sb];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
815 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
816
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
817 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
818 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
819
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
820
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
821 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
822 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
823 * Called by process_subpacket_11 to process more data from subpacket 11 with sb 0-8
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
824 * Called by process_subpacket_12 to process data from subpacket 12 with sb 8-sb_used
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
825 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
826 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
827 * @param gb bitreader context
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
828 * @param length packet length in bits
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
829 * @param sb_min lower subband processed (sb_min included)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
830 * @param sb_max higher subband processed (sb_max excluded)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
831 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
832 static void synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int length, int sb_min, int sb_max)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
833 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
834 int sb, j, k, n, ch, run, channels;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
835 int joined_stereo, zero_encoding, chs;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
836 int type34_first;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
837 float type34_div = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
838 float type34_predictor;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
839 float samples[10], sign_bits[16];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
840
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
841 if (length == 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
842 // If no data use noise
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
843 for (sb=sb_min; sb < sb_max; sb++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
844 build_sb_samples_from_noise (q, sb);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
845
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
846 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
847 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
848
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
849 for (sb = sb_min; sb < sb_max; sb++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
850 FIX_NOISE_IDX(q->noise_idx);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
851
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
852 channels = q->nb_channels;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
853
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
854 if (q->nb_channels <= 1 || sb < 12)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
855 joined_stereo = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
856 else if (sb >= 24)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
857 joined_stereo = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
858 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
859 joined_stereo = (BITS_LEFT(length,gb) >= 1) ? get_bits1 (gb) : 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
860
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
861 if (joined_stereo) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
862 if (BITS_LEFT(length,gb) >= 16)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
863 for (j = 0; j < 16; j++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
864 sign_bits[j] = get_bits1 (gb);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
865
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
866 for (j = 0; j < 64; j++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
867 if (q->coding_method[1][sb][j] > q->coding_method[0][sb][j])
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
868 q->coding_method[0][sb][j] = q->coding_method[1][sb][j];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
869
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
870 fix_coding_method_array(sb, q->nb_channels, q->coding_method);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
871 channels = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
872 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
873
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
874 for (ch = 0; ch < channels; ch++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
875 zero_encoding = (BITS_LEFT(length,gb) >= 1) ? get_bits1(gb) : 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
876 type34_predictor = 0.0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
877 type34_first = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
878
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
879 for (j = 0; j < 128; ) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
880 switch (q->coding_method[ch][sb][j / 2]) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
881 case 8:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
882 if (BITS_LEFT(length,gb) >= 10) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
883 if (zero_encoding) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
884 for (k = 0; k < 5; k++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
885 if ((j + 2 * k) >= 128)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
886 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
887 samples[2 * k] = get_bits1(gb) ? dequant_1bit[joined_stereo][2 * get_bits1(gb)] : 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
888 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
889 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
890 n = get_bits(gb, 8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
891 for (k = 0; k < 5; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
892 samples[2 * k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
893 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
894 for (k = 0; k < 5; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
895 samples[2 * k + 1] = SB_DITHERING_NOISE(sb,q->noise_idx);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
896 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
897 for (k = 0; k < 10; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
898 samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
899 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
900 run = 10;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
901 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
902
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
903 case 10:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
904 if (BITS_LEFT(length,gb) >= 1) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
905 float f = 0.81;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
906
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
907 if (get_bits1(gb))
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
908 f = -f;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
909 f -= noise_samples[((sb + 1) * (j +5 * ch + 1)) & 127] * 9.0 / 40.0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
910 samples[0] = f;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
911 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
912 samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
913 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
914 run = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
915 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
916
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
917 case 16:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
918 if (BITS_LEFT(length,gb) >= 10) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
919 if (zero_encoding) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
920 for (k = 0; k < 5; k++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
921 if ((j + k) >= 128)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
922 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
923 samples[k] = (get_bits1(gb) == 0) ? 0 : dequant_1bit[joined_stereo][2 * get_bits1(gb)];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
924 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
925 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
926 n = get_bits (gb, 8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
927 for (k = 0; k < 5; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
928 samples[k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
929 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
930 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
931 for (k = 0; k < 5; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
932 samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
933 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
934 run = 5;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
935 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
936
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
937 case 24:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
938 if (BITS_LEFT(length,gb) >= 7) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
939 n = get_bits(gb, 7);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
940 for (k = 0; k < 3; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
941 samples[k] = (random_dequant_type24[n][k] - 2.0) * 0.5;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
942 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
943 for (k = 0; k < 3; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
944 samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
945 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
946 run = 3;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
947 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
948
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
949 case 30:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
950 if (BITS_LEFT(length,gb) >= 4)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
951 samples[0] = type30_dequant[qdm2_get_vlc(gb, &vlc_tab_type30, 0, 1)];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
952 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
953 samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
954
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
955 run = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
956 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
957
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
958 case 34:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
959 if (BITS_LEFT(length,gb) >= 7) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
960 if (type34_first) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
961 type34_div = (float)(1 << get_bits(gb, 2));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
962 samples[0] = ((float)get_bits(gb, 5) - 16.0) / 15.0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
963 type34_predictor = samples[0];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
964 type34_first = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
965 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
966 samples[0] = type34_delta[qdm2_get_vlc(gb, &vlc_tab_type34, 0, 1)] / type34_div + type34_predictor;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
967 type34_predictor = samples[0];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
968 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
969 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
970 samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
971 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
972 run = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
973 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
974
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
975 default:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
976 samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
977 run = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
978 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
979 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
980
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
981 if (joined_stereo) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
982 float tmp[10][MPA_MAX_CHANNELS];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
983
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
984 for (k = 0; k < run; k++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
985 tmp[k][0] = samples[k];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
986 tmp[k][1] = (sign_bits[(j + k) / 8]) ? -samples[k] : samples[k];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
987 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
988 for (chs = 0; chs < q->nb_channels; chs++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
989 for (k = 0; k < run; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
990 if ((j + k) < 128)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
991 q->sb_samples[chs][j + k][sb] = (int32_t)(f2i_scale * q->tone_level[chs][sb][((j + k)/2)] * tmp[k][chs] + .5);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
992 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
993 for (k = 0; k < run; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
994 if ((j + k) < 128)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
995 q->sb_samples[ch][j + k][sb] = (int32_t)(f2i_scale * q->tone_level[ch][sb][(j + k)/2] * samples[k] + .5);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
996 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
997
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
998 j += run;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
999 } // j loop
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1000 } // channel loop
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1001 } // subband loop
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1002 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1003
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1004
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1005 /**
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1006 * Init the first element of a channel in quantized_coeffs with data from packet 10 (quantized_coeffs[ch][0]).
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1007 * This is similar to process_subpacket_9, but for a single channel and for element [0]
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1008 * same VLC tables as process_subpacket_9 are used.
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1009 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1010 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1011 * @param quantized_coeffs pointer to quantized_coeffs[ch][0]
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1012 * @param gb bitreader context
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1013 * @param length packet length in bits
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1014 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1015 static void init_quantized_coeffs_elem0 (int8_t *quantized_coeffs, GetBitContext *gb, int length)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1016 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1017 int i, k, run, level, diff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1018
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1019 if (BITS_LEFT(length,gb) < 16)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1020 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1021 level = qdm2_get_vlc(gb, &vlc_tab_level, 0, 2);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1022
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1023 quantized_coeffs[0] = level;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1024
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1025 for (i = 0; i < 7; ) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1026 if (BITS_LEFT(length,gb) < 16)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1027 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1028 run = qdm2_get_vlc(gb, &vlc_tab_run, 0, 1) + 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1029
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1030 if (BITS_LEFT(length,gb) < 16)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1031 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1032 diff = qdm2_get_se_vlc(&vlc_tab_diff, gb, 2);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1033
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1034 for (k = 1; k <= run; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1035 quantized_coeffs[i + k] = (level + ((k * diff) / run));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1036
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1037 level += diff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1038 i += run;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1039 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1040 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1041
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1042
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1043 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1044 * Related to synthesis filter, process data from packet 10
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1045 * Init part of quantized_coeffs via function init_quantized_coeffs_elem0
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1046 * Init tone_level_idx_hi1, tone_level_idx_hi2, tone_level_idx_mid with data from packet 10
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1047 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1048 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1049 * @param gb bitreader context
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1050 * @param length packet length in bits
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1051 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1052 static void init_tone_level_dequantization (QDM2Context *q, GetBitContext *gb, int length)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1053 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1054 int sb, j, k, n, ch;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1055
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1056 for (ch = 0; ch < q->nb_channels; ch++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1057 init_quantized_coeffs_elem0(q->quantized_coeffs[ch][0], gb, length);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1058
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1059 if (BITS_LEFT(length,gb) < 16) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1060 memset(q->quantized_coeffs[ch][0], 0, 8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1061 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1062 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1063 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1064
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1065 n = q->sub_sampling + 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1066
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1067 for (sb = 0; sb < n; sb++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1068 for (ch = 0; ch < q->nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1069 for (j = 0; j < 8; j++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1070 if (BITS_LEFT(length,gb) < 1)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1071 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1072 if (get_bits1(gb)) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1073 for (k=0; k < 8; k++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1074 if (BITS_LEFT(length,gb) < 16)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1075 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1076 q->tone_level_idx_hi1[ch][sb][j][k] = qdm2_get_vlc(gb, &vlc_tab_tone_level_idx_hi1, 0, 2);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1077 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1078 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1079 for (k=0; k < 8; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1080 q->tone_level_idx_hi1[ch][sb][j][k] = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1081 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1082 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1083
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1084 n = QDM2_SB_USED(q->sub_sampling) - 4;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1085
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1086 for (sb = 0; sb < n; sb++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1087 for (ch = 0; ch < q->nb_channels; ch++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1088 if (BITS_LEFT(length,gb) < 16)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1089 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1090 q->tone_level_idx_hi2[ch][sb] = qdm2_get_vlc(gb, &vlc_tab_tone_level_idx_hi2, 0, 2);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1091 if (sb > 19)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1092 q->tone_level_idx_hi2[ch][sb] -= 16;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1093 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1094 for (j = 0; j < 8; j++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1095 q->tone_level_idx_mid[ch][sb][j] = -16;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1096 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1097
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1098 n = QDM2_SB_USED(q->sub_sampling) - 5;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1099
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1100 for (sb = 0; sb < n; sb++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1101 for (ch = 0; ch < q->nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1102 for (j = 0; j < 8; j++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1103 if (BITS_LEFT(length,gb) < 16)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1104 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1105 q->tone_level_idx_mid[ch][sb][j] = qdm2_get_vlc(gb, &vlc_tab_tone_level_idx_mid, 0, 2) - 32;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1106 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1107 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1108
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1109 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1110 * Process subpacket 9, init quantized_coeffs with data from it
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1111 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1112 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1113 * @param node pointer to node with packet
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1114 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1115 static void process_subpacket_9 (QDM2Context *q, QDM2SubPNode *node)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1116 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1117 GetBitContext gb;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1118 int i, j, k, n, ch, run, level, diff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1119
2916
767156b9aa0d init_get_bits() requires size in bits, not bytes
rtognimp
parents: 2914
diff changeset
1120 init_get_bits(&gb, node->packet->data, node->packet->size*8);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1121
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1122 n = coeff_per_sb_for_avg[q->coeff_per_sb_select][QDM2_SB_USED(q->sub_sampling) - 1] + 1; // same as averagesomething function
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1123
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1124 for (i = 1; i < n; i++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1125 for (ch=0; ch < q->nb_channels; ch++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1126 level = qdm2_get_vlc(&gb, &vlc_tab_level, 0, 2);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1127 q->quantized_coeffs[ch][i][0] = level;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1128
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1129 for (j = 0; j < (8 - 1); ) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1130 run = qdm2_get_vlc(&gb, &vlc_tab_run, 0, 1) + 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1131 diff = qdm2_get_se_vlc(&vlc_tab_diff, &gb, 2);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1132
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1133 for (k = 1; k <= run; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1134 q->quantized_coeffs[ch][i][j + k] = (level + ((k*diff) / run));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1135
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1136 level += diff;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1137 j += run;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1138 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1139 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1140
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1141 for (ch = 0; ch < q->nb_channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1142 for (i = 0; i < 8; i++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1143 q->quantized_coeffs[ch][0][i] = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1144 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1145
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1146
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1147 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1148 * Process subpacket 10 if not null, else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1149 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1150 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1151 * @param node pointer to node with packet
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1152 * @param length packet length in bits
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1153 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1154 static void process_subpacket_10 (QDM2Context *q, QDM2SubPNode *node, int length)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1155 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1156 GetBitContext gb;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1157
2916
767156b9aa0d init_get_bits() requires size in bits, not bytes
rtognimp
parents: 2914
diff changeset
1158 init_get_bits(&gb, ((node == NULL) ? empty_buffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size*8));
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1159
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1160 if (length != 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1161 init_tone_level_dequantization(q, &gb, length);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1162 fill_tone_level_array(q, 1);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1163 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1164 fill_tone_level_array(q, 0);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1165 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1166 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1167
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1168
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1169 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1170 * Process subpacket 11
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1171 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1172 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1173 * @param node pointer to node with packet
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1174 * @param length packet length in bit
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1175 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1176 static void process_subpacket_11 (QDM2Context *q, QDM2SubPNode *node, int length)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1177 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1178 GetBitContext gb;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1179
2916
767156b9aa0d init_get_bits() requires size in bits, not bytes
rtognimp
parents: 2914
diff changeset
1180 init_get_bits(&gb, ((node == NULL) ? empty_buffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size*8));
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1181 if (length >= 32) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1182 int c = get_bits (&gb, 13);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1183
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1184 if (c > 3)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1185 fill_coding_method_array (q->tone_level_idx, q->tone_level_idx_temp, q->coding_method,
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1186 q->nb_channels, 8*c, q->superblocktype_2_3, q->cm_table_select);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1187 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1188
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1189 synthfilt_build_sb_samples(q, &gb, length, 0, 8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1190 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1191
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1192
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1193 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1194 * Process subpacket 12
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1195 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1196 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1197 * @param node pointer to node with packet
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1198 * @param length packet length in bits
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1199 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1200 static void process_subpacket_12 (QDM2Context *q, QDM2SubPNode *node, int length)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1201 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1202 GetBitContext gb;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1203
2916
767156b9aa0d init_get_bits() requires size in bits, not bytes
rtognimp
parents: 2914
diff changeset
1204 init_get_bits(&gb, ((node == NULL) ? empty_buffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size*8));
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1205 synthfilt_build_sb_samples(q, &gb, length, 8, QDM2_SB_USED(q->sub_sampling));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1206 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1207
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1208 /*
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1209 * Process new subpackets for synthesis filter
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1210 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1211 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1212 * @param list list with synthesis filter packets (list D)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1213 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1214 static void process_synthesis_subpackets (QDM2Context *q, QDM2SubPNode *list)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1215 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1216 QDM2SubPNode *nodes[4];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1217
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1218 nodes[0] = qdm2_search_subpacket_type_in_list(list, 9);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1219 if (nodes[0] != NULL)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1220 process_subpacket_9(q, nodes[0]);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1221
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1222 nodes[1] = qdm2_search_subpacket_type_in_list(list, 10);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1223 if (nodes[1] != NULL)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1224 process_subpacket_10(q, nodes[1], nodes[1]->packet->size << 3);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1225 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1226 process_subpacket_10(q, NULL, 0);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1227
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1228 nodes[2] = qdm2_search_subpacket_type_in_list(list, 11);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1229 if (nodes[0] != NULL && nodes[1] != NULL && nodes[2] != NULL)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1230 process_subpacket_11(q, nodes[2], (nodes[2]->packet->size << 3));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1231 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1232 process_subpacket_11(q, NULL, 0);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1233
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1234 nodes[3] = qdm2_search_subpacket_type_in_list(list, 12);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1235 if (nodes[0] != NULL && nodes[1] != NULL && nodes[3] != NULL)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1236 process_subpacket_12(q, nodes[3], (nodes[3]->packet->size << 3));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1237 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1238 process_subpacket_12(q, NULL, 0);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1239 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1240
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1241
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1242 /*
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1243 * Decode superblock, fill packet lists.
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1244 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1245 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1246 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1247 static void qdm2_decode_super_block (QDM2Context *q)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1248 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1249 GetBitContext gb;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1250 QDM2SubPacket header, *packet;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1251 int i, packet_bytes, sub_packet_size, sub_packets_D;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1252 unsigned int next_index = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1253
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1254 memset(q->tone_level_idx_hi1, 0, sizeof(q->tone_level_idx_hi1));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1255 memset(q->tone_level_idx_mid, 0, sizeof(q->tone_level_idx_mid));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1256 memset(q->tone_level_idx_hi2, 0, sizeof(q->tone_level_idx_hi2));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1257
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1258 q->sub_packets_B = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1259 sub_packets_D = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1260
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1261 average_quantized_coeffs(q); // average elements in quantized_coeffs[max_ch][10][8]
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1262
2916
767156b9aa0d init_get_bits() requires size in bits, not bytes
rtognimp
parents: 2914
diff changeset
1263 init_get_bits(&gb, q->compressed_data, q->compressed_size*8);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1264 qdm2_decode_sub_packet_header(&gb, &header);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1265
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1266 if (header.type < 2 || header.type >= 8) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1267 q->has_errors = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1268 av_log(NULL,AV_LOG_ERROR,"bad superblock type\n");
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1269 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1270 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1271
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1272 q->superblocktype_2_3 = (header.type == 2 || header.type == 3);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1273 packet_bytes = (q->compressed_size - get_bits_count(&gb) / 8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1274
2916
767156b9aa0d init_get_bits() requires size in bits, not bytes
rtognimp
parents: 2914
diff changeset
1275 init_get_bits(&gb, header.data, header.size*8);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1276
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1277 if (header.type == 2 || header.type == 4 || header.type == 5) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1278 int csum = 257 * get_bits(&gb, 8) + 2 * get_bits(&gb, 8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1279
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1280 csum = qdm2_packet_checksum(q->compressed_data, q->checksum_size, csum);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1281
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1282 if (csum != 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1283 q->has_errors = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1284 av_log(NULL,AV_LOG_ERROR,"bad packet checksum\n");
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1285 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1286 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1287 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1288
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1289 q->sub_packet_list_B[0].packet = NULL;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1290 q->sub_packet_list_D[0].packet = NULL;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1291
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1292 for (i = 0; i < 6; i++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1293 if (--q->fft_level_exp[i] < 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1294 q->fft_level_exp[i] = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1295
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1296 for (i = 0; packet_bytes > 0; i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1297 int j;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1298
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1299 q->sub_packet_list_A[i].next = NULL;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1300
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1301 if (i > 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1302 q->sub_packet_list_A[i - 1].next = &q->sub_packet_list_A[i];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1303
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1304 /* seek to next block */
2916
767156b9aa0d init_get_bits() requires size in bits, not bytes
rtognimp
parents: 2914
diff changeset
1305 init_get_bits(&gb, header.data, header.size*8);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1306 skip_bits(&gb, next_index*8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1307
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1308 if (next_index >= header.size)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1309 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1310 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1311
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1312 /* decode subpacket */
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1313 packet = &q->sub_packets[i];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1314 qdm2_decode_sub_packet_header(&gb, packet);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1315 next_index = packet->size + get_bits_count(&gb) / 8;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1316 sub_packet_size = ((packet->size > 0xff) ? 1 : 0) + packet->size + 2;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1317
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1318 if (packet->type == 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1319 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1320
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1321 if (sub_packet_size > packet_bytes) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1322 if (packet->type != 10 && packet->type != 11 && packet->type != 12)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1323 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1324 packet->size += packet_bytes - sub_packet_size;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1325 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1326
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1327 packet_bytes -= sub_packet_size;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1328
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1329 /* add subpacket to 'all subpackets' list */
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1330 q->sub_packet_list_A[i].packet = packet;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1331
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1332 /* add subpacket to related list */
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1333 if (packet->type == 8) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1334 SAMPLES_NEEDED_2("packet type 8");
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1335 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1336 } else if (packet->type >= 9 && packet->type <= 12) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1337 /* packets for MPEG Audio like Synthesis Filter */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1338 QDM2_LIST_ADD(q->sub_packet_list_D, sub_packets_D, packet);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1339 } else if (packet->type == 13) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1340 for (j = 0; j < 6; j++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1341 q->fft_level_exp[j] = get_bits(&gb, 6);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1342 } else if (packet->type == 14) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1343 for (j = 0; j < 6; j++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1344 q->fft_level_exp[j] = qdm2_get_vlc(&gb, &fft_level_exp_vlc, 0, 2);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1345 } else if (packet->type == 15) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1346 SAMPLES_NEEDED_2("packet type 15")
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1347 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1348 } else if (packet->type >= 16 && packet->type < 48 && !fft_subpackets[packet->type - 16]) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1349 /* packets for FFT */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1350 QDM2_LIST_ADD(q->sub_packet_list_B, q->sub_packets_B, packet);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1351 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1352 } // Packet bytes loop
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1353
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1354 /* **************************************************************** */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1355 if (q->sub_packet_list_D[0].packet != NULL) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1356 process_synthesis_subpackets(q, q->sub_packet_list_D);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1357 q->do_synth_filter = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1358 } else if (q->do_synth_filter) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1359 process_subpacket_10(q, NULL, 0);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1360 process_subpacket_11(q, NULL, 0);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1361 process_subpacket_12(q, NULL, 0);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1362 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1363 /* **************************************************************** */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1364 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1365
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1366
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1367 static void qdm2_fft_init_coefficient (QDM2Context *q, int sub_packet,
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1368 int offset, int duration, int channel,
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1369 int exp, int phase)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1370 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1371 if (q->fft_coefs_min_index[duration] < 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1372 q->fft_coefs_min_index[duration] = q->fft_coefs_index;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1373
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1374 q->fft_coefs[q->fft_coefs_index].sub_packet = ((sub_packet >= 16) ? (sub_packet - 16) : sub_packet);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1375 q->fft_coefs[q->fft_coefs_index].channel = channel;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1376 q->fft_coefs[q->fft_coefs_index].offset = offset;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1377 q->fft_coefs[q->fft_coefs_index].exp = exp;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1378 q->fft_coefs[q->fft_coefs_index].phase = phase;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1379 q->fft_coefs_index++;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1380 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1381
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1382
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1383 static void qdm2_fft_decode_tones (QDM2Context *q, int duration, GetBitContext *gb, int b)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1384 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1385 int channel, stereo, phase, exp;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1386 int local_int_4, local_int_8, stereo_phase, local_int_10;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1387 int local_int_14, stereo_exp, local_int_20, local_int_28;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1388 int n, offset;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1389
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1390 local_int_4 = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1391 local_int_28 = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1392 local_int_20 = 2;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1393 local_int_8 = (4 - duration);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1394 local_int_10 = 1 << (q->group_order - duration - 1);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1395 offset = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1396
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1397 while (1) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1398 if (q->superblocktype_2_3) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1399 while ((n = qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2)) < 2) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1400 offset = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1401 if (n == 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1402 local_int_4 += local_int_10;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1403 local_int_28 += (1 << local_int_8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1404 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1405 local_int_4 += 8*local_int_10;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1406 local_int_28 += (8 << local_int_8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1407 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1408 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1409 offset += (n - 2);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1410 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1411 offset += qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1412 while (offset >= (local_int_10 - 1)) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1413 offset += (1 - (local_int_10 - 1));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1414 local_int_4 += local_int_10;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1415 local_int_28 += (1 << local_int_8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1416 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1417 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1418
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1419 if (local_int_4 >= q->group_size)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1420 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1421
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1422 local_int_14 = (offset >> local_int_8);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1423
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1424 if (q->nb_channels > 1) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1425 channel = get_bits1(gb);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1426 stereo = get_bits1(gb);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1427 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1428 channel = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1429 stereo = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1430 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1431
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1432 exp = qdm2_get_vlc(gb, (b ? &fft_level_exp_vlc : &fft_level_exp_alt_vlc), 0, 2);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1433 exp += q->fft_level_exp[fft_level_index_table[local_int_14]];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1434 exp = (exp < 0) ? 0 : exp;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1435
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1436 phase = get_bits(gb, 3);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1437 stereo_exp = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1438 stereo_phase = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1439
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1440 if (stereo) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1441 stereo_exp = (exp - qdm2_get_vlc(gb, &fft_stereo_exp_vlc, 0, 1));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1442 stereo_phase = (phase - qdm2_get_vlc(gb, &fft_stereo_phase_vlc, 0, 1));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1443 if (stereo_phase < 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1444 stereo_phase += 8;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1445 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1446
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1447 if (q->frequency_range > (local_int_14 + 1)) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1448 int sub_packet = (local_int_20 + local_int_28);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1449
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1450 qdm2_fft_init_coefficient(q, sub_packet, offset, duration, channel, exp, phase);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1451 if (stereo)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1452 qdm2_fft_init_coefficient(q, sub_packet, offset, duration, (1 - channel), stereo_exp, stereo_phase);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1453 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1454
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1455 offset++;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1456 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1457 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1458
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1459
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1460 static void qdm2_decode_fft_packets (QDM2Context *q)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1461 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1462 int i, j, min, max, value, type, unknown_flag;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1463 GetBitContext gb;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1464
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1465 if (q->sub_packet_list_B[0].packet == NULL)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1466 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1467
6903
0f63fc62ea8b consistency cosmetics: indices --> indexes
diego
parents: 6712
diff changeset
1468 /* reset minimum indexes for FFT coefficients */
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1469 q->fft_coefs_index = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1470 for (i=0; i < 5; i++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1471 q->fft_coefs_min_index[i] = -1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1472
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1473 /* process subpackets ordered by type, largest type first */
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1474 for (i = 0, max = 256; i < q->sub_packets_B; i++) {
7306
7950572e58eb minor simplification of qdm2_decode_fft_packets()
michael
parents: 7129
diff changeset
1475 QDM2SubPacket *packet= NULL;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1476
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1477 /* find subpacket with largest type less than max */
7306
7950572e58eb minor simplification of qdm2_decode_fft_packets()
michael
parents: 7129
diff changeset
1478 for (j = 0, min = 0; j < q->sub_packets_B; j++) {
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1479 value = q->sub_packet_list_B[j].packet->type;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1480 if (value > min && value < max) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1481 min = value;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1482 packet = q->sub_packet_list_B[j].packet;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1483 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1484 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1485
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1486 max = min;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1487
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1488 /* check for errors (?) */
7323
5d6c51a125d0 Fix for possible null pointer dereferencing, closes Coverity report 68 run 2.
banan
parents: 7306
diff changeset
1489 if (!packet)
5d6c51a125d0 Fix for possible null pointer dereferencing, closes Coverity report 68 run 2.
banan
parents: 7306
diff changeset
1490 return;
5d6c51a125d0 Fix for possible null pointer dereferencing, closes Coverity report 68 run 2.
banan
parents: 7306
diff changeset
1491
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1492 if (i == 0 && (packet->type < 16 || packet->type >= 48 || fft_subpackets[packet->type - 16]))
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1493 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1494
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1495 /* decode FFT tones */
2916
767156b9aa0d init_get_bits() requires size in bits, not bytes
rtognimp
parents: 2914
diff changeset
1496 init_get_bits (&gb, packet->data, packet->size*8);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1497
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1498 if (packet->type >= 32 && packet->type < 48 && !fft_subpackets[packet->type - 16])
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1499 unknown_flag = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1500 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1501 unknown_flag = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1502
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1503 type = packet->type;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1504
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1505 if ((type >= 17 && type < 24) || (type >= 33 && type < 40)) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1506 int duration = q->sub_sampling + 5 - (type & 15);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1507
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1508 if (duration >= 0 && duration < 4)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1509 qdm2_fft_decode_tones(q, duration, &gb, unknown_flag);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1510 } else if (type == 31) {
3320
888e539459f4 10000l don't reuse outer loop index in inner loops
rtogni
parents: 3158
diff changeset
1511 for (j=0; j < 4; j++)
888e539459f4 10000l don't reuse outer loop index in inner loops
rtogni
parents: 3158
diff changeset
1512 qdm2_fft_decode_tones(q, j, &gb, unknown_flag);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1513 } else if (type == 46) {
3320
888e539459f4 10000l don't reuse outer loop index in inner loops
rtogni
parents: 3158
diff changeset
1514 for (j=0; j < 6; j++)
888e539459f4 10000l don't reuse outer loop index in inner loops
rtogni
parents: 3158
diff changeset
1515 q->fft_level_exp[j] = get_bits(&gb, 6);
888e539459f4 10000l don't reuse outer loop index in inner loops
rtogni
parents: 3158
diff changeset
1516 for (j=0; j < 4; j++)
888e539459f4 10000l don't reuse outer loop index in inner loops
rtogni
parents: 3158
diff changeset
1517 qdm2_fft_decode_tones(q, j, &gb, unknown_flag);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1518 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1519 } // Loop on B packets
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1520
6903
0f63fc62ea8b consistency cosmetics: indices --> indexes
diego
parents: 6712
diff changeset
1521 /* calculate maximum indexes for FFT coefficients */
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1522 for (i = 0, j = -1; i < 5; i++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1523 if (q->fft_coefs_min_index[i] >= 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1524 if (j >= 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1525 q->fft_coefs_max_index[j] = q->fft_coefs_min_index[i];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1526 j = i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1527 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1528 if (j >= 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1529 q->fft_coefs_max_index[j] = q->fft_coefs_index;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1530 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1531
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1532
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1533 static void qdm2_fft_generate_tone (QDM2Context *q, FFTTone *tone)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1534 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1535 float level, f[6];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1536 int i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1537 QDM2Complex c;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1538 const double iscale = 2.0*M_PI / 512.0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1539
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1540 tone->phase += tone->phase_shift;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1541
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1542 /* calculate current level (maximum amplitude) of tone */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1543 level = fft_tone_envelope_table[tone->duration][tone->time_index] * tone->level;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1544 c.im = level * sin(tone->phase*iscale);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1545 c.re = level * cos(tone->phase*iscale);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1546
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1547 /* generate FFT coefficients for tone */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1548 if (tone->duration >= 3 || tone->cutoff >= 3) {
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1549 tone->complex[0].im += c.im;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1550 tone->complex[0].re += c.re;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1551 tone->complex[1].im -= c.im;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1552 tone->complex[1].re -= c.re;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1553 } else {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1554 f[1] = -tone->table[4];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1555 f[0] = tone->table[3] - tone->table[0];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1556 f[2] = 1.0 - tone->table[2] - tone->table[3];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1557 f[3] = tone->table[1] + tone->table[4] - 1.0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1558 f[4] = tone->table[0] - tone->table[1];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1559 f[5] = tone->table[2];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1560 for (i = 0; i < 2; i++) {
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1561 tone->complex[fft_cutoff_index_table[tone->cutoff][i]].re += c.re * f[i];
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1562 tone->complex[fft_cutoff_index_table[tone->cutoff][i]].im += c.im *((tone->cutoff <= i) ? -f[i] : f[i]);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1563 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1564 for (i = 0; i < 4; i++) {
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1565 tone->complex[i].re += c.re * f[i+2];
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1566 tone->complex[i].im += c.im * f[i+2];
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1567 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1568 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1569
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1570 /* copy the tone if it has not yet died out */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1571 if (++tone->time_index < ((1 << (5 - tone->duration)) - 1)) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1572 memcpy(&q->fft_tones[q->fft_tone_end], tone, sizeof(FFTTone));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1573 q->fft_tone_end = (q->fft_tone_end + 1) % 1000;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1574 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1575 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1576
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1577
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1578 static void qdm2_fft_tone_synthesizer (QDM2Context *q, int sub_packet)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1579 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1580 int i, j, ch;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1581 const double iscale = 0.25 * M_PI;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1582
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1583 for (ch = 0; ch < q->channels; ch++) {
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1584 memset(q->fft.complex[ch], 0, q->fft_size * sizeof(QDM2Complex));
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1585 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1586
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1587
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1588 /* apply FFT tones with duration 4 (1 FFT period) */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1589 if (q->fft_coefs_min_index[4] >= 0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1590 for (i = q->fft_coefs_min_index[4]; i < q->fft_coefs_max_index[4]; i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1591 float level;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1592 QDM2Complex c;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1593
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1594 if (q->fft_coefs[i].sub_packet != sub_packet)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1595 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1596
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1597 ch = (q->channels == 1) ? 0 : q->fft_coefs[i].channel;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1598 level = (q->fft_coefs[i].exp < 0) ? 0.0 : fft_tone_level_table[q->superblocktype_2_3 ? 0 : 1][q->fft_coefs[i].exp & 63];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1599
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1600 c.re = level * cos(q->fft_coefs[i].phase * iscale);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1601 c.im = level * sin(q->fft_coefs[i].phase * iscale);
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1602 q->fft.complex[ch][q->fft_coefs[i].offset + 0].re += c.re;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1603 q->fft.complex[ch][q->fft_coefs[i].offset + 0].im += c.im;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1604 q->fft.complex[ch][q->fft_coefs[i].offset + 1].re -= c.re;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1605 q->fft.complex[ch][q->fft_coefs[i].offset + 1].im -= c.im;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1606 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1607
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1608 /* generate existing FFT tones */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1609 for (i = q->fft_tone_end; i != q->fft_tone_start; ) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1610 qdm2_fft_generate_tone(q, &q->fft_tones[q->fft_tone_start]);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1611 q->fft_tone_start = (q->fft_tone_start + 1) % 1000;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1612 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1613
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1614 /* create and generate new FFT tones with duration 0 (long) to 3 (short) */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1615 for (i = 0; i < 4; i++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1616 if (q->fft_coefs_min_index[i] >= 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1617 for (j = q->fft_coefs_min_index[i]; j < q->fft_coefs_max_index[i]; j++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1618 int offset, four_i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1619 FFTTone tone;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1620
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1621 if (q->fft_coefs[j].sub_packet != sub_packet)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1622 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1623
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1624 four_i = (4 - i);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1625 offset = q->fft_coefs[j].offset >> four_i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1626 ch = (q->channels == 1) ? 0 : q->fft_coefs[j].channel;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1627
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1628 if (offset < q->frequency_range) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1629 if (offset < 2)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1630 tone.cutoff = offset;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1631 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1632 tone.cutoff = (offset >= 60) ? 3 : 2;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1633
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1634 tone.level = (q->fft_coefs[j].exp < 0) ? 0.0 : fft_tone_level_table[q->superblocktype_2_3 ? 0 : 1][q->fft_coefs[j].exp & 63];
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1635 tone.complex = &q->fft.complex[ch][offset];
6273
michael
parents: 6122
diff changeset
1636 tone.table = fft_tone_sample_table[i][q->fft_coefs[j].offset - (offset << four_i)];
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1637 tone.phase = 64 * q->fft_coefs[j].phase - (offset << 8) - 128;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1638 tone.phase_shift = (2 * q->fft_coefs[j].offset + 1) << (7 - four_i);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1639 tone.duration = i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1640 tone.time_index = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1641
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1642 qdm2_fft_generate_tone(q, &tone);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1643 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1644 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1645 q->fft_coefs_min_index[i] = j;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1646 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1647 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1648
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1649
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1650 static void qdm2_calculate_fft (QDM2Context *q, int channel, int sub_packet)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1651 {
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1652 const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1653 int i;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1654 q->fft.complex[channel][0].re *= 2.0f;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1655 q->fft.complex[channel][0].im = 0.0f;
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1656 ff_rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1657 /* add samples to output buffer */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1658 for (i = 0; i < ((q->fft_frame_size + 15) & ~15); i++)
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1659 q->output_buffer[q->channels * i + channel] += ((float *) q->fft.complex[channel])[i] * gain;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1660 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1661
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1662
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1663 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1664 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1665 * @param index subpacket number
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1666 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1667 static void qdm2_synthesis_filter (QDM2Context *q, int index)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1668 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1669 OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1670 int i, k, ch, sb_used, sub_sampling, dither_state = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1671
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1672 /* copy sb_samples */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1673 sb_used = QDM2_SB_USED(q->sub_sampling);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1674
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1675 for (ch = 0; ch < q->channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1676 for (i = 0; i < 8; i++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1677 for (k=sb_used; k < SBLIMIT; k++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1678 q->sb_samples[ch][(8 * index) + i][k] = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1679
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1680 for (ch = 0; ch < q->nb_channels; ch++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1681 OUT_INT *samples_ptr = samples + ch;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1682
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1683 for (i = 0; i < 8; i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1684 ff_mpa_synth_filter(q->synth_buf[ch], &(q->synth_buf_offset[ch]),
10440
899237b1961f mpegaudiodec, mpc and qdm2 all use the same mpa_synth window, so make
reimar
parents: 9665
diff changeset
1685 ff_mpa_synth_window, &dither_state,
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1686 samples_ptr, q->nb_channels,
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1687 q->sb_samples[ch][(8 * index) + i]);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1688 samples_ptr += 32 * q->nb_channels;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1689 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1690 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1691
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1692 /* add samples to output buffer */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1693 sub_sampling = (4 >> q->sub_sampling);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1694
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1695 for (ch = 0; ch < q->channels; ch++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1696 for (i = 0; i < q->frame_size; i++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1697 q->output_buffer[q->channels * i + ch] += (float)(samples[q->nb_channels * sub_sampling * i + ch] >> (sizeof(OUT_INT)*8-16));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1698 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1699
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1700
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1701 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1702 * Init static data (does not depend on specific file)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1703 *
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1704 * @param q context
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1705 */
9007
043574c5c153 Add missing av_cold in static init/close functions.
stefano
parents: 8718
diff changeset
1706 static av_cold void qdm2_init(QDM2Context *q) {
6350
8e63d869a904 typo fix: inited --> initialized
diego
parents: 6273
diff changeset
1707 static int initialized = 0;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1708
6350
8e63d869a904 typo fix: inited --> initialized
diego
parents: 6273
diff changeset
1709 if (initialized != 0)
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1710 return;
6350
8e63d869a904 typo fix: inited --> initialized
diego
parents: 6273
diff changeset
1711 initialized = 1;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1712
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1713 qdm2_init_vlc();
10440
899237b1961f mpegaudiodec, mpc and qdm2 all use the same mpa_synth window, so make
reimar
parents: 9665
diff changeset
1714 ff_mpa_synth_init(ff_mpa_synth_window);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1715 softclip_table_init();
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1716 rnd_table_init();
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1717 init_noise_samples();
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1718
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1719 av_log(NULL, AV_LOG_DEBUG, "init done\n");
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1720 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1721
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1722
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1723 #if 0
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1724 static void dump_context(QDM2Context *q)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1725 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1726 int i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1727 #define PRINT(a,b) av_log(NULL,AV_LOG_DEBUG," %s = %d\n", a, b);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1728 PRINT("compressed_data",q->compressed_data);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1729 PRINT("compressed_size",q->compressed_size);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1730 PRINT("frame_size",q->frame_size);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1731 PRINT("checksum_size",q->checksum_size);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1732 PRINT("channels",q->channels);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1733 PRINT("nb_channels",q->nb_channels);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1734 PRINT("fft_frame_size",q->fft_frame_size);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1735 PRINT("fft_size",q->fft_size);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1736 PRINT("sub_sampling",q->sub_sampling);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1737 PRINT("fft_order",q->fft_order);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1738 PRINT("group_order",q->group_order);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1739 PRINT("group_size",q->group_size);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1740 PRINT("sub_packet",q->sub_packet);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1741 PRINT("frequency_range",q->frequency_range);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1742 PRINT("has_errors",q->has_errors);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1743 PRINT("fft_tone_end",q->fft_tone_end);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1744 PRINT("fft_tone_start",q->fft_tone_start);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1745 PRINT("fft_coefs_index",q->fft_coefs_index);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1746 PRINT("coeff_per_sb_select",q->coeff_per_sb_select);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1747 PRINT("cm_table_select",q->cm_table_select);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1748 PRINT("noise_idx",q->noise_idx);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1749
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1750 for (i = q->fft_tone_start; i < q->fft_tone_end; i++)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1751 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1752 FFTTone *t = &q->fft_tones[i];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1753
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1754 av_log(NULL,AV_LOG_DEBUG,"Tone (%d) dump:\n", i);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1755 av_log(NULL,AV_LOG_DEBUG," level = %f\n", t->level);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1756 // PRINT(" level", t->level);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1757 PRINT(" phase", t->phase);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1758 PRINT(" phase_shift", t->phase_shift);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1759 PRINT(" duration", t->duration);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1760 PRINT(" samples_im", t->samples_im);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1761 PRINT(" samples_re", t->samples_re);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1762 PRINT(" table", t->table);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1763 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1764
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1765 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1766 #endif
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1767
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1768
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1769 /**
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1770 * Init parameters from codec extradata
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1771 */
9007
043574c5c153 Add missing av_cold in static init/close functions.
stefano
parents: 8718
diff changeset
1772 static av_cold int qdm2_decode_init(AVCodecContext *avctx)
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1773 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1774 QDM2Context *s = avctx->priv_data;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1775 uint8_t *extradata;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1776 int extradata_size;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1777 int tmp_val, tmp, size;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1778
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1779 /* extradata parsing
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1780
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1781 Structure:
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1782 wave {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1783 frma (QDM2)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1784 QDCA
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1785 QDCP
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1786 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1787
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1788 32 size (including this field)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1789 32 tag (=frma)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1790 32 type (=QDM2 or QDMC)
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1791
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1792 32 size (including this field, in bytes)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1793 32 tag (=QDCA) // maybe mandatory parameters
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1794 32 unknown (=1)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1795 32 channels (=2)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1796 32 samplerate (=44100)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1797 32 bitrate (=96000)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1798 32 block size (=4096)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1799 32 frame size (=256) (for one channel)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1800 32 packet size (=1300)
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1801
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1802 32 size (including this field, in bytes)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1803 32 tag (=QDCP) // maybe some tuneable parameters
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1804 32 float1 (=1.0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1805 32 zero ?
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1806 32 float2 (=1.0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1807 32 float3 (=1.0)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1808 32 unknown (27)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1809 32 unknown (8)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1810 32 zero ?
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1811 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1812
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1813 if (!avctx->extradata || (avctx->extradata_size < 48)) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1814 av_log(avctx, AV_LOG_ERROR, "extradata missing or truncated\n");
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1815 return -1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1816 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1817
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1818 extradata = avctx->extradata;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1819 extradata_size = avctx->extradata_size;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1820
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1821 while (extradata_size > 7) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1822 if (!memcmp(extradata, "frmaQDM", 7))
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1823 break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1824 extradata++;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1825 extradata_size--;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1826 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1827
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1828 if (extradata_size < 12) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1829 av_log(avctx, AV_LOG_ERROR, "not enough extradata (%i)\n",
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1830 extradata_size);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1831 return -1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1832 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1833
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1834 if (memcmp(extradata, "frmaQDM", 7)) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1835 av_log(avctx, AV_LOG_ERROR, "invalid headers, QDM? not found\n");
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1836 return -1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1837 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1838
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1839 if (extradata[7] == 'C') {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1840 // s->is_qdmc = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1841 av_log(avctx, AV_LOG_ERROR, "stream is QDMC version 1, which is not supported\n");
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1842 return -1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1843 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1844
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1845 extradata += 8;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1846 extradata_size -= 8;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1847
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
1848 size = AV_RB32(extradata);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1849
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1850 if(size > extradata_size){
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1851 av_log(avctx, AV_LOG_ERROR, "extradata size too small, %i < %i\n",
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1852 extradata_size, size);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1853 return -1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1854 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1855
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1856 extradata += 4;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1857 av_log(avctx, AV_LOG_DEBUG, "size: %d\n", size);
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
1858 if (AV_RB32(extradata) != MKBETAG('Q','D','C','A')) {
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1859 av_log(avctx, AV_LOG_ERROR, "invalid extradata, expecting QDCA\n");
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1860 return -1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1861 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1862
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1863 extradata += 8;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1864
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
1865 avctx->channels = s->nb_channels = s->channels = AV_RB32(extradata);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1866 extradata += 4;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1867
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
1868 avctx->sample_rate = AV_RB32(extradata);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1869 extradata += 4;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1870
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
1871 avctx->bit_rate = AV_RB32(extradata);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1872 extradata += 4;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1873
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
1874 s->group_size = AV_RB32(extradata);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1875 extradata += 4;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1876
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
1877 s->fft_size = AV_RB32(extradata);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1878 extradata += 4;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1879
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
1880 s->checksum_size = AV_RB32(extradata);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1881
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1882 s->fft_order = av_log2(s->fft_size) + 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1883 s->fft_frame_size = 2 * s->fft_size; // complex has two floats
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1884
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1885 // something like max decodable tones
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1886 s->group_order = av_log2(s->group_size) + 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1887 s->frame_size = s->group_size / 16; // 16 iterations per super block
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1888
2954
43f14ef874de Support for samples with fft_order = 7
rtognimp
parents: 2953
diff changeset
1889 s->sub_sampling = s->fft_order - 7;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1890 s->frequency_range = 255 / (1 << (2 - s->sub_sampling));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1891
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1892 switch ((s->sub_sampling * 2 + s->channels - 1)) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1893 case 0: tmp = 40; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1894 case 1: tmp = 48; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1895 case 2: tmp = 56; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1896 case 3: tmp = 72; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1897 case 4: tmp = 80; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1898 case 5: tmp = 100;break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1899 default: tmp=s->sub_sampling; break;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1900 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1901 tmp_val = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1902 if ((tmp * 1000) < avctx->bit_rate) tmp_val = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1903 if ((tmp * 1440) < avctx->bit_rate) tmp_val = 2;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1904 if ((tmp * 1760) < avctx->bit_rate) tmp_val = 3;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1905 if ((tmp * 2240) < avctx->bit_rate) tmp_val = 4;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1906 s->cm_table_select = tmp_val;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1907
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1908 if (s->sub_sampling == 0)
2954
43f14ef874de Support for samples with fft_order = 7
rtognimp
parents: 2953
diff changeset
1909 tmp = 7999;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1910 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1911 tmp = ((-(s->sub_sampling -1)) & 8000) + 20000;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1912 /*
2954
43f14ef874de Support for samples with fft_order = 7
rtognimp
parents: 2953
diff changeset
1913 0: 7999 -> 0
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1914 1: 20000 -> 2
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1915 2: 28000 -> 2
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1916 */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1917 if (tmp < 8000)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1918 s->coeff_per_sb_select = 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1919 else if (tmp <= 16000)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1920 s->coeff_per_sb_select = 1;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1921 else
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1922 s->coeff_per_sb_select = 2;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1923
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1924 // Fail on unknown fft order
2954
43f14ef874de Support for samples with fft_order = 7
rtognimp
parents: 2953
diff changeset
1925 if ((s->fft_order < 7) || (s->fft_order > 9)) {
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1926 av_log(avctx, AV_LOG_ERROR, "Unknown FFT order (%d), contact the developers!\n", s->fft_order);
2954
43f14ef874de Support for samples with fft_order = 7
rtognimp
parents: 2953
diff changeset
1927 return -1;
43f14ef874de Support for samples with fft_order = 7
rtognimp
parents: 2953
diff changeset
1928 }
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1929
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1930 ff_rdft_init(&s->rdft_ctx, s->fft_order, IRDFT);
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1931
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1932 qdm2_init(s);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1933
7451
85ab7655ad4d Modify all codecs to report their supported input and output sample format(s).
pross
parents: 7326
diff changeset
1934 avctx->sample_fmt = SAMPLE_FMT_S16;
85ab7655ad4d Modify all codecs to report their supported input and output sample format(s).
pross
parents: 7326
diff changeset
1935
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1936 // dump_context(s);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1937 return 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1938 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1939
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1940
9007
043574c5c153 Add missing av_cold in static init/close functions.
stefano
parents: 8718
diff changeset
1941 static av_cold int qdm2_decode_close(AVCodecContext *avctx)
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1942 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1943 QDM2Context *s = avctx->priv_data;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1944
8695
d8a784fb1bbe Use the new RDFT code in the QDM2 decoder.
alexc
parents: 8592
diff changeset
1945 ff_rdft_end(&s->rdft_ctx);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1946
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1947 return 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1948 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1949
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1950
6273
michael
parents: 6122
diff changeset
1951 static void qdm2_decode (QDM2Context *q, const uint8_t *in, int16_t *out)
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1952 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1953 int ch, i;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1954 const int frame_size = (q->frame_size * q->channels);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2954
diff changeset
1955
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1956 /* select input buffer */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1957 q->compressed_data = in;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1958 q->compressed_size = q->checksum_size;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1959
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1960 // dump_context(q);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1961
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1962 /* copy old block, clear new block of output samples */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1963 memmove(q->output_buffer, &q->output_buffer[frame_size], frame_size * sizeof(float));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1964 memset(&q->output_buffer[frame_size], 0, frame_size * sizeof(float));
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1965
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1966 /* decode block of QDM2 compressed data */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1967 if (q->sub_packet == 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1968 q->has_errors = 0; // zero it for a new super block
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1969 av_log(NULL,AV_LOG_DEBUG,"Superblock follows\n");
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1970 qdm2_decode_super_block(q);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1971 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1972
3043
583020ce54a8 Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
diego
parents: 3036
diff changeset
1973 /* parse subpackets */
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1974 if (!q->has_errors) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1975 if (q->sub_packet == 2)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1976 qdm2_decode_fft_packets(q);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1977
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1978 qdm2_fft_tone_synthesizer(q, q->sub_packet);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1979 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1980
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1981 /* sound synthesis stage 1 (FFT) */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1982 for (ch = 0; ch < q->channels; ch++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1983 qdm2_calculate_fft(q, ch, q->sub_packet);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1984
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1985 if (!q->has_errors && q->sub_packet_list_C[0].packet != NULL) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1986 SAMPLES_NEEDED_2("has errors, and C list is not empty")
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1987 return;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1988 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1989 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1990
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1991 /* sound synthesis stage 2 (MPEG audio like synthesis filter) */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1992 if (!q->has_errors && q->do_synth_filter)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1993 qdm2_synthesis_filter(q, q->sub_packet);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1994
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1995 q->sub_packet = (q->sub_packet + 1) % 16;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1996
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1997 /* clip and convert output float[] to 16bit signed samples */
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1998 for (i = 0; i < frame_size; i++) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
1999 int value = (int)q->output_buffer[i];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2000
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2001 if (value > SOFTCLIP_THRESHOLD)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2002 value = (value > HARDCLIP_THRESHOLD) ? 32767 : softclip_table[ value - SOFTCLIP_THRESHOLD];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2003 else if (value < -SOFTCLIP_THRESHOLD)
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2004 value = (value < -HARDCLIP_THRESHOLD) ? -32767 : -softclip_table[-value - SOFTCLIP_THRESHOLD];
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2005
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2006 out[i] = value;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2007 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2008 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2009
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2010
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2011 static int qdm2_decode_frame(AVCodecContext *avctx,
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2012 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 9007
diff changeset
2013 AVPacket *avpkt)
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2014 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 9007
diff changeset
2015 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 9007
diff changeset
2016 int buf_size = avpkt->size;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2017 QDM2Context *s = avctx->priv_data;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2018
3158
5b2a0e54dfa7 fix infinite loop
michael
parents: 3076
diff changeset
2019 if(!buf)
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2020 return 0;
3158
5b2a0e54dfa7 fix infinite loop
michael
parents: 3076
diff changeset
2021 if(buf_size < s->checksum_size)
5b2a0e54dfa7 fix infinite loop
michael
parents: 3076
diff changeset
2022 return -1;
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2023
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2024 *data_size = s->channels * s->frame_size * sizeof(int16_t);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2025
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2026 av_log(avctx, AV_LOG_DEBUG, "decode(%d): %p[%d] -> %p[%d]\n",
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2027 buf_size, buf, s->checksum_size, data, *data_size);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2028
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2029 qdm2_decode(s, buf, data);
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2030
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2031 // reading only when next superblock found
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2032 if (s->sub_packet == 0) {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2033 return s->checksum_size;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2034 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2035
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2036 return 0;
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2037 }
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2038
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2039 AVCodec qdm2_decoder =
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2040 {
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2041 .name = "qdm2",
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2042 .type = CODEC_TYPE_AUDIO,
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2043 .id = CODEC_ID_QDM2,
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2044 .priv_data_size = sizeof(QDM2Context),
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2045 .init = qdm2_decode_init,
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2046 .close = qdm2_decode_close,
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2047 .decode = qdm2_decode_frame,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6903
diff changeset
2048 .long_name = NULL_IF_CONFIG_SMALL("QDesign Music Codec 2"),
2914
4a52affac0e0 QDM2 compatible decoder
rtognimp
parents:
diff changeset
2049 };