qdm2: formatting cosmetics

Apply the usual style plus drop few unnecessary return at the end
of void functions.
This commit is contained in:
Luca Barbato 2013-06-27 02:49:15 +02:00
parent f054e309c5
commit 76efedeadb
1 changed files with 204 additions and 187 deletions

View File

@ -216,6 +216,10 @@ static const uint16_t qdm2_vlc_offs[] = {
0,260,566,598,894,1166,1230,1294,1678,1950,2214,2278,2310,2570,2834,3124,3448,3838,
};
static const 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
};
static av_cold void qdm2_init_vlc(void)
{
static VLC_TYPE qdm2_table[3838][2];
@ -381,7 +385,6 @@ static int qdm2_get_vlc (GetBitContext *gb, VLC *vlc, int flag, int depth)
return value;
}
static int qdm2_get_se_vlc(VLC *vlc, GetBitContext *gb, int depth)
{
int value = qdm2_get_vlc(gb, vlc, 0, depth);
@ -389,7 +392,6 @@ static int qdm2_get_se_vlc (VLC *vlc, GetBitContext *gb, int depth)
return (value & 1) ? ((value + 1) >> 1) : -(value >> 1);
}
/**
* QDM2 checksum
*
@ -399,7 +401,8 @@ static int qdm2_get_se_vlc (VLC *vlc, GetBitContext *gb, int depth)
*
* @return 0 if checksum is OK
*/
static uint16_t qdm2_packet_checksum (const uint8_t *data, int length, int value) {
static uint16_t qdm2_packet_checksum(const uint8_t *data, int length, int value)
{
int i;
for (i = 0; i < length; i++)
@ -408,14 +411,14 @@ static uint16_t qdm2_packet_checksum (const uint8_t *data, int length, int value
return (uint16_t)(value & 0xffff);
}
/**
* Fill a QDM2SubPacket structure with packet type, size, and data pointer.
*
* @param gb bitreader context
* @param sub_packet packet under analysis
*/
static void qdm2_decode_sub_packet_header (GetBitContext *gb, QDM2SubPacket *sub_packet)
static void qdm2_decode_sub_packet_header(GetBitContext *gb,
QDM2SubPacket *sub_packet)
{
sub_packet->type = get_bits(gb, 8);
@ -434,14 +437,14 @@ static void qdm2_decode_sub_packet_header (GetBitContext *gb, QDM2SubPacket *sub
if (sub_packet->type == 0x7f)
sub_packet->type |= (get_bits(gb, 8) << 8);
sub_packet->data = &gb->buffer[get_bits_count(gb) / 8]; // FIXME: this depends on bitreader internal data
// FIXME: this depends on bitreader-internal data
sub_packet->data = &gb->buffer[get_bits_count(gb) / 8];
}
av_log(NULL, AV_LOG_DEBUG, "Subpacket: type=%d size=%d start_offs=%x\n",
sub_packet->type, sub_packet->size, get_bits_count(gb) / 8);
}
/**
* Return node pointer to first packet of requested type in list.
*
@ -449,7 +452,8 @@ static void qdm2_decode_sub_packet_header (GetBitContext *gb, QDM2SubPacket *sub
* @param type type of searched subpacket
* @return node pointer for subpacket if found, else NULL
*/
static QDM2SubPNode* qdm2_search_subpacket_type_in_list (QDM2SubPNode *list, int type)
static QDM2SubPNode *qdm2_search_subpacket_type_in_list(QDM2SubPNode *list,
int type)
{
while (list != NULL && list->packet != NULL) {
if (list->packet->type == type)
@ -459,7 +463,6 @@ static QDM2SubPNode* qdm2_search_subpacket_type_in_list (QDM2SubPNode *list, int
return NULL;
}
/**
* Replace 8 elements with their average value.
* Called by qdm2_decode_superblock before starting subblock decoding.
@ -488,7 +491,6 @@ static void average_quantized_coeffs (QDM2Context *q)
}
}
/**
* Build subband samples with noise weighted by q->tone_level.
* Called by synthfilt_build_sb_samples.
@ -505,13 +507,15 @@ static void build_sb_samples_from_noise (QDM2Context *q, int sb)
if (!q->nb_channels)
return;
for (ch = 0; ch < q->nb_channels; ch++)
for (ch = 0; ch < q->nb_channels; ch++) {
for (j = 0; j < 64; j++) {
q->sb_samples[ch][j * 2][sb] = SB_DITHERING_NOISE(sb,q->noise_idx) * q->tone_level[ch][sb][j];
q->sb_samples[ch][j * 2 + 1][sb] = SB_DITHERING_NOISE(sb,q->noise_idx) * q->tone_level[ch][sb][j];
q->sb_samples[ch][j * 2][sb] =
SB_DITHERING_NOISE(sb, q->noise_idx) * q->tone_level[ch][sb][j];
q->sb_samples[ch][j * 2 + 1][sb] =
SB_DITHERING_NOISE(sb, q->noise_idx) * q->tone_level[ch][sb][j];
}
}
}
/**
* Called while processing data from subpackets 11 and 12.
@ -521,12 +525,12 @@ static void build_sb_samples_from_noise (QDM2Context *q, int sb)
* @param channels number of channels
* @param coding_method q->coding_method[0][0][0]
*/
static void fix_coding_method_array (int sb, int channels, sb_int8_array coding_method)
static void fix_coding_method_array(int sb, int channels,
sb_int8_array coding_method)
{
int j, k;
int ch;
int run, case_val;
static const 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};
for (ch = 0; ch < channels; ch++) {
for (j = 0; j < 64; ) {
@ -535,30 +539,48 @@ static void fix_coding_method_array (int sb, int channels, sb_int8_array coding_
case_val = 8;
} else {
switch (switchtable[coding_method[ch][sb][j] - 8]) {
case 0: run = 10; case_val = 10; break;
case 1: run = 1; case_val = 16; break;
case 2: run = 5; case_val = 24; break;
case 3: run = 3; case_val = 30; break;
case 4: run = 1; case_val = 30; break;
case 5: run = 1; case_val = 8; break;
default: run = 1; case_val = 8; break;
case 0: run = 10;
case_val = 10;
break;
case 1: run = 1;
case_val = 16;
break;
case 2: run = 5;
case_val = 24;
break;
case 3: run = 3;
case_val = 30;
break;
case 4: run = 1;
case_val = 30;
break;
case 5: run = 1;
case_val = 8;
break;
default: run = 1;
case_val = 8;
break;
}
}
for (k = 0; k < run; k++)
if (j + k < 128)
if (coding_method[ch][sb + (j + k) / 64][(j + k) % 64] > coding_method[ch][sb][j])
for (k = 0; k < run; k++) {
if (j + k < 128) {
if (coding_method[ch][sb + (j + k) / 64][(j + k) % 64] > coding_method[ch][sb][j]) {
if (k > 0) {
SAMPLES_NEEDED
//not debugged, almost never used
memset(&coding_method[ch][sb][j + k], case_val, k * sizeof(int8_t));
memset(&coding_method[ch][sb][j + k], case_val, 3 * sizeof(int8_t));
memset(&coding_method[ch][sb][j + k], case_val,
k *sizeof(int8_t));
memset(&coding_method[ch][sb][j + k], case_val,
3 * sizeof(int8_t));
}
}
}
}
j += run;
}
}
}
/**
* Related to synthesis filter
* Called by process_subpacket_10
@ -638,16 +660,14 @@ static void fill_tone_level_array (QDM2Context *q, int flag)
}
}
}
return;
}
/**
* Related to synthesis filter
* Called by process_subpacket_11
* c is built with data from subpacket 11
* Most of this function is used only if superblock_type_2_3 == 0, never seen it in samples
* Most of this function is used only if superblock_type_2_3 == 0,
* never seen it in samples.
*
* @param tone_level_idx
* @param tone_level_idx_temp
@ -657,9 +677,12 @@ static void fill_tone_level_array (QDM2Context *q, int flag)
* @param superblocktype_2_3 flag based on superblock packet type
* @param cm_table_select q->cm_table_select
*/
static void fill_coding_method_array (sb_int8_array tone_level_idx, sb_int8_array tone_level_idx_temp,
sb_int8_array coding_method, int nb_channels,
int c, int superblocktype_2_3, int cm_table_select)
static void fill_coding_method_array(sb_int8_array tone_level_idx,
sb_int8_array tone_level_idx_temp,
sb_int8_array coding_method,
int nb_channels,
int c, int superblocktype_2_3,
int cm_table_select)
{
int ch, sb, j;
int tmp, acc, esp_40, comp;
@ -765,15 +788,14 @@ static void fill_coding_method_array (sb_int8_array tone_level_idx, sb_int8_arra
for (j = 0; j < 64; j++)
coding_method[ch][sb][j] = coding_method_table[cm_table_select][sb];
}
return;
}
/**
*
* Called by process_subpacket_11 to process more data from subpacket 11 with sb 0-8
* Called by process_subpacket_12 to process data from subpacket 12 with sb 8-sb_used
* Called by process_subpacket_11 to process more data from subpacket 11
* with sb 0-8.
* Called by process_subpacket_12 to process data from subpacket 12 with
* sb 8-sb_used.
*
* @param q context
* @param gb bitreader context
@ -781,7 +803,8 @@ static void fill_coding_method_array (sb_int8_array tone_level_idx, sb_int8_arra
* @param sb_min lower subband processed (sb_min included)
* @param sb_max higher subband processed (sb_max excluded)
*/
static void synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int length, int sb_min, int sb_max)
static void synthfilt_build_sb_samples(QDM2Context *q, GetBitContext *gb,
int length, int sb_min, int sb_max)
{
int sb, j, k, n, ch, run, channels;
int joined_stereo, zero_encoding, chs;
@ -961,16 +984,18 @@ static void synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int l
} // subband loop
}
/**
* Init the first element of a channel in quantized_coeffs with data from packet 10 (quantized_coeffs[ch][0]).
* This is similar to process_subpacket_9, but for a single channel and for element [0]
* Init the first element of a channel in quantized_coeffs with data
* from packet 10 (quantized_coeffs[ch][0]).
* This is similar to process_subpacket_9, but for a single channel
* and for element [0]
* same VLC tables as process_subpacket_9 are used.
*
* @param quantized_coeffs pointer to quantized_coeffs[ch][0]
* @param gb bitreader context
*/
static void init_quantized_coeffs_elem0 (int8_t *quantized_coeffs, GetBitContext *gb)
static void init_quantized_coeffs_elem0(int8_t *quantized_coeffs,
GetBitContext *gb)
{
int i, k, run, level, diff;
@ -997,11 +1022,11 @@ static void init_quantized_coeffs_elem0 (int8_t *quantized_coeffs, GetBitContext
}
}
/**
* Related to synthesis filter, process data from packet 10
* Init part of quantized_coeffs via function init_quantized_coeffs_elem0
* Init tone_level_idx_hi1, tone_level_idx_hi2, tone_level_idx_mid with data from packet 10
* Init tone_level_idx_hi1, tone_level_idx_hi2, tone_level_idx_mid with
* data from packet 10
*
* @param q context
* @param gb bitreader context
@ -1076,7 +1101,7 @@ static void process_subpacket_9 (QDM2Context *q, QDM2SubPNode *node)
init_get_bits(&gb, node->packet->data, node->packet->size * 8);
n = coeff_per_sb_for_avg[q->coeff_per_sb_select][QDM2_SB_USED(q->sub_sampling) - 1] + 1; // same as averagesomething function
n = coeff_per_sb_for_avg[q->coeff_per_sb_select][QDM2_SB_USED(q->sub_sampling) - 1] + 1;
for (i = 1; i < n; i++)
for (ch = 0; ch < q->nb_channels; ch++) {
@ -1100,7 +1125,6 @@ static void process_subpacket_9 (QDM2Context *q, QDM2SubPNode *node)
q->quantized_coeffs[ch][0][i] = 0;
}
/**
* Process subpacket 10 if not null, else
*
@ -1120,7 +1144,6 @@ static void process_subpacket_10 (QDM2Context *q, QDM2SubPNode *node)
}
}
/**
* Process subpacket 11
*
@ -1141,14 +1164,15 @@ static void process_subpacket_11 (QDM2Context *q, QDM2SubPNode *node)
int c = get_bits(&gb, 13);
if (c > 3)
fill_coding_method_array (q->tone_level_idx, q->tone_level_idx_temp, q->coding_method,
q->nb_channels, 8*c, q->superblocktype_2_3, q->cm_table_select);
fill_coding_method_array(q->tone_level_idx,
q->tone_level_idx_temp, q->coding_method,
q->nb_channels, 8 * c,
q->superblocktype_2_3, q->cm_table_select);
}
synthfilt_build_sb_samples(q, &gb, length, 0, 8);
}
/**
* Process subpacket 12
*
@ -1201,7 +1225,6 @@ static void process_synthesis_subpackets (QDM2Context *q, QDM2SubPNode *list)
process_subpacket_12(q, NULL);
}
/*
* Decode superblock, fill packet lists.
*
@ -1314,13 +1337,13 @@ static void qdm2_decode_super_block (QDM2Context *q)
} else if (packet->type == 15) {
SAMPLES_NEEDED_2("packet type 15")
return;
} else if (packet->type >= 16 && packet->type < 48 && !fft_subpackets[packet->type - 16]) {
} else if (packet->type >= 16 && packet->type < 48 &&
!fft_subpackets[packet->type - 16]) {
/* packets for FFT */
QDM2_LIST_ADD(q->sub_packet_list_B, q->sub_packets_B, packet);
}
} // Packet bytes loop
/* **************************************************************** */
if (q->sub_packet_list_D[0].packet != NULL) {
process_synthesis_subpackets(q, q->sub_packet_list_D);
q->do_synth_filter = 1;
@ -1329,10 +1352,8 @@ static void qdm2_decode_super_block (QDM2Context *q)
process_subpacket_11(q, NULL);
process_subpacket_12(q, NULL);
}
/* **************************************************************** */
}
static void qdm2_fft_init_coefficient(QDM2Context *q, int sub_packet,
int offset, int duration, int channel,
int exp, int phase)
@ -1340,7 +1361,8 @@ static void qdm2_fft_init_coefficient (QDM2Context *q, int sub_packet,
if (q->fft_coefs_min_index[duration] < 0)
q->fft_coefs_min_index[duration] = q->fft_coefs_index;
q->fft_coefs[q->fft_coefs_index].sub_packet = ((sub_packet >= 16) ? (sub_packet - 16) : sub_packet);
q->fft_coefs[q->fft_coefs_index].sub_packet =
((sub_packet >= 16) ? (sub_packet - 16) : sub_packet);
q->fft_coefs[q->fft_coefs_index].channel = channel;
q->fft_coefs[q->fft_coefs_index].offset = offset;
q->fft_coefs[q->fft_coefs_index].exp = exp;
@ -1348,8 +1370,8 @@ static void qdm2_fft_init_coefficient (QDM2Context *q, int sub_packet,
q->fft_coefs_index++;
}
static void qdm2_fft_decode_tones (QDM2Context *q, int duration, GetBitContext *gb, int b)
static void qdm2_fft_decode_tones(QDM2Context *q, int duration,
GetBitContext *gb, int b)
{
int channel, stereo, phase, exp;
int local_int_4, local_int_8, stereo_phase, local_int_10;
@ -1418,16 +1440,17 @@ static void qdm2_fft_decode_tones (QDM2Context *q, int duration, GetBitContext *
if (q->frequency_range > (local_int_14 + 1)) {
int sub_packet = (local_int_20 + local_int_28);
qdm2_fft_init_coefficient(q, sub_packet, offset, duration, channel, exp, phase);
qdm2_fft_init_coefficient(q, sub_packet, offset, duration,
channel, exp, phase);
if (stereo)
qdm2_fft_init_coefficient(q, sub_packet, offset, duration, (1 - channel), stereo_exp, stereo_phase);
qdm2_fft_init_coefficient(q, sub_packet, offset, duration,
1 - channel,
stereo_exp, stereo_phase);
}
offset++;
}
}
static void qdm2_decode_fft_packets(QDM2Context *q)
{
int i, j, min, max, value, type, unknown_flag;
@ -1460,7 +1483,9 @@ static void qdm2_decode_fft_packets (QDM2Context *q)
if (!packet)
return;
if (i == 0 && (packet->type < 16 || packet->type >= 48 || fft_subpackets[packet->type - 16]))
if (i == 0 &&
(packet->type < 16 || packet->type >= 48 ||
fft_subpackets[packet->type - 16]))
return;
/* decode FFT tones */
@ -1500,7 +1525,6 @@ static void qdm2_decode_fft_packets (QDM2Context *q)
q->fft_coefs_max_index[j] = q->fft_coefs_index;
}
static void qdm2_fft_generate_tone(QDM2Context *q, FFTTone *tone)
{
float level, f[6];
@ -1529,8 +1553,10 @@ static void qdm2_fft_generate_tone (QDM2Context *q, FFTTone *tone)
f[4] = tone->table[0] - tone->table[1];
f[5] = tone->table[2];
for (i = 0; i < 2; i++) {
tone->complex[fft_cutoff_index_table[tone->cutoff][i]].re += c.re * f[i];
tone->complex[fft_cutoff_index_table[tone->cutoff][i]].im += c.im *((tone->cutoff <= i) ? -f[i] : f[i]);
tone->complex[fft_cutoff_index_table[tone->cutoff][i]].re +=
c.re * f[i];
tone->complex[fft_cutoff_index_table[tone->cutoff][i]].im +=
c.im * ((tone->cutoff <= i) ? -f[i] : f[i]);
}
for (i = 0; i < 4; i++) {
tone->complex[i].re += c.re * f[i + 2];
@ -1545,7 +1571,6 @@ static void qdm2_fft_generate_tone (QDM2Context *q, FFTTone *tone)
}
}
static void qdm2_fft_tone_synthesizer(QDM2Context *q, int sub_packet)
{
int i, j, ch;
@ -1617,7 +1642,6 @@ static void qdm2_fft_tone_synthesizer (QDM2Context *q, int sub_packet)
}
}
static void qdm2_calculate_fft(QDM2Context *q, int channel, int sub_packet)
{
const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f;
@ -1634,7 +1658,6 @@ static void qdm2_calculate_fft (QDM2Context *q, int channel, int sub_packet)
}
}
/**
* @param q context
* @param index subpacket number
@ -1672,7 +1695,6 @@ static void qdm2_synthesis_filter (QDM2Context *q, int index)
q->output_buffer[q->channels * i + ch] += (1 << 23) * q->samples[q->nb_channels * sub_sampling * i + ch];
}
/**
* Init static data (does not depend on specific file)
*
@ -1686,7 +1708,6 @@ static av_cold void qdm2_init_static_data(AVCodec *codec) {
init_noise_samples();
}
/**
* Init parameters from codec extradata
*/
@ -1869,7 +1890,6 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
return 0;
}
static av_cold int qdm2_decode_close(AVCodecContext *avctx)
{
QDM2Context *s = avctx->priv_data;
@ -1879,7 +1899,6 @@ static av_cold int qdm2_decode_close(AVCodecContext *avctx)
return 0;
}
static int qdm2_decode(QDM2Context *q, const uint8_t *in, int16_t *out)
{
int ch, i;
@ -1939,7 +1958,6 @@ static int qdm2_decode (QDM2Context *q, const uint8_t *in, int16_t *out)
return 0;
}
static int qdm2_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{
@ -1974,8 +1992,7 @@ static int qdm2_decode_frame(AVCodecContext *avctx, void *data,
return s->checksum_size;
}
AVCodec ff_qdm2_decoder =
{
AVCodec ff_qdm2_decoder = {
.name = "qdm2",
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_QDM2,