Mercurial > libavcodec.hg
comparison qdm2.c @ 3043:583020ce54a8 libavcodec
Fix a bunch of spelling/grammar mistakes in doxygen comments and output.
author | diego |
---|---|
date | Sat, 14 Jan 2006 15:00:10 +0000 |
parents | 0b546eab515d |
children | 50d80b04f150 |
comparison
equal
deleted
inserted
replaced
3042:a434a3752e78 | 3043:583020ce54a8 |
---|---|
23 | 23 |
24 /** | 24 /** |
25 * @file qdm2.c | 25 * @file qdm2.c |
26 * QDM2 decoder | 26 * QDM2 decoder |
27 * @author Ewald Snel, Benjamin Larsson, Alex Beregszaszi, Roberto Togni | 27 * @author Ewald Snel, Benjamin Larsson, Alex Beregszaszi, Roberto Togni |
28 * The decoder is not perfect yet, there are still some distorions expecially | 28 * The decoder is not perfect yet, there are still some distortions |
29 * on files encoded with 16 or 8 subbands | 29 * especially on files encoded with 16 or 8 subbands. |
30 */ | 30 */ |
31 | 31 |
32 #include <math.h> | 32 #include <math.h> |
33 #include <stddef.h> | 33 #include <stddef.h> |
34 #include <stdio.h> | 34 #include <stdio.h> |
92 unsigned int size; ///< subpacket size | 92 unsigned int size; ///< subpacket size |
93 const uint8_t *data; ///< pointer to subpacket data (points to input data buffer, it's not a private copy) | 93 const uint8_t *data; ///< pointer to subpacket data (points to input data buffer, it's not a private copy) |
94 } QDM2SubPacket; | 94 } QDM2SubPacket; |
95 | 95 |
96 /** | 96 /** |
97 * A node in subpacket list | 97 * A node in the subpacket list |
98 */ | 98 */ |
99 typedef struct _QDM2SubPNode { | 99 typedef struct _QDM2SubPNode { |
100 QDM2SubPacket *packet; ///< packet | 100 QDM2SubPacket *packet; ///< packet |
101 struct _QDM2SubPNode *next; ///< pointer to next packet in the list, NULL if leaf node | 101 struct _QDM2SubPNode *next; ///< pointer to next packet in the list, NULL if leaf node |
102 } QDM2SubPNode; | 102 } QDM2SubPNode; |
194 int8_t tone_level_idx_hi2[MPA_MAX_CHANNELS][26]; | 194 int8_t tone_level_idx_hi2[MPA_MAX_CHANNELS][26]; |
195 int8_t tone_level_idx[MPA_MAX_CHANNELS][30][64]; | 195 int8_t tone_level_idx[MPA_MAX_CHANNELS][30][64]; |
196 int8_t tone_level_idx_temp[MPA_MAX_CHANNELS][30][64]; | 196 int8_t tone_level_idx_temp[MPA_MAX_CHANNELS][30][64]; |
197 | 197 |
198 // Flags | 198 // Flags |
199 int has_errors; ///< packet have errors | 199 int has_errors; ///< packet has errors |
200 int superblocktype_2_3; ///< select fft tables and some algorithm based on superblock type | 200 int superblocktype_2_3; ///< select fft tables and some algorithm based on superblock type |
201 int do_synth_filter; ///< used to perform or skip synthesis filter | 201 int do_synth_filter; ///< used to perform or skip synthesis filter |
202 | 202 |
203 int sub_packet; | 203 int sub_packet; |
204 int noise_idx; ///< Index for dithering noise table | 204 int noise_idx; ///< index for dithering noise table |
205 } QDM2Context; | 205 } QDM2Context; |
206 | 206 |
207 | 207 |
208 static uint8_t empty_buffer[FF_INPUT_BUFFER_PADDING_SIZE]; | 208 static uint8_t empty_buffer[FF_INPUT_BUFFER_PADDING_SIZE]; |
209 | 209 |
399 * | 399 * |
400 * @param data pointer to data to be checksum'ed | 400 * @param data pointer to data to be checksum'ed |
401 * @param length data length | 401 * @param length data length |
402 * @param value checksum value | 402 * @param value checksum value |
403 * | 403 * |
404 * @return 0 if checksum is ok | 404 * @return 0 if checksum is OK |
405 */ | 405 */ |
406 static uint16_t qdm2_packet_checksum (uint8_t *data, int length, int value) { | 406 static uint16_t qdm2_packet_checksum (uint8_t *data, int length, int value) { |
407 int i; | 407 int i; |
408 | 408 |
409 for (i=0; i < length; i++) | 409 for (i=0; i < length; i++) |
412 return (uint16_t)(value & 0xffff); | 412 return (uint16_t)(value & 0xffff); |
413 } | 413 } |
414 | 414 |
415 | 415 |
416 /** | 416 /** |
417 * Fills a QDM2SubPacket structure with packet type, size, and data pointer | 417 * Fills a QDM2SubPacket structure with packet type, size, and data pointer. |
418 * | 418 * |
419 * @param gb bitreader context | 419 * @param gb bitreader context |
420 * @param sub_packet packet under analysis | 420 * @param sub_packet packet under analysis |
421 */ | 421 */ |
422 static void qdm2_decode_sub_packet_header (GetBitContext *gb, QDM2SubPacket *sub_packet) | 422 static void qdm2_decode_sub_packet_header (GetBitContext *gb, QDM2SubPacket *sub_packet) |
439 sub_packet->type |= (get_bits (gb, 8) << 8); | 439 sub_packet->type |= (get_bits (gb, 8) << 8); |
440 | 440 |
441 sub_packet->data = &gb->buffer[get_bits_count(gb) / 8]; // FIXME: this depends on bitreader internal data | 441 sub_packet->data = &gb->buffer[get_bits_count(gb) / 8]; // FIXME: this depends on bitreader internal data |
442 } | 442 } |
443 | 443 |
444 av_log(NULL,AV_LOG_DEBUG,"Sub packet: type=%d size=%d start_offs=%x\n", | 444 av_log(NULL,AV_LOG_DEBUG,"Subpacket: type=%d size=%d start_offs=%x\n", |
445 sub_packet->type, sub_packet->size, get_bits_count(gb) / 8); | 445 sub_packet->type, sub_packet->size, get_bits_count(gb) / 8); |
446 } | 446 } |
447 | 447 |
448 | 448 |
449 /** | 449 /** |
450 * Return node pointer to first packet of requested type in list | 450 * Return node pointer to first packet of requested type in list. |
451 * | 451 * |
452 * @param list list of subpacket to be scanned | 452 * @param list list of subpackets to be scanned |
453 * @param type type of searched subpacket | 453 * @param type type of searched subpacket |
454 * @return node pointer for subpacket if found, else NULL | 454 * @return node pointer for subpacket if found, else NULL |
455 */ | 455 */ |
456 static QDM2SubPNode* qdm2_search_subpacket_type_in_list (QDM2SubPNode *list, int type) | 456 static QDM2SubPNode* qdm2_search_subpacket_type_in_list (QDM2SubPNode *list, int type) |
457 { | 457 { |
463 return NULL; | 463 return NULL; |
464 } | 464 } |
465 | 465 |
466 | 466 |
467 /** | 467 /** |
468 * Replaces 8 elements with their average value | 468 * Replaces 8 elements with their average value. |
469 * Called by qdm2_decode_superblock before starting subblocks decoding | 469 * Called by qdm2_decode_superblock before starting subblock decoding. |
470 * | 470 * |
471 * @param q context | 471 * @param q context |
472 */ | 472 */ |
473 static void average_quantized_coeffs (QDM2Context *q) | 473 static void average_quantized_coeffs (QDM2Context *q) |
474 { | 474 { |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
495 | 495 |
496 /** | 496 /** |
497 * Build subband samples with noise weighted by q->tone_level | 497 * Build subband samples with noise weighted by q->tone_level. |
498 * Called by synthfilt_build_sb_samples | 498 * Called by synthfilt_build_sb_samples. |
499 * | 499 * |
500 * @param q context | 500 * @param q context |
501 * @param sb subband index | 501 * @param sb subband index |
502 */ | 502 */ |
503 static void build_sb_samples_from_noise (QDM2Context *q, int sb) | 503 static void build_sb_samples_from_noise (QDM2Context *q, int sb) |
516 } | 516 } |
517 } | 517 } |
518 | 518 |
519 | 519 |
520 /** | 520 /** |
521 * Called while processing data from subpackets 11 and 12 | 521 * Called while processing data from subpackets 11 and 12. |
522 * Used after making changes to coding_method array | 522 * Used after making changes to coding_method array. |
523 * | 523 * |
524 * @param sb subband index | 524 * @param sb subband index |
525 * @param channels number of channels | 525 * @param channels number of channels |
526 * @param coding_method q->coding_method[0][0][0] | 526 * @param coding_method q->coding_method[0][0][0] |
527 */ | 527 */ |
788 * Called by process_subpacket_11 to process more data from subpacket 11 with sb 0-8 | 788 * Called by process_subpacket_11 to process more data from subpacket 11 with sb 0-8 |
789 * Called by process_subpacket_12 to process data from subpacket 12 with sb 8-sb_used | 789 * Called by process_subpacket_12 to process data from subpacket 12 with sb 8-sb_used |
790 * | 790 * |
791 * @param q context | 791 * @param q context |
792 * @param gb bitreader context | 792 * @param gb bitreader context |
793 * @param length packet length in bit | 793 * @param length packet length in bits |
794 * @param sb_min lower subband processed (sb_min included) | 794 * @param sb_min lower subband processed (sb_min included) |
795 * @param sb_max higher subband processed (sb_max excluded) | 795 * @param sb_max higher subband processed (sb_max excluded) |
796 */ | 796 */ |
797 static void synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int length, int sb_min, int sb_max) | 797 static void synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int length, int sb_min, int sb_max) |
798 { | 798 { |
966 } // subband loop | 966 } // subband loop |
967 } | 967 } |
968 | 968 |
969 | 969 |
970 /** | 970 /** |
971 * Init the first element of a channel in quantized_coeffs with data from packet 10 (quantized_coeffs[ch][0]) | 971 * Init the first element of a channel in quantized_coeffs with data from packet 10 (quantized_coeffs[ch][0]). |
972 * This is similar to process_subpacket_9, but for a single channel and for element [0] | 972 * This is similar to process_subpacket_9, but for a single channel and for element [0] |
973 * same VLC tables as process_subpacket_9 are used | 973 * same VLC tables as process_subpacket_9 are used. |
974 * | 974 * |
975 * @param q context | 975 * @param q context |
976 * @param quantized_coeffs pointer to quantized_coeffs[ch][0] | 976 * @param quantized_coeffs pointer to quantized_coeffs[ch][0] |
977 * @param gb bitreader context | 977 * @param gb bitreader context |
978 * @param length packet length in bit | 978 * @param length packet length in bits |
979 */ | 979 */ |
980 static void init_quantized_coeffs_elem0 (int8_t *quantized_coeffs, GetBitContext *gb, int length) | 980 static void init_quantized_coeffs_elem0 (int8_t *quantized_coeffs, GetBitContext *gb, int length) |
981 { | 981 { |
982 int i, k, run, level, diff; | 982 int i, k, run, level, diff; |
983 | 983 |
1010 * Init part of quantized_coeffs via function init_quantized_coeffs_elem0 | 1010 * Init part of quantized_coeffs via function init_quantized_coeffs_elem0 |
1011 * Init tone_level_idx_hi1, tone_level_idx_hi2, tone_level_idx_mid with data from packet 10 | 1011 * Init tone_level_idx_hi1, tone_level_idx_hi2, tone_level_idx_mid with data from packet 10 |
1012 * | 1012 * |
1013 * @param q context | 1013 * @param q context |
1014 * @param gb bitreader context | 1014 * @param gb bitreader context |
1015 * @param length packet length in bit | 1015 * @param length packet length in bits |
1016 */ | 1016 */ |
1017 static void init_tone_level_dequantization (QDM2Context *q, GetBitContext *gb, int length) | 1017 static void init_tone_level_dequantization (QDM2Context *q, GetBitContext *gb, int length) |
1018 { | 1018 { |
1019 int sb, j, k, n, ch; | 1019 int sb, j, k, n, ch; |
1020 | 1020 |
1112 /** | 1112 /** |
1113 * Process subpacket 10 if not null, else | 1113 * Process subpacket 10 if not null, else |
1114 * | 1114 * |
1115 * @param q context | 1115 * @param q context |
1116 * @param node pointer to node with packet | 1116 * @param node pointer to node with packet |
1117 * @param length packet length in bit | 1117 * @param length packet length in bits |
1118 */ | 1118 */ |
1119 static void process_subpacket_10 (QDM2Context *q, QDM2SubPNode *node, int length) | 1119 static void process_subpacket_10 (QDM2Context *q, QDM2SubPNode *node, int length) |
1120 { | 1120 { |
1121 GetBitContext gb; | 1121 GetBitContext gb; |
1122 | 1122 |
1158 /** | 1158 /** |
1159 * Process subpacket 12 | 1159 * Process subpacket 12 |
1160 * | 1160 * |
1161 * @param q context | 1161 * @param q context |
1162 * @param node pointer to node with packet | 1162 * @param node pointer to node with packet |
1163 * @param length packet length in bit | 1163 * @param length packet length in bits |
1164 */ | 1164 */ |
1165 static void process_subpacket_12 (QDM2Context *q, QDM2SubPNode *node, int length) | 1165 static void process_subpacket_12 (QDM2Context *q, QDM2SubPNode *node, int length) |
1166 { | 1166 { |
1167 GetBitContext gb; | 1167 GetBitContext gb; |
1168 | 1168 |
1203 process_subpacket_12(q, NULL, 0); | 1203 process_subpacket_12(q, NULL, 0); |
1204 } | 1204 } |
1205 | 1205 |
1206 | 1206 |
1207 /* | 1207 /* |
1208 * Decode superblock, fill packet lists | 1208 * Decode superblock, fill packet lists. |
1209 * | 1209 * |
1210 * @param q context | 1210 * @param q context |
1211 */ | 1211 */ |
1212 static void qdm2_decode_super_block (QDM2Context *q) | 1212 static void qdm2_decode_super_block (QDM2Context *q) |
1213 { | 1213 { |
1272 | 1272 |
1273 if (next_index >= header.size) | 1273 if (next_index >= header.size) |
1274 break; | 1274 break; |
1275 } | 1275 } |
1276 | 1276 |
1277 /* decode sub packet */ | 1277 /* decode subpacket */ |
1278 packet = &q->sub_packets[i]; | 1278 packet = &q->sub_packets[i]; |
1279 qdm2_decode_sub_packet_header(&gb, packet); | 1279 qdm2_decode_sub_packet_header(&gb, packet); |
1280 next_index = packet->size + get_bits_count(&gb) / 8; | 1280 next_index = packet->size + get_bits_count(&gb) / 8; |
1281 sub_packet_size = ((packet->size > 0xff) ? 1 : 0) + packet->size + 2; | 1281 sub_packet_size = ((packet->size > 0xff) ? 1 : 0) + packet->size + 2; |
1282 | 1282 |
1289 packet->size += packet_bytes - sub_packet_size; | 1289 packet->size += packet_bytes - sub_packet_size; |
1290 } | 1290 } |
1291 | 1291 |
1292 packet_bytes -= sub_packet_size; | 1292 packet_bytes -= sub_packet_size; |
1293 | 1293 |
1294 /* add sub packet to 'all sub packets' list */ | 1294 /* add subpacket to 'all subpackets' list */ |
1295 q->sub_packet_list_A[i].packet = packet; | 1295 q->sub_packet_list_A[i].packet = packet; |
1296 | 1296 |
1297 /* add sub packet to related list */ | 1297 /* add subpacket to related list */ |
1298 if (packet->type == 8) { | 1298 if (packet->type == 8) { |
1299 SAMPLES_NEEDED_2("packet type 8"); | 1299 SAMPLES_NEEDED_2("packet type 8"); |
1300 return; | 1300 return; |
1301 } else if (packet->type >= 9 && packet->type <= 12) { | 1301 } else if (packet->type >= 9 && packet->type <= 12) { |
1302 /* packets for MPEG Audio like Synthesis Filter */ | 1302 /* packets for MPEG Audio like Synthesis Filter */ |
1433 /* reset minimum indices for FFT coefficients */ | 1433 /* reset minimum indices for FFT coefficients */ |
1434 q->fft_coefs_index = 0; | 1434 q->fft_coefs_index = 0; |
1435 for (i=0; i < 5; i++) | 1435 for (i=0; i < 5; i++) |
1436 q->fft_coefs_min_index[i] = -1; | 1436 q->fft_coefs_min_index[i] = -1; |
1437 | 1437 |
1438 /* process sub packets ordered by type, largest type first */ | 1438 /* process subpackets ordered by type, largest type first */ |
1439 for (i = 0, max = 256; i < q->sub_packets_B; i++) { | 1439 for (i = 0, max = 256; i < q->sub_packets_B; i++) { |
1440 QDM2SubPacket *packet; | 1440 QDM2SubPacket *packet; |
1441 | 1441 |
1442 /* find sub packet with largest type less than max */ | 1442 /* find subpacket with largest type less than max */ |
1443 for (j = 0, min = 0, packet = NULL; j < q->sub_packets_B; j++) { | 1443 for (j = 0, min = 0, packet = NULL; j < q->sub_packets_B; j++) { |
1444 value = q->sub_packet_list_B[j].packet->type; | 1444 value = q->sub_packet_list_B[j].packet->type; |
1445 if (value > min && value < max) { | 1445 if (value > min && value < max) { |
1446 min = value; | 1446 min = value; |
1447 packet = q->sub_packet_list_B[j].packet; | 1447 packet = q->sub_packet_list_B[j].packet; |
1617 const int n2 = n >> 1; | 1617 const int n2 = n >> 1; |
1618 const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.25f : 0.50f; | 1618 const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.25f : 0.50f; |
1619 float c, s, f0, f1, f2, f3; | 1619 float c, s, f0, f1, f2, f3; |
1620 int i, j; | 1620 int i, j; |
1621 | 1621 |
1622 /* pre rotation (or something like that) */ | 1622 /* prerotation (or something like that) */ |
1623 for (i=1; i < n2; i++) { | 1623 for (i=1; i < n2; i++) { |
1624 j = (n - i); | 1624 j = (n - i); |
1625 c = q->exptab[i].re; | 1625 c = q->exptab[i].re; |
1626 s = -q->exptab[i].im; | 1626 s = -q->exptab[i].im; |
1627 f0 = (q->fft.samples_re[channel][i] - q->fft.samples_re[channel][j]) * gain; | 1627 f0 = (q->fft.samples_re[channel][i] - q->fft.samples_re[channel][j]) * gain; |
1958 memset(&q->output_buffer[frame_size], 0, frame_size * sizeof(float)); | 1958 memset(&q->output_buffer[frame_size], 0, frame_size * sizeof(float)); |
1959 | 1959 |
1960 /* decode block of QDM2 compressed data */ | 1960 /* decode block of QDM2 compressed data */ |
1961 if (q->sub_packet == 0) { | 1961 if (q->sub_packet == 0) { |
1962 q->has_errors = 0; // zero it for a new super block | 1962 q->has_errors = 0; // zero it for a new super block |
1963 av_log(NULL,AV_LOG_DEBUG,"Super block follows\n"); | 1963 av_log(NULL,AV_LOG_DEBUG,"Superblock follows\n"); |
1964 qdm2_decode_super_block(q); | 1964 qdm2_decode_super_block(q); |
1965 } | 1965 } |
1966 | 1966 |
1967 /* parse sub packets */ | 1967 /* parse subpackets */ |
1968 if (!q->has_errors) { | 1968 if (!q->has_errors) { |
1969 if (q->sub_packet == 2) | 1969 if (q->sub_packet == 2) |
1970 qdm2_decode_fft_packets(q); | 1970 qdm2_decode_fft_packets(q); |
1971 | 1971 |
1972 qdm2_fft_tone_synthesizer(q, q->sub_packet); | 1972 qdm2_fft_tone_synthesizer(q, q->sub_packet); |