X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=wmadec_filter.c;h=0dff2b7914a0e1f1e18afc412bbd331bfe32f648;hp=8b751f04592eff0f7d6b3e5fe73ade1938c17382;hb=0b6e7a20c19d642f9d8e65683e1525c91dd3de39;hpb=2f07d34b5d4c37606be5849b6ee51e0443707898;ds=sidebyside diff --git a/wmadec_filter.c b/wmadec_filter.c index 8b751f04..0dff2b79 100644 --- a/wmadec_filter.c +++ b/wmadec_filter.c @@ -17,11 +17,7 @@ #define _XOPEN_SOURCE 600 -#include -#include -#include #include -#include #include #include @@ -62,17 +58,11 @@ struct private_wmadec_data { /** Information contained in the audio file header. */ struct asf_header_info ahi; struct getbit_context gb; - /** Whether to use the bit reservoir. */ - int use_bit_reservoir; - /** Whether to use variable block length. */ - int use_variable_block_len; - /** Whether to use exponent coding. */ - int use_exp_vlc; /** Whether perceptual noise is added. */ int use_noise_coding; /** Depends on number of the bits per second and the frame length. */ int byte_offset_bits; - /** Only used if use_exp_vlc is true. */ + /** Only used if ahi->use_exp_vlc is true. */ struct vlc exp_vlc; uint16_t exponent_bands[BLOCK_NB_SIZES][25]; /** The index of the first coef in high band. */ @@ -96,10 +86,10 @@ struct private_wmadec_data { int frame_len; /** log2 of frame_len. */ int frame_len_bits; - /** Number of block sizes. */ + /** 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. */ @@ -141,13 +131,10 @@ struct private_wmadec_data { }; #define EXPVLCBITS 8 -#define EXPMAX DIV_ROUND_UP(19, EXPVLCBITS) - #define HGAINVLCBITS 9 -#define HGAINMAX DIV_ROUND_UP(13, HGAINVLCBITS) - #define VLCBITS 9 -#define VLCMAX DIV_ROUND_UP(22, VLCBITS) + +/** \cond sine_winows */ #define SINE_WINDOW(x) static float sine_ ## x[x] __a_aligned(16) @@ -161,6 +148,7 @@ SINE_WINDOW(4096); static float *sine_windows[6] = { sine_128, sine_256, sine_512, sine_1024, sine_2048, sine_4096 }; +/** \endcond sine_windows */ /* Generate a sine window. */ static void sine_window_init(float *window, int n) @@ -177,7 +165,7 @@ static void wmadec_cleanup(struct private_wmadec_data *pwd) for (i = 0; i < pwd->nb_block_sizes; i++) imdct_end(pwd->mdct_ctx[i]); - if (pwd->use_exp_vlc) + if (pwd->ahi.use_exp_vlc) free_vlc(&pwd->exp_vlc); if (pwd->use_noise_coding) free_vlc(&pwd->hgain_vlc); @@ -311,7 +299,7 @@ static int wma_init(struct private_wmadec_data *pwd) else pwd->frame_len_bits = 11; pwd->frame_len = 1 << pwd->frame_len_bits; - if (pwd->use_variable_block_len) { + if (pwd->ahi.use_variable_block_len) { int nb_max, nb; nb = ((flags2 >> 3) & 3) + 1; if ((ahi->bit_rate / ahi->channels) >= 32000) @@ -392,7 +380,7 @@ static int wma_init(struct private_wmadec_data *pwd) pwd->frame_len, bps, bps1, high_freq, pwd->byte_offset_bits); PARA_INFO_LOG("use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n", - pwd->use_noise_coding, pwd->use_exp_vlc, pwd->nb_block_sizes); + pwd->use_noise_coding, pwd->ahi.use_exp_vlc, pwd->nb_block_sizes); compute_scale_factor_band_sizes(pwd, high_freq); /* init MDCT windows : simple sinus window */ @@ -403,11 +391,11 @@ 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 */ - if (pwd->use_exp_vlc) + if (pwd->ahi.use_exp_vlc) pwd->noise_mult = 0.02; else pwd->noise_mult = 0.04; @@ -441,13 +429,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 */ @@ -481,10 +469,6 @@ static int wma_decode_init(char *initial_buf, int len, struct private_wmadec_dat return ret; } - pwd->use_exp_vlc = pwd->ahi.flags2 & 0x0001; - pwd->use_bit_reservoir = pwd->ahi.flags2 & 0x0002; - pwd->use_variable_block_len = pwd->ahi.flags2 & 0x0004; - ret = wma_init(pwd); if (ret < 0) return ret; @@ -501,13 +485,13 @@ static int wma_decode_init(char *initial_buf, int len, struct private_wmadec_dat wma_hgain_huffcodes, 2); } - if (pwd->use_exp_vlc) { + if (pwd->ahi.use_exp_vlc) { PARA_INFO_LOG("using exp_vlc\n"); init_vlc(&pwd->exp_vlc, EXPVLCBITS, sizeof(wma_scale_huffbits), 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; @@ -597,7 +581,7 @@ static int decode_exp_vlc(struct private_wmadec_data *pwd, int ch) last_exp = 36; while (q < q_end) { - code = get_vlc(&pwd->gb, pwd->exp_vlc.table, EXPVLCBITS, EXPMAX); + code = get_vlc(&pwd->gb, pwd->exp_vlc.table, EXPVLCBITS); if (code < 0) return code; /* NOTE: this offset is the same as MPEG4 AAC ! */ @@ -725,8 +709,7 @@ static int compute_high_band_values(struct private_wmadec_data *pwd, val = get_bits(&pwd->gb, 7) - 19; else { int code = get_vlc(&pwd->gb, - pwd->hgain_vlc.table, HGAINVLCBITS, - HGAINMAX); + pwd->hgain_vlc.table, HGAINVLCBITS); if (code < 0) return code; val += code - 18; @@ -827,7 +810,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) @@ -847,11 +830,11 @@ static int wma_decode_block(struct private_wmadec_data *pwd) int nb_coefs[MAX_CHANNELS]; /* compute current block length */ - if (pwd->use_variable_block_len) { + if (pwd->ahi.use_variable_block_len) { 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; @@ -924,7 +907,7 @@ static int wma_decode_block(struct private_wmadec_data *pwd) if ((pwd->block_len_bits == pwd->frame_len_bits) || get_bit(&pwd->gb)) { for (ch = 0; ch < pwd->ahi.channels; ch++) { if (pwd->channel_coded[ch]) { - if (pwd->use_exp_vlc) { + if (pwd->ahi.use_exp_vlc) { ret = decode_exp_vlc(pwd, ch); if (ret < 0) return ret; @@ -957,8 +940,7 @@ static int wma_decode_block(struct private_wmadec_data *pwd) eptr = ptr + nb_coefs[ch]; memset(ptr, 0, pwd->block_len * sizeof(int16_t)); for (;;) { - code = get_vlc(&pwd->gb, coef_vlc->table, - VLCBITS, VLCMAX); + code = get_vlc(&pwd->gb, coef_vlc->table, VLCBITS); if (code < 0) return code; if (code == 1) /* EOB */ @@ -1093,7 +1075,7 @@ static int wma_decode_superframe(struct private_wmadec_data *pwd, void *data, buf_size = pwd->ahi.block_align; samples = data; init_get_bits(&pwd->gb, buf, buf_size); - if (pwd->use_bit_reservoir) { + if (pwd->ahi.use_bit_reservoir) { int i, nb_frames, bit_offset, pos, len; uint8_t *q; @@ -1147,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) @@ -1210,9 +1192,9 @@ static int wmadec_execute(struct btr_node *btrn, const char *cmd, char **result) #define WMA_OUTPUT_BUFFER_SIZE (128 * 1024) -static int wmadec_post_select(__a_unused struct sched *s, struct task *t) +static int wmadec_post_select(__a_unused struct sched *s, void *context) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = context; int ret, converted, out_size; struct private_wmadec_data *pwd = fn->private_data; struct btr_node *btrn = fn->btrn;