From: Andre Noll Date: Tue, 7 Jan 2025 23:09:21 +0000 (+0100) Subject: wmadec: Remove noise coding. X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=85a159d245b19e1fd0542b6f0ea1c290e519b515;p=paraslash.git wmadec: Remove noise coding. It is not used anyway in most cases, and it complicates the code considerably. --- diff --git a/wmadata.h b/wmadata.h index 185ec1fc..f4f92217 100644 --- a/wmadata.h +++ b/wmadata.h @@ -60,22 +60,6 @@ static const uint8_t exponent_band_44100[3][25] = { {17, 4, 8, 8, 4, 12, 12, 8, 8, 24, 16, 20, 24, 32, 40, 60, 80, 152,}, }; -static const uint16_t wma_hgain_huffcodes[37] = { - 0x00003, 0x002e7, 0x00001, 0x005cd, 0x0005d, 0x005c9, 0x0005e, 0x00003, - 0x00016, 0x0000b, 0x00001, 0x00006, 0x00001, 0x00006, 0x00004, 0x00005, - 0x00004, 0x00007, 0x00003, 0x00007, 0x00004, 0x0000a, 0x0000a, 0x00002, - 0x00003, 0x00000, 0x00005, 0x00002, 0x0005f, 0x00004, 0x00003, 0x00002, - 0x005c8, 0x000b8, 0x005ca, 0x005cb, 0x005cc, -}; - -static const uint8_t wma_hgain_huffbits[37] = { - 10, 12, 10, 13, 9, 13, 9, 8, - 7, 5, 5, 4, 4, 3, 3, 3, - 4, 3, 4, 4, 5, 5, 6, 8, - 7, 10, 8, 10, 9, 8, 9, 9, - 13, 10, 13, 13, 13, -}; - #define NB_LSP_COEFS 10 static const float wma_lsp_codebook[NB_LSP_COEFS][16] = { diff --git a/wmadec_filter.c b/wmadec_filter.c index 922a8aae..ebb83e6f 100644 --- a/wmadec_filter.c +++ b/wmadec_filter.c @@ -38,24 +38,16 @@ #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1) -/* XXX: find exact max size */ -#define HIGH_BAND_MAX_SIZE 16 - /* XXX: is it a suitable value ? */ #define MAX_CODED_SUPERFRAME_SIZE 16384 #define MAX_CHANNELS 2 - -#define NOISE_TAB_SIZE 8192 - #define LSP_POW_BITS 7 struct private_wmadec_data { /** Information contained in the audio file header. */ struct asf_header_info ahi; struct getbit_context gb; - /** 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 ahi->use_exp_vlc is true. */ @@ -65,14 +57,6 @@ struct private_wmadec_data { int high_band_start[BLOCK_NB_SIZES]; /** Maximal number of coded coefficients. */ int coefs_end[BLOCK_NB_SIZES]; - int exponent_high_sizes[BLOCK_NB_SIZES]; - int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE]; - struct vlc hgain_vlc; - - /* coded values in high bands */ - int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]; - int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]; - /* there are two possible tables for spectral coefficients */ struct vlc coef_vlc[2]; uint16_t *run_table[2]; @@ -113,9 +97,6 @@ struct private_wmadec_data { uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */ int last_bitoffset; int last_superframe_len; - float noise_table[NOISE_TAB_SIZE]; - int noise_index; - float noise_mult; /* XXX: suppress that and integrate it in the noise array */ /* lsp_to_curve tables */ float lsp_cos_table[BLOCK_MAX_SIZE]; float lsp_pow_e_table[256]; @@ -124,7 +105,6 @@ struct private_wmadec_data { }; #define EXPVLCBITS 8 -#define HGAINVLCBITS 9 #define VLCBITS 9 /** \cond sine_winows */ @@ -227,7 +207,6 @@ static void compute_scale_factor_band_sizes(struct private_wmadec_data *pwd, pwd->high_band_start[k] = (int) ((block_len * 2 * high_freq) / ahi->sample_rate + 0.5); n = exponent_size; - j = 0; pos = 0; for (i = 0; i < n; i++) { int start, end; @@ -238,10 +217,7 @@ static void compute_scale_factor_band_sizes(struct private_wmadec_data *pwd, start = pwd->high_band_start[k]; if (end > pwd->coefs_end[k]) end = pwd->coefs_end[k]; - if (end > start) - pwd->exponent_high_bands[k][j++] = end - start; } - pwd->exponent_high_sizes[k] = j; } } @@ -281,7 +257,6 @@ static int wma_init(struct private_wmadec_data *pwd) pwd->nb_block_sizes = 1; /* init rate dependent parameters */ - pwd->use_noise_coding = 1; high_freq = ahi->sample_rate * 0.5; /* wma2 rates are normalized */ @@ -307,17 +282,15 @@ static int wma_init(struct private_wmadec_data *pwd) if (ahi->channels == 2) bps1 = bps * 1.6; if (sample_rate1 == 44100) { - if (bps1 >= 0.61) - pwd->use_noise_coding = 0; - else + if (bps1 < 0.61) high_freq = high_freq * 0.4; } else if (sample_rate1 == 22050) { - if (bps1 >= 1.16) - pwd->use_noise_coding = 0; - else if (bps1 >= 0.72) - high_freq = high_freq * 0.7; - else - high_freq = high_freq * 0.6; + if (bps1 < 1.16) { + if (bps1 >= 0.72) + high_freq = high_freq * 0.7; + else + high_freq = high_freq * 0.6; + } } else if (sample_rate1 == 16000) { if (bps > 0.5) high_freq = high_freq * 0.5; @@ -328,9 +301,7 @@ static int wma_init(struct private_wmadec_data *pwd) else if (sample_rate1 == 8000) { if (bps <= 0.625) high_freq = high_freq * 0.5; - else if (bps > 0.75) - pwd->use_noise_coding = 0; - else + else if (bps <= 0.75) high_freq = high_freq * 0.65; } else { if (bps >= 0.8) @@ -348,8 +319,8 @@ static int wma_init(struct private_wmadec_data *pwd) "high_freq=%f bitoffset=%d\n", 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->ahi.use_exp_vlc, pwd->nb_block_sizes); + PARA_INFO_LOG("use_exp_vlc=%d nb_block_sizes=%d\n", + pwd->ahi.use_exp_vlc, pwd->nb_block_sizes); compute_scale_factor_band_sizes(pwd, high_freq); /* init MDCT windows : simple sinus window */ @@ -362,21 +333,6 @@ static int wma_init(struct private_wmadec_data *pwd) pwd->reset_block_lengths = true; - if (pwd->use_noise_coding) { - unsigned int seed = 1; - float norm; - /* init the noise generator */ - if (pwd->ahi.use_exp_vlc) - pwd->noise_mult = 0.02; - else - pwd->noise_mult = 0.04; - norm = (1.0 / (float)(1LL << 31)) * sqrt(3) * pwd->noise_mult; - for (i = 0; i < NOISE_TAB_SIZE; i++) { - seed = seed * 314159 + 1; - pwd->noise_table[i] = (float)((int)seed) * norm; - } - } - /* choose the VLC tables for the coefficients */ coef_vlc_table = 4; if (ahi->sample_rate >= 32000) { @@ -439,13 +395,6 @@ static int wma_decode_init(char *initial_buf, int len, struct private_wmadec_dat if (ret < 0) return ret; } - if (pwd->use_noise_coding) { - PARA_INFO_LOG("using noise coding\n"); - init_vlc(&pwd->hgain_vlc, HGAINVLCBITS, - sizeof(wma_hgain_huffbits), wma_hgain_huffbits, - wma_hgain_huffcodes, 2); - } - if (pwd->ahi.use_exp_vlc) { PARA_INFO_LOG("using exp_vlc\n"); init_vlc(&pwd->exp_vlc, EXPVLCBITS, sizeof(wma_scale_huffbits), @@ -637,49 +586,6 @@ static int wma_total_gain_to_bits(int total_gain) return 9; } -static int compute_high_band_values(struct private_wmadec_data *pwd, - int bsize, int nb_coefs[MAX_CHANNELS]) -{ - int ch; - - if (!pwd->use_noise_coding) - return 0; - for (ch = 0; ch < pwd->ahi.channels; ch++) { - int i, m, a; - if (!pwd->channel_coded[ch]) - continue; - m = pwd->exponent_high_sizes[bsize]; - for (i = 0; i < m; i++) { - a = get_bit(&pwd->gb); - pwd->high_band_coded[ch][i] = a; - if (!a) - continue; - nb_coefs[ch] -= pwd->exponent_high_bands[bsize][i]; - } - } - for (ch = 0; ch < pwd->ahi.channels; ch++) { - int i, n, val; - if (!pwd->channel_coded[ch]) - continue; - n = pwd->exponent_high_sizes[bsize]; - val = (int)0x80000000; - for (i = 0; i < n; i++) { - if (!pwd->high_band_coded[ch][i]) - continue; - if (val == (int)0x80000000) - val = get_bits(&pwd->gb, 7) - 19; - else { - int code = get_vlc(&pwd->gb, &pwd->hgain_vlc); - if (code < 0) - return code; - val += code - 18; - } - pwd->high_band_values[ch][i] = val; - } - } - return 1; -} - static void compute_mdct_coefficients(struct private_wmadec_data *pwd, int bsize, int total_gain, int nb_coefs[MAX_CHANNELS]) { @@ -688,9 +594,8 @@ static void compute_mdct_coefficients(struct private_wmadec_data *pwd, for (ch = 0; ch < pwd->ahi.channels; ch++) { int16_t *coefs1; - float *coefs, *exponents, mult, mult1, noise; - int i, j, n, n1, last_high_band, esize; - float exp_power[HIGH_BAND_MAX_SIZE]; + float *coefs, *exponents, mult; + int i, n, esize; if (!pwd->channel_coded[ch]) continue; @@ -700,82 +605,14 @@ static void compute_mdct_coefficients(struct private_wmadec_data *pwd, mult = pow(10, total_gain * 0.05) / pwd->max_exponent[ch]; mult *= mdct_norm; coefs = pwd->coefs[ch]; - if (!pwd->use_noise_coding) { - /* XXX: optimize more */ - n = nb_coefs[ch]; - for (i = 0; i < n; i++) - *coefs++ = coefs1[i] * - exponents[i << bsize >> esize] * mult; - n = pwd->block_len - pwd->coefs_end[bsize]; - for (i = 0; i < n; i++) - *coefs++ = 0.0; - continue; - } - n1 = pwd->exponent_high_sizes[bsize]; - /* compute power of high bands */ - exponents = pwd->exponents[ch] + - (pwd->high_band_start[bsize] << bsize); - last_high_band = 0; /* avoid warning */ - for (j = 0; j < n1; j++) { - n = pwd->exponent_high_bands[ - pwd->frame_len_bits - pwd->block_len_bits][j]; - if (pwd->high_band_coded[ch][j]) { - float e2, val; - e2 = 0; - for (i = 0; i < n; i++) { - val = exponents[i << bsize >> esize]; - e2 += val * val; - } - exp_power[j] = e2 / n; - last_high_band = j; - } - exponents += n << bsize; - } - /* main freqs and high freqs */ - exponents = pwd->exponents[ch]; - for (j = -1; j < n1; j++) { - if (j < 0) - n = pwd->high_band_start[bsize]; - else - n = pwd->exponent_high_bands[pwd->frame_len_bits - - pwd->block_len_bits][j]; - if (j >= 0 && pwd->high_band_coded[ch][j]) { - /* use noise with specified power */ - mult1 = sqrt(exp_power[j] - / exp_power[last_high_band]); - /* XXX: use a table */ - mult1 *= pow(10, pwd->high_band_values[ch][j] * 0.05); - mult1 /= (pwd->max_exponent[ch] * pwd->noise_mult); - mult1 *= mdct_norm; - for (i = 0; i < n; i++) { - noise = pwd->noise_table[pwd->noise_index]; - pwd->noise_index = (pwd->noise_index + 1) - & (NOISE_TAB_SIZE - 1); - *coefs++ = noise * exponents[ - i << bsize >> esize] * mult1; - } - exponents += n << bsize; - } else { - /* coded values + small noise */ - for (i = 0; i < n; i++) { - noise = pwd->noise_table[pwd->noise_index]; - pwd->noise_index = (pwd->noise_index + 1) - & (NOISE_TAB_SIZE - 1); - *coefs++ = ((*coefs1++) + noise) * - exponents[i << bsize >> esize] - * mult; - } - exponents += n << bsize; - } - } - /* very high freqs: noise */ + /* XXX: optimize more */ + n = nb_coefs[ch]; + for (i = 0; i < n; i++) + *coefs++ = coefs1[i] * + exponents[i << bsize >> esize] * mult; n = pwd->block_len - pwd->coefs_end[bsize]; - 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) - & (NOISE_TAB_SIZE - 1); - } + for (i = 0; i < n; i++) + *coefs++ = 0.0; } } @@ -860,10 +697,6 @@ static int wma_decode_block(struct private_wmadec_data *pwd) for (ch = 0; ch < pwd->ahi.channels; ch++) nb_coefs[ch] = n; - ret = compute_high_band_values(pwd, bsize, nb_coefs); - if (ret < 0) - return ret; - /* exponents can be reused in short blocks. */ if ((pwd->block_len_bits == pwd->frame_len_bits) || get_bit(&pwd->gb)) { for (ch = 0; ch < pwd->ahi.channels; ch++) { @@ -1132,8 +965,6 @@ static void wmadec_close(struct filter_node *fn) imdct_end(pwd->mdct_ctx[i]); if (pwd->ahi.use_exp_vlc) free_vlc(&pwd->exp_vlc); - if (pwd->use_noise_coding) - free_vlc(&pwd->hgain_vlc); for (i = 0; i < 2; i++) { free_vlc(&pwd->coef_vlc[i]); free(pwd->run_table[i]);