struct vlc coef_vlc[2];
uint16_t *run_table[2];
uint16_t *level_table[2];
- uint16_t *int_table[2];
const struct coef_vlc_table *coef_vlcs[2];
/* frame info */
int frame_len; ///< frame length in samples
free_vlc(&pwd->coef_vlc[i]);
free(pwd->run_table[i]);
free(pwd->level_table[i]);
- free(pwd->int_table[i]);
}
}
-/* XXX: use same run/length optimization as mpeg decoders */
-//FIXME maybe split decode / encode or pass flag
static void init_coef_vlc(struct vlc *vlc, uint16_t **prun_table,
- uint16_t **plevel_table, uint16_t **pint_table,
- const struct coef_vlc_table *vlc_table)
+ uint16_t **plevel_table, const struct coef_vlc_table *vlc_table)
{
int n = vlc_table->n;
const uint8_t *table_bits = vlc_table->huffbits;
const uint32_t *table_codes = vlc_table->huffcodes;
const uint16_t *levels_table = vlc_table->levels;
- uint16_t *run_table, *level_table, *int_table;
+ uint16_t *run_table, *level_table;
int i, l, j, k, level;
init_vlc(vlc, VLCBITS, n, table_bits, table_codes, 4);
run_table = para_malloc(n * sizeof(uint16_t));
level_table = para_malloc(n * sizeof(uint16_t));
- int_table = para_malloc(n * sizeof(uint16_t));
i = 2;
level = 1;
k = 0;
while (i < n) {
- int_table[k] = i;
l = levels_table[k++];
for (j = 0; j < l; j++) {
run_table[i] = j;
}
*prun_table = run_table;
*plevel_table = level_table;
- *pint_table = int_table;
}
/* compute the scale factor band sizes for each MDCT block size */
pwd->coef_vlcs[0] = &coef_vlcs[coef_vlc_table * 2];
pwd->coef_vlcs[1] = &coef_vlcs[coef_vlc_table * 2 + 1];
init_coef_vlc(&pwd->coef_vlc[0], &pwd->run_table[0], &pwd->level_table[0],
- &pwd->int_table[0], pwd->coef_vlcs[0]);
+ pwd->coef_vlcs[0]);
init_coef_vlc(&pwd->coef_vlc[1], &pwd->run_table[1], &pwd->level_table[1],
- &pwd->int_table[1], pwd->coef_vlcs[1]);
+ pwd->coef_vlcs[1]);
return 0;
}
/* parse spectral coefficients : just RLE encoding */
for (ch = 0; ch < pwd->ahi.channels; ch++) {
- if (pwd->channel_coded[ch]) {
- struct vlc *coef_vlc;
- int level, run, sign, tindex;
- int16_t *ptr, *eptr;
- const uint16_t *level_table, *run_table;
-
- /* special VLC tables are used for ms stereo because
- there is potentially less energy there */
- tindex = (ch == 1 && pwd->ms_stereo);
- coef_vlc = &pwd->coef_vlc[tindex];
- run_table = pwd->run_table[tindex];
- level_table = pwd->level_table[tindex];
- /* XXX: optimize */
- ptr = &pwd->coefs1[ch][0];
- 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);
- if (code < 0)
- return -1;
- if (code == 1) {
- /* EOB */
- break;
- } else if (code == 0) {
- /* escape */
- level = get_bits(&pwd->gb, coef_nb_bits);
- /* NOTE: this is rather suboptimal. reading
- block_len_bits would be better */
- run =
- get_bits(&pwd->gb, pwd->frame_len_bits);
- } else {
- /* normal code */
- run = run_table[code];
- level = level_table[code];
- }
- sign = get_bit(&pwd->gb);
- if (!sign)
- level = -level;
- ptr += run;
- if (ptr >= eptr) {
- PARA_ERROR_LOG("overflow in spectral RLE, ignoring\n");
- break;
- }
- *ptr++ = level;
- /* NOTE: EOB can be omitted */
- if (ptr >= eptr)
- break;
+ struct vlc *coef_vlc;
+ int level, run, tindex;
+ int16_t *ptr, *eptr;
+ const uint16_t *level_table, *run_table;
+
+ if (!pwd->channel_coded[ch])
+ continue;
+ /*
+ * special VLC tables are used for ms stereo because there is
+ * potentially less energy there
+ */
+ tindex = (ch == 1 && pwd->ms_stereo);
+ coef_vlc = &pwd->coef_vlc[tindex];
+ run_table = pwd->run_table[tindex];
+ level_table = pwd->level_table[tindex];
+ /* XXX: optimize */
+ ptr = &pwd->coefs1[ch][0];
+ 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);
+ if (code < 0)
+ return -1;
+ if (code == 1) /* EOB */
+ break;
+ if (code == 0) { /* escape */
+ level = get_bits(&pwd->gb, coef_nb_bits);
+ /* reading block_len_bits would be better */
+ run = get_bits(&pwd->gb, pwd->frame_len_bits);
+ } else { /* normal code */
+ run = run_table[code];
+ level = level_table[code];
}
+ if (!get_bit(&pwd->gb))
+ level = -level;
+ ptr += run;
+ if (ptr >= eptr) {
+ PARA_ERROR_LOG("overflow in spectral RLE, ignoring\n");
+ break;
+ }
+ *ptr++ = level;
+ if (ptr >= eptr) /* EOB can be omitted */
+ break;
}
}
static int wma_decode_superframe(struct private_wmadec_data *pwd, void *data,
int *data_size, const uint8_t *buf, int buf_size)
{
- int ret, nb_frames, bit_offset, i, pos, len;
- uint8_t *q;
+ int ret;
int16_t *samples;
static int frame_count;
samples = data;
init_get_bits(&pwd->gb, buf, buf_size);
if (pwd->use_bit_reservoir) {
+ int i, nb_frames, bit_offset, pos, len;
+ uint8_t *q;
+
/* read super frame header */
skip_bits(&pwd->gb, 4); /* super frame index */
nb_frames = get_bits(&pwd->gb, 4) - 1;
if (out_size < 128 * 1024)
return 0;
+ if (len <= WMA_FRAME_SKIP)
+ return 0;
if (!pwd) {
ret = wma_decode_init(inbuffer, len, &pwd);
if (ret <= 0)