diff --git a/audio/mp3/l3.go b/audio/mp3/l3.go index d9865277f..19145afa0 100644 --- a/audio/mp3/l3.go +++ b/audio/mp3/l3.go @@ -28,6 +28,34 @@ import ( "unsafe" ) +var powtab34 = make([]float64, 8207) + +func init() { + for i := range powtab34 { + powtab34[i] = math.Pow(float64(i), 4.0/3.0) + } +} + +func requantizeProcessShort(gr, ch, is_pos, sfb, win int) { + sf_mult := 0.5 + if C.g_side_info.scalefac_scale[gr][ch] != 0 { + sf_mult = 1.0 + } + tmp1 := 1.0 + if sfb < 12 { + tmp1 = math.Pow(2.0, -(sf_mult * float64(C.g_main_data.scalefac_s[gr][ch][sfb][win]))) + } + tmp2 := math.Pow(2.0, 0.25*(float64(C.g_side_info.global_gain[gr][ch])-210.0- + 8.0*float64(C.g_side_info.subblock_gain[gr][ch][win]))) + tmp3 := 0.0 + if C.g_main_data.is[gr][ch][is_pos] < 0 { + tmp3 = -powtab34[int(-C.g_main_data.is[gr][ch][is_pos])] + } else { + tmp3 = powtab34[int(C.g_main_data.is[gr][ch][is_pos])] + } + C.g_main_data.is[gr][ch][is_pos] = C.float(tmp1 * tmp2 * tmp3) +} + type sfBandIndices struct { l []int s []int @@ -85,7 +113,7 @@ func L3_Requantize(gr C.unsigned, ch C.unsigned) { } for win := 0; win < 3; win++ { for j := 0; j < win_len; j++ { - C.Requantize_Process_Short(gr, ch, C.unsigned(i), C.unsigned(sfb), C.unsigned(win)) + requantizeProcessShort(int(gr), int(ch), i, sfb, win) i++ } } @@ -106,7 +134,7 @@ func L3_Requantize(gr C.unsigned, ch C.unsigned) { } for win := 0; win < 3; win++ { for j := 0; j < win_len; j++ { - C.Requantize_Process_Short(gr, ch, C.unsigned(i), C.unsigned(sfb), C.unsigned(win)) + requantizeProcessShort(int(gr), int(ch), i, sfb, win) i++ } /* end for(j... */ } diff --git a/audio/mp3/pdmp3.c b/audio/mp3/pdmp3.c index f8a5da67e..cc40d9fc9 100644 --- a/audio/mp3/pdmp3.c +++ b/audio/mp3/pdmp3.c @@ -494,7 +494,11 @@ void Requantize_Process_Long(unsigned gr,unsigned ch,unsigned is_pos,unsigned sf sf_mult = g_side_info.scalefac_scale[gr][ch] ? 1.0 : 0.5; pf_x_pt = g_side_info.preflag[gr][ch] * pretab[sfb]; - tmp1 = pow(2.0,-(sf_mult *(g_main_data.scalefac_l[gr][ch][sfb] + pf_x_pt))); + if (sfb >= 21) { + tmp1 = 1.0; + } else { + tmp1 = pow(2.0,-(sf_mult *(g_main_data.scalefac_l[gr][ch][sfb] + pf_x_pt))); + } tmp2 = pow(2.0,0.25 *((int32_t) g_side_info.global_gain[gr][ch] - 210)); if(g_main_data.is[gr][ch][is_pos] < 0.0) tmp3 = -Requantize_Pow_43(-g_main_data.is[gr][ch][is_pos]); @@ -503,24 +507,6 @@ void Requantize_Process_Long(unsigned gr,unsigned ch,unsigned is_pos,unsigned sf return; /* Done */ } -/**Description: requantize sample in subband that uses short blocks. -* Parameters: TBD -* Return value: TBD -* Author: Krister Lagerström(krister@kmlager.com) **/ -void Requantize_Process_Short(unsigned gr,unsigned ch,unsigned is_pos,unsigned sfb,unsigned win){ - float res,tmp1,tmp2,tmp3,sf_mult; - - sf_mult = g_side_info.scalefac_scale[gr][ch] ? 1.0f : 0.5f; - tmp1 = pow(2.0f,-(sf_mult * g_main_data.scalefac_s[gr][ch][sfb][win])); - tmp2 = pow(2.0f,0.25f *((float) g_side_info.global_gain[gr][ch] - 210.0f - - 8.0f *(float) g_side_info.subblock_gain[gr][ch][win])); - tmp3 =(g_main_data.is[gr][ch][is_pos] < 0.0) - ? -Requantize_Pow_43(-g_main_data.is[gr][ch][is_pos]) - : Requantize_Pow_43(g_main_data.is[gr][ch][is_pos]); - res = g_main_data.is[gr][ch][is_pos] = tmp1 * tmp2 * tmp3; - return; /* Done */ -} - /**Description: output audio data * Parameters: Pointers to the samples,the number of samples * Return value: None diff --git a/audio/mp3/pdmp3.h b/audio/mp3/pdmp3.h index 7b85832cd..5fc38bbed 100644 --- a/audio/mp3/pdmp3.h +++ b/audio/mp3/pdmp3.h @@ -108,7 +108,6 @@ void L3_Frequency_Inversion(unsigned gr,unsigned ch); void L3_Subband_Synthesis(unsigned gr,unsigned ch, unsigned* outdata); void Requantize_Process_Long(unsigned gr,unsigned ch,unsigned is_pos,unsigned sfb); -void Requantize_Process_Short(unsigned gr,unsigned ch,unsigned is_pos,unsigned sfb,unsigned win); int Read_CRC(void);