annotate src/ffmpeg/libavcodec/qdm2.c @ 808:e8776388b02a trunk

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