]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/qdm2.c
x86: ff_get_cpu_flags_x86(): Avoid a pointless variable indirection
[ffmpeg] / libavcodec / qdm2.c
index 358d0e1cc707475c2d5936c48be2c7ac856f937a..4d3b3915fbd2a3157d0b86b7515a14cd02492980 100644 (file)
@@ -140,7 +140,6 @@ typedef struct {
     /// Parameters built from header parameters, do not change during playback
     int group_order;         ///< order of frame group
     int fft_order;           ///< order of FFT (actually fftorder+1)
-    int fft_frame_size;      ///< size of fft frame, in components (1 comples = re + im)
     int frame_size;          ///< size of data frame
     int frequency_range;
     int sub_sampling;        ///< subsampling: 0=25%, 1=50%, 2=100% */
@@ -200,8 +199,6 @@ typedef struct {
 } QDM2Context;
 
 
-static uint8_t empty_buffer[FF_INPUT_BUFFER_PADDING_SIZE];
-
 static VLC vlc_tab_level;
 static VLC vlc_tab_diff;
 static VLC vlc_tab_run;
@@ -501,7 +498,7 @@ static void fix_coding_method_array (int sb, int channels, sb_int8_array coding_
     int j,k;
     int ch;
     int run, case_val;
-    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 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; ) {
@@ -882,9 +879,13 @@ static void synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int l
                         break;
 
                     case 30:
-                        if (get_bits_left(gb) >= 4)
-                            samples[0] = type30_dequant[qdm2_get_vlc(gb, &vlc_tab_type30, 0, 1)];
-                        else
+                        if (get_bits_left(gb) >= 4) {
+                            unsigned index = qdm2_get_vlc(gb, &vlc_tab_type30, 0, 1);
+                            if (index < FF_ARRAY_ELEMS(type30_dequant)) {
+                                samples[0] = type30_dequant[index];
+                            } else
+                                samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
+                        } else
                             samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
 
                         run = 1;
@@ -898,8 +899,12 @@ static void synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int l
                                 type34_predictor = samples[0];
                                 type34_first = 0;
                             } else {
-                                samples[0] = type34_delta[qdm2_get_vlc(gb, &vlc_tab_type34, 0, 1)] / type34_div + type34_predictor;
-                                type34_predictor = samples[0];
+                                unsigned index = qdm2_get_vlc(gb, &vlc_tab_type34, 0, 1);
+                                if (index < FF_ARRAY_ELEMS(type34_delta)) {
+                                    samples[0] = type34_delta[index] / type34_div + type34_predictor;
+                                    type34_predictor = samples[0];
+                                } else
+                                    samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
                             }
                         } else {
                             samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
@@ -1081,15 +1086,13 @@ static void process_subpacket_9 (QDM2Context *q, QDM2SubPNode *node)
  *
  * @param q         context
  * @param node      pointer to node with packet
- * @param length    packet length in bits
  */
-static void process_subpacket_10 (QDM2Context *q, QDM2SubPNode *node, int length)
+static void process_subpacket_10 (QDM2Context *q, QDM2SubPNode *node)
 {
     GetBitContext gb;
 
-    init_get_bits(&gb, ((node == NULL) ? empty_buffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size*8));
-
-    if (length != 0) {
+    if (node) {
+        init_get_bits(&gb, node->packet->data, node->packet->size * 8);
         init_tone_level_dequantization(q, &gb);
         fill_tone_level_array(q, 1);
     } else {
@@ -1103,13 +1106,17 @@ static void process_subpacket_10 (QDM2Context *q, QDM2SubPNode *node, int length
  *
  * @param q         context
  * @param node      pointer to node with packet
- * @param length    packet length in bit
  */
-static void process_subpacket_11 (QDM2Context *q, QDM2SubPNode *node, int length)
+static void process_subpacket_11 (QDM2Context *q, QDM2SubPNode *node)
 {
     GetBitContext gb;
+    int length = 0;
+
+    if (node) {
+        length = node->packet->size * 8;
+        init_get_bits(&gb, node->packet->data, length);
+    }
 
-    init_get_bits(&gb, ((node == NULL) ? empty_buffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size*8));
     if (length >= 32) {
         int c = get_bits (&gb, 13);
 
@@ -1127,13 +1134,17 @@ static void process_subpacket_11 (QDM2Context *q, QDM2SubPNode *node, int length
  *
  * @param q         context
  * @param node      pointer to node with packet
- * @param length    packet length in bits
  */
-static void process_subpacket_12 (QDM2Context *q, QDM2SubPNode *node, int length)
+static void process_subpacket_12 (QDM2Context *q, QDM2SubPNode *node)
 {
     GetBitContext gb;
+    int length = 0;
+
+    if (node) {
+        length = node->packet->size * 8;
+        init_get_bits(&gb, node->packet->data, length);
+    }
 
-    init_get_bits(&gb, ((node == NULL) ? empty_buffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size*8));
     synthfilt_build_sb_samples(q, &gb, length, 8, QDM2_SB_USED(q->sub_sampling));
 }
 
@@ -1153,21 +1164,21 @@ static void process_synthesis_subpackets (QDM2Context *q, QDM2SubPNode *list)
 
     nodes[1] = qdm2_search_subpacket_type_in_list(list, 10);
     if (nodes[1] != NULL)
-        process_subpacket_10(q, nodes[1], nodes[1]->packet->size << 3);
+        process_subpacket_10(q, nodes[1]);
     else
-        process_subpacket_10(q, NULL, 0);
+        process_subpacket_10(q, NULL);
 
     nodes[2] = qdm2_search_subpacket_type_in_list(list, 11);
     if (nodes[0] != NULL && nodes[1] != NULL && nodes[2] != NULL)
-        process_subpacket_11(q, nodes[2], (nodes[2]->packet->size << 3));
+        process_subpacket_11(q, nodes[2]);
     else
-        process_subpacket_11(q, NULL, 0);
+        process_subpacket_11(q, NULL);
 
     nodes[3] = qdm2_search_subpacket_type_in_list(list, 12);
     if (nodes[0] != NULL && nodes[1] != NULL && nodes[3] != NULL)
-        process_subpacket_12(q, nodes[3], (nodes[3]->packet->size << 3));
+        process_subpacket_12(q, nodes[3]);
     else
-        process_subpacket_12(q, NULL, 0);
+        process_subpacket_12(q, NULL);
 }
 
 
@@ -1289,9 +1300,9 @@ static void qdm2_decode_super_block (QDM2Context *q)
         process_synthesis_subpackets(q, q->sub_packet_list_D);
         q->do_synth_filter = 1;
     } else if (q->do_synth_filter) {
-        process_subpacket_10(q, NULL, 0);
-        process_subpacket_11(q, NULL, 0);
-        process_subpacket_12(q, NULL, 0);
+        process_subpacket_10(q, NULL);
+        process_subpacket_11(q, NULL);
+        process_subpacket_12(q, NULL);
     }
 /* **************************************************************** */
 }
@@ -1585,13 +1596,17 @@ 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;
+    float *out = q->output_buffer + channel;
     int i;
     q->fft.complex[channel][0].re *= 2.0f;
     q->fft.complex[channel][0].im = 0.0f;
     q->rdft_ctx.rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]);
     /* add samples to output buffer */
-    for (i = 0; i < ((q->fft_frame_size + 15) & ~15); i++)
-        q->output_buffer[q->channels * i + channel] += ((float *) q->fft.complex[channel])[i] * gain;
+    for (i = 0; i < FFALIGN(q->fft_size, 8); i++) {
+        out[0]           += q->fft.complex[channel][i].re * gain;
+        out[q->channels] += q->fft.complex[channel][i].im * gain;
+        out += 2 * q->channels;
+    }
 }
 
 
@@ -1655,52 +1670,6 @@ static av_cold void qdm2_init(QDM2Context *q) {
 }
 
 
-#if 0
-static void dump_context(QDM2Context *q)
-{
-    int i;
-#define PRINT(a,b) av_log(NULL,AV_LOG_DEBUG," %s = %d\n", a, b);
-    PRINT("compressed_data",q->compressed_data);
-    PRINT("compressed_size",q->compressed_size);
-    PRINT("frame_size",q->frame_size);
-    PRINT("checksum_size",q->checksum_size);
-    PRINT("channels",q->channels);
-    PRINT("nb_channels",q->nb_channels);
-    PRINT("fft_frame_size",q->fft_frame_size);
-    PRINT("fft_size",q->fft_size);
-    PRINT("sub_sampling",q->sub_sampling);
-    PRINT("fft_order",q->fft_order);
-    PRINT("group_order",q->group_order);
-    PRINT("group_size",q->group_size);
-    PRINT("sub_packet",q->sub_packet);
-    PRINT("frequency_range",q->frequency_range);
-    PRINT("has_errors",q->has_errors);
-    PRINT("fft_tone_end",q->fft_tone_end);
-    PRINT("fft_tone_start",q->fft_tone_start);
-    PRINT("fft_coefs_index",q->fft_coefs_index);
-    PRINT("coeff_per_sb_select",q->coeff_per_sb_select);
-    PRINT("cm_table_select",q->cm_table_select);
-    PRINT("noise_idx",q->noise_idx);
-
-    for (i = q->fft_tone_start; i < q->fft_tone_end; i++)
-    {
-    FFTTone *t = &q->fft_tones[i];
-
-    av_log(NULL,AV_LOG_DEBUG,"Tone (%d) dump:\n", i);
-    av_log(NULL,AV_LOG_DEBUG,"  level = %f\n", t->level);
-//  PRINT(" level", t->level);
-    PRINT(" phase", t->phase);
-    PRINT(" phase_shift", t->phase_shift);
-    PRINT(" duration", t->duration);
-    PRINT(" samples_im", t->samples_im);
-    PRINT(" samples_re", t->samples_re);
-    PRINT(" table", t->table);
-    }
-
-}
-#endif
-
-
 /**
  * Init parameters from codec extradata
  */
@@ -1821,7 +1790,6 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
     }
 
     s->fft_order = av_log2(s->fft_size) + 1;
-    s->fft_frame_size = 2 * s->fft_size; // complex has two floats
 
     // something like max decodable tones
     s->group_order = av_log2(s->group_size) + 1;
@@ -1880,7 +1848,6 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
     avcodec_get_frame_defaults(&s->frame);
     avctx->coded_frame = &s->frame;
 
-//    dump_context(s);
     return 0;
 }
 
@@ -1904,8 +1871,6 @@ static int qdm2_decode (QDM2Context *q, const uint8_t *in, int16_t *out)
     q->compressed_data = in;
     q->compressed_size = q->checksum_size;
 
-//  dump_context(q);
-
     /* copy old block, clear new block of output samples */
     memmove(q->output_buffer, &q->output_buffer[frame_size], frame_size * sizeof(float));
     memset(&q->output_buffer[frame_size], 0, frame_size * sizeof(float));
@@ -1995,7 +1960,7 @@ AVCodec ff_qdm2_decoder =
 {
     .name           = "qdm2",
     .type           = AVMEDIA_TYPE_AUDIO,
-    .id             = CODEC_ID_QDM2,
+    .id             = AV_CODEC_ID_QDM2,
     .priv_data_size = sizeof(QDM2Context),
     .init           = qdm2_decode_init,
     .close          = qdm2_decode_close,