#define _XOPEN_SOURCE 600
-#include <sys/time.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <math.h>
-#include <string.h>
#include <regex.h>
#include <sys/select.h>
/** 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. */
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. */
};
#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)
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)
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);
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)
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 */
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;
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 */
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;
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;
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 ! */
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;
}
/* 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)
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;
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;
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 */
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;
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)
#define WMA_OUTPUT_BUFFER_SIZE (128 * 1024)
-static void 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;
next_buffer:
converted = 0;
- t->error = 0;
ret = btr_node_status(btrn, fn->min_iqs, BTR_NT_INTERNAL);
if (ret < 0)
goto err;
if (ret == 0)
- return;
+ return 0;
btr_merge(btrn, fn->min_iqs);
len = btr_next_buffer(btrn, (char **)&in);
ret = -E_WMADEC_EOF;
converted += ret + WMA_FRAME_SKIP;
success:
btr_consume(btrn, converted);
- return;
+ return 0;
err:
assert(ret < 0);
- t->error = ret;
btr_remove_node(&fn->btrn);
+ return ret;
}
static void wmadec_open(struct filter_node *fn)