Convert filters to lopsub.
[paraslash.git] / wmadec_filter.c
index c1f0c302960999704658c89560c1d1d7631808e4..18997aec47ea67ba0740e7d7dd844c48f9e5db22 100644 (file)
@@ -24,7 +24,6 @@
 #include "para.h"
 #include "error.h"
 #include "list.h"
-#include "ggo.h"
 #include "string.h"
 #include "sched.h"
 #include "buffer_tree.h"
@@ -88,8 +87,8 @@ struct private_wmadec_data {
        int frame_len_bits;
        /** Number of block sizes, one if !ahi->use_variable_block_len. */
        int nb_block_sizes;
-       /* block info */
-       int reset_block_lengths;
+       /* Whether to update block lengths from getbit context. */
+       bool reset_block_lengths;
        /** log2 of current block length. */
        int block_len_bits;
        /** log2 of next block length. */
@@ -371,8 +370,8 @@ static int wma_init(struct private_wmadec_data *pwd)
                else
                        high_freq = high_freq * 0.5;
        }
-       PARA_INFO_LOG("channels=%d sample_rate=%d "
-               "bitrate=%d block_align=%d\n",
+       PARA_INFO_LOG("channels=%u sample_rate=%u "
+               "bitrate=%u block_align=%d\n",
                ahi->channels, ahi->sample_rate,
                ahi->bit_rate, ahi->block_align);
        PARA_INFO_LOG("frame_len=%d, bps=%f bps1=%f "
@@ -391,7 +390,7 @@ static int wma_init(struct private_wmadec_data *pwd)
                pwd->windows[i] = sine_windows[pwd->frame_len_bits - i - 7];
        }
 
-       pwd->reset_block_lengths = 1;
+       pwd->reset_block_lengths = true;
 
        if (pwd->use_noise_coding) {
                /* init the noise generator */
@@ -429,13 +428,13 @@ static int wma_init(struct private_wmadec_data *pwd)
        return 0;
 }
 
-static void wma_lsp_to_curve_init(struct private_wmadec_data *pwd, int frame_len)
+static void wma_lsp_to_curve_init(struct private_wmadec_data *pwd)
 {
        float wdel, a, b;
        int i, e, m;
 
-       wdel = M_PI / frame_len;
-       for (i = 0; i < frame_len; i++)
+       wdel = M_PI / pwd->frame_len;
+       for (i = 0; i < pwd->frame_len; i++)
                pwd->lsp_cos_table[i] = 2.0f * cos(wdel * i);
 
        /* tables for x^-0.25 computation */
@@ -491,7 +490,7 @@ static int wma_decode_init(char *initial_buf, int len, struct private_wmadec_dat
                        wma_scale_huffbits, wma_scale_huffcodes, 4);
        } else {
                PARA_INFO_LOG("using curve\n");
-               wma_lsp_to_curve_init(pwd, pwd->frame_len);
+               wma_lsp_to_curve_init(pwd);
        }
        *result = pwd;
        return pwd->ahi.header_len;
@@ -810,7 +809,7 @@ static void compute_mdct_coefficients(struct private_wmadec_data *pwd,
                }
                /* very high freqs: noise */
                n = pwd->block_len - pwd->coefs_end[bsize];
-               mult1 = mult * exponents[((-1 << bsize)) >> esize];
+               mult1 = mult * exponents[(-(1 << bsize)) >> esize];
                for (i = 0; i < n; i++) {
                        *coefs++ = pwd->noise_table[pwd->noise_index] * mult1;
                        pwd->noise_index = (pwd->noise_index + 1)
@@ -834,7 +833,7 @@ static int wma_decode_block(struct private_wmadec_data *pwd)
                n = wma_log2(pwd->nb_block_sizes - 1) + 1;
 
                if (pwd->reset_block_lengths) {
-                       pwd->reset_block_lengths = 0;
+                       pwd->reset_block_lengths = false;
                        v = get_bits(&pwd->gb, n);
                        if (v >= pwd->nb_block_sizes)
                                return -E_WMA_BLOCK_SIZE;
@@ -1028,7 +1027,7 @@ static inline int16_t av_clip_int16(int a)
 /* Decode a frame of frame_len samples. */
 static int wma_decode_frame(struct private_wmadec_data *pwd, int16_t *samples)
 {
-       int ret, i, n, ch, incr;
+       int ret, i, ch;
        int16_t *ptr;
        float *iptr;
 
@@ -1043,15 +1042,13 @@ static int wma_decode_frame(struct private_wmadec_data *pwd, int16_t *samples)
        }
 
        /* convert frame to integer */
-       n = pwd->frame_len;
-       incr = pwd->ahi.channels;
        for (ch = 0; ch < pwd->ahi.channels; ch++) {
                ptr = samples + ch;
                iptr = pwd->frame_out[ch];
 
-               for (i = 0; i < n; i++) {
+               for (i = 0; i < pwd->frame_len; i++) {
                        *ptr = av_clip_int16(lrintf(*iptr++));
-                       ptr += incr;
+                       ptr += pwd->ahi.channels;
                }
                /* prepare for next block */
                memmove(&pwd->frame_out[ch][0], &pwd->frame_out[ch][pwd->frame_len],
@@ -1068,10 +1065,13 @@ static int wma_decode_superframe(struct private_wmadec_data *pwd, void *data,
 
        if (buf_size == 0) {
                pwd->last_superframe_len = 0;
+               *data_size = 0;
                return 0;
        }
-       if (buf_size < pwd->ahi.block_align)
+       if (buf_size < pwd->ahi.block_align) {
+               *data_size = 0;
                return 0;
+       }
        buf_size = pwd->ahi.block_align;
        samples = data;
        init_get_bits(&pwd->gb, buf, buf_size);
@@ -1129,7 +1129,7 @@ static int wma_decode_superframe(struct private_wmadec_data *pwd, void *data,
                if (len > 0)
                        skip_bits(&pwd->gb, len);
 
-               pwd->reset_block_lengths = 1;
+               pwd->reset_block_lengths = true;
                for (i = 0; i < nb_frames; i++) {
                        ret = wma_decode_frame(pwd, samples);
                        if (ret < 0)
@@ -1209,7 +1209,7 @@ next_buffer:
        if (ret == 0)
                return 0;
        btr_merge(btrn, fn->min_iqs);
-       len = btr_next_buffer(btrn, (char **)&in);
+       len = btr_next_buffer(btrn, &in);
        ret = -E_WMADEC_EOF;
        if (len < fn->min_iqs)
                goto err;
@@ -1221,12 +1221,12 @@ next_buffer:
                        fn->min_iqs += 4096;
                        goto next_buffer;
                }
-               fn->min_iqs = 2 * (WMA_FRAME_SKIP + pwd->ahi.block_align);
+               fn->min_iqs = 2 * pwd->ahi.packet_size;
                fn->private_data = pwd;
                converted = pwd->ahi.header_len;
                goto success;
        }
-       fn->min_iqs = WMA_FRAME_SKIP + pwd->ahi.block_align;
+       fn->min_iqs = pwd->ahi.packet_size;
        if (fn->min_iqs > len)
                goto success;
        out_size = WMA_OUTPUT_BUFFER_SIZE;
@@ -1237,10 +1237,12 @@ next_buffer:
                free(out);
                goto err;
        }
-       out = para_realloc(out, out_size);
-       if (out_size > 0)
+       if (out_size > 0) {
+               out = para_realloc(out, out_size);
                btr_add_output(out, out_size, btrn);
-       converted += ret + WMA_FRAME_SKIP;
+       } else
+               free(out);
+       converted += pwd->ahi.packet_size;
 success:
        btr_consume(btrn, converted);
        return 0;
@@ -1256,16 +1258,10 @@ static void wmadec_open(struct filter_node *fn)
        fn->min_iqs = 4096;
 }
 
-/**
- * The init function of the wma decoder.
- *
- * \param f Its fields are filled in by the function.
- */
-void wmadec_filter_init(struct filter *f)
-{
-       f->open = wmadec_open;
-       f->close = wmadec_close;
-       f->execute = wmadec_execute;
-       f->pre_select = generic_filter_pre_select;
-       f->post_select = wmadec_post_select;
-}
+const struct filter lsg_filter_cmd_com_wmadec_user_data = {
+       .open = wmadec_open,
+       .close = wmadec_close,
+       .execute = wmadec_execute,
+       .pre_select = generic_filter_pre_select,
+       .post_select = wmadec_post_select,
+};