audio/mp3: Move Requantize_Process_Long to Go

This commit is contained in:
Hajime Hoshi 2017-06-16 22:56:54 +09:00
parent 8e4abca1f8
commit 4b9242cbd0
3 changed files with 32 additions and 96 deletions

View File

@ -28,7 +28,10 @@ import (
"unsafe" "unsafe"
) )
var powtab34 = make([]float64, 8207) var (
powtab34 = make([]float64, 8207)
pretab = []float64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2}
)
func init() { func init() {
for i := range powtab34 { for i := range powtab34 {
@ -36,12 +39,34 @@ func init() {
} }
} }
func requantizeProcessLong(gr, ch, is_pos, sfb int) {
sf_mult := 0.5
if C.g_side_info.scalefac_scale[gr][ch] != 0 {
sf_mult = 1.0
}
tmp1 := 1.0
// https://github.com/technosaurus/PDMP3/issues/4
if sfb < 21 {
pf_x_pt := float64(C.g_side_info.preflag[gr][ch]) * pretab[sfb]
tmp1 = math.Pow(2.0, -(sf_mult * (float64(C.g_main_data.scalefac_l[gr][ch][sfb]) + pf_x_pt)))
}
tmp2 := math.Pow(2.0, 0.25*(float64(C.g_side_info.global_gain[gr][ch])-210))
tmp3 := 0.0
if C.g_main_data.is[gr][ch][is_pos] < 0.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)
}
func requantizeProcessShort(gr, ch, is_pos, sfb, win int) { func requantizeProcessShort(gr, ch, is_pos, sfb, win int) {
sf_mult := 0.5 sf_mult := 0.5
if C.g_side_info.scalefac_scale[gr][ch] != 0 { if C.g_side_info.scalefac_scale[gr][ch] != 0 {
sf_mult = 1.0 sf_mult = 1.0
} }
tmp1 := 1.0 tmp1 := 1.0
// https://github.com/technosaurus/PDMP3/issues/4
if sfb < 12 { if sfb < 12 {
tmp1 = math.Pow(2.0, -(sf_mult * float64(C.g_main_data.scalefac_s[gr][ch][sfb][win]))) tmp1 = math.Pow(2.0, -(sf_mult * float64(C.g_main_data.scalefac_s[gr][ch][sfb][win])))
} }
@ -94,8 +119,8 @@ func L3_Requantize(gr C.unsigned, ch C.unsigned) {
if i == next_sfb { if i == next_sfb {
sfb++ sfb++
next_sfb = sfBandIndicesSet[sfreq].l[sfb+1] next_sfb = sfBandIndicesSet[sfreq].l[sfb+1]
} /* end if */ }
C.Requantize_Process_Long(gr, ch, C.unsigned(i), C.unsigned(sfb)) requantizeProcessLong(int(gr), int(ch), i, sfb)
} }
/* And next the remaining,non-zero,bands which uses short blocks */ /* And next the remaining,non-zero,bands which uses short blocks */
sfb = 3 sfb = 3
@ -126,7 +151,7 @@ func L3_Requantize(gr C.unsigned, ch C.unsigned) {
sfBandIndicesSet[sfreq].s[sfb] sfBandIndicesSet[sfreq].s[sfb]
for i := 0; i < int(C.g_side_info.count1[gr][ch]); /* i++ done below! */ { for i := 0; i < int(C.g_side_info.count1[gr][ch]); /* i++ done below! */ {
/* Check if we're into the next scalefac band */ /* Check if we're into the next scalefac band */
if i == next_sfb { /* Yes */ if i == next_sfb {
sfb++ sfb++
next_sfb = sfBandIndicesSet[sfreq].s[sfb+1] * 3 next_sfb = sfBandIndicesSet[sfreq].s[sfb+1] * 3
win_len = sfBandIndicesSet[sfreq].s[sfb+1] - win_len = sfBandIndicesSet[sfreq].s[sfb+1] -
@ -136,7 +161,7 @@ func L3_Requantize(gr C.unsigned, ch C.unsigned) {
for j := 0; j < win_len; j++ { for j := 0; j < win_len; j++ {
requantizeProcessShort(int(gr), int(ch), i, sfb, win) requantizeProcessShort(int(gr), int(ch), i, sfb, win)
i++ i++
} /* end for(j... */ }
} }
} }
} }
@ -147,8 +172,8 @@ func L3_Requantize(gr C.unsigned, ch C.unsigned) {
if i == next_sfb { if i == next_sfb {
sfb++ sfb++
next_sfb = sfBandIndicesSet[sfreq].l[sfb+1] next_sfb = sfBandIndicesSet[sfreq].l[sfb+1]
} /* end if */ }
C.Requantize_Process_Long(gr, ch, C.unsigned(i), C.unsigned(sfb)) requantizeProcessLong(int(gr), int(ch), i, sfb)
} }
} }
} }

View File

@ -60,17 +60,6 @@ static const unsigned g_mpeg1_bitrates[3 /* layer 1-3 */][15 /* header bitrate_i
}, },
g_sampling_frequency[3] = { 44100 * Hz,48000 * Hz,32000 * Hz }; g_sampling_frequency[3] = { 44100 * Hz,48000 * Hz,32000 * Hz };
#ifdef POW34_ITERATE
static const float powtab34[32] = {
0.000000f,1.000000f,2.519842f,4.326749f,6.349605f,8.549880f,10.902724f,
13.390519f,16.000001f,18.720756f,21.544349f,24.463783f,27.473145f,30.567354f,
33.741995f,36.993185f,40.317478f,43.711792f,47.173351f,50.699637f,54.288359f,
57.937415f,61.644873f,65.408949f,69.227988f,73.100453f,77.024908f,81.000011f,
85.024502f,89.097200f,93.216988f,97.382814f
}
#endif
;
unsigned synth_init = 1; unsigned synth_init = 1;
/* Scale factor band indices /* Scale factor band indices
@ -171,59 +160,6 @@ static void dmp_samples(t_mpeg1_main_data *md,int gr,int ch,int type){
} }
#endif #endif
/**Description: calculates y=x^(4/3) when requantizing samples.
* Parameters: TBD
* Return value: TBD
* Author: Krister Lagerström(krister@kmlager.com) **/
static inline float Requantize_Pow_43(unsigned is_pos){
#ifdef POW34_TABLE
static float powtab34[8207];
static int init = 0;
int i;
if(init == 0) { /* First time initialization */
for(i = 0; i < 8207; i++)
powtab34[i] = pow((float) i,4.0 / 3.0);
init = 1;
}
#ifdef DEBUG
if(is_pos > 8206) {
ERR("is_pos = %d larger than 8206!",is_pos);
is_pos = 8206;
}
#endif /* DEBUG */
return(powtab34[is_pos]); /* Done */
#elif defined POW34_ITERATE
float a4,a2,x,x2,x3,x_next,is_f1,is_f2,is_f3;
unsigned i;
//static unsigned init = 0;
//static float powtab34[32];
static float coeff[3] = {-1.030797119e+02,6.319399834e+00,2.395095071e-03};
//if(init == 0) { /* First time initialization */
// for(i = 0; i < 32; i++) powtab34[i] = pow((float) i,4.0 / 3.0);
// init = 1;
//}
/* We use a table for 0<is_pos<32 since they are so common */
if(is_pos < 32) return(powtab34[is_pos]);
a2 = is_pos * is_pos;
a4 = a2 * a2;
is_f1 =(float) is_pos;
is_f2 = is_f1 * is_f1;
is_f3 = is_f1 * is_f2;
/* x = coeff[0] + coeff[1]*is_f1 + coeff[2]*is_f2 + coeff[3]*is_f3; */
x = coeff[0] + coeff[1]*is_f1 + coeff[2]*is_f2;
for(i = 0; i < 3; i++) {
x2 = x*x;
x3 = x*x2;
x_next =(2*x3 + a4) /(3*x2);
x = x_next;
}
return(x);
#else /* no optimization */
return powf((float)is_pos,4.0f / 3.0f);
#endif /* POW34_TABLE || POW34_ITERATE */
}
/**Description: decodes a layer 3 bitstream into audio samples. /**Description: decodes a layer 3 bitstream into audio samples.
* Parameters: Outdata vector. * Parameters: Outdata vector.
* Return value: OK or ERROR if the frame contains errors. * Return value: OK or ERROR if the frame contains errors.
@ -484,29 +420,6 @@ void Read_Huffman(unsigned part_2_start,unsigned gr,unsigned ch){
return; /* Done */ return; /* Done */
} }
/**Description: requantize sample in subband that uses long blocks.
* Parameters: TBD
* Return value: TBD
* Author: Krister Lagerström(krister@kmlager.com) **/
void Requantize_Process_Long(unsigned gr,unsigned ch,unsigned is_pos,unsigned sfb){
float res,tmp1,tmp2,tmp3,sf_mult,pf_x_pt;
static float pretab[21] = { 0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2 };
sf_mult = g_side_info.scalefac_scale[gr][ch] ? 1.0 : 0.5;
pf_x_pt = g_side_info.preflag[gr][ch] * pretab[sfb];
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]);
else tmp3 = 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 /**Description: output audio data
* Parameters: Pointers to the samples,the number of samples * Parameters: Pointers to the samples,the number of samples
* Return value: None * Return value: None

View File

@ -107,8 +107,6 @@ void L3_Hybrid_Synthesis(unsigned gr,unsigned ch);
void L3_Frequency_Inversion(unsigned gr,unsigned ch); void L3_Frequency_Inversion(unsigned gr,unsigned ch);
void L3_Subband_Synthesis(unsigned gr,unsigned ch, unsigned* outdata); void L3_Subband_Synthesis(unsigned gr,unsigned ch, unsigned* outdata);
void Requantize_Process_Long(unsigned gr,unsigned ch,unsigned is_pos,unsigned sfb);
int Read_CRC(void); int Read_CRC(void);
int Huffman_Decode(unsigned table_num, int32_t* x, int32_t*y, int32_t* v, int32_t* w); int Huffman_Decode(unsigned table_num, int32_t* x, int32_t*y, int32_t* v, int32_t* w);