mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio/mp3: Move L3_Requantize to Go
This commit is contained in:
parent
c96b54dbfb
commit
74c2953f56
@ -50,6 +50,81 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
//export L3_Requantize
|
||||
func L3_Requantize(gr C.unsigned, ch C.unsigned) {
|
||||
/* Setup sampling frequency index */
|
||||
sfreq := C.g_frame_header.sampling_frequency
|
||||
/* Determine type of block to process */
|
||||
if (C.g_side_info.win_switch_flag[gr][ch] == 1) && (C.g_side_info.block_type[gr][ch] == 2) { /* Short blocks */
|
||||
/* Check if the first two subbands
|
||||
*(=2*18 samples = 8 long or 3 short sfb's) uses long blocks */
|
||||
if C.g_side_info.mixed_block_flag[gr][ch] != 0 { /* 2 longbl. sb first */
|
||||
/* First process the 2 long block subbands at the start */
|
||||
sfb := 0
|
||||
next_sfb := sfBandIndicesSet[sfreq].l[sfb+1]
|
||||
for i := 0; i < 36; i++ {
|
||||
if i == next_sfb {
|
||||
sfb++
|
||||
next_sfb = sfBandIndicesSet[sfreq].l[sfb+1]
|
||||
} /* end if */
|
||||
C.Requantize_Process_Long(gr, ch, C.unsigned(i), C.unsigned(sfb))
|
||||
}
|
||||
/* And next the remaining,non-zero,bands which uses short blocks */
|
||||
sfb = 3
|
||||
next_sfb = sfBandIndicesSet[sfreq].s[sfb+1] * 3
|
||||
win_len := sfBandIndicesSet[sfreq].s[sfb+1] -
|
||||
sfBandIndicesSet[sfreq].s[sfb]
|
||||
|
||||
for i := 36; i < int(C.g_side_info.count1[gr][ch]); /* i++ done below! */ {
|
||||
/* Check if we're into the next scalefac band */
|
||||
if i == next_sfb { /* Yes */
|
||||
sfb++
|
||||
next_sfb = sfBandIndicesSet[sfreq].s[sfb+1] * 3
|
||||
win_len = sfBandIndicesSet[sfreq].s[sfb+1] -
|
||||
sfBandIndicesSet[sfreq].s[sfb]
|
||||
}
|
||||
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))
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else { /* Only short blocks */
|
||||
sfb := 0
|
||||
next_sfb := sfBandIndicesSet[sfreq].s[sfb+1] * 3
|
||||
win_len := sfBandIndicesSet[sfreq].s[sfb+1] -
|
||||
sfBandIndicesSet[sfreq].s[sfb]
|
||||
for i := 0; i < int(C.g_side_info.count1[gr][ch]); /* i++ done below! */ {
|
||||
/* Check if we're into the next scalefac band */
|
||||
if i == next_sfb { /* Yes */
|
||||
sfb++
|
||||
next_sfb = sfBandIndicesSet[sfreq].s[sfb+1] * 3
|
||||
win_len = sfBandIndicesSet[sfreq].s[sfb+1] -
|
||||
sfBandIndicesSet[sfreq].s[sfb]
|
||||
}
|
||||
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))
|
||||
i++
|
||||
} /* end for(j... */
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { /* Only long blocks */
|
||||
sfb := 0
|
||||
next_sfb := sfBandIndicesSet[sfreq].l[sfb+1]
|
||||
for i := 0; i < int(C.g_side_info.count1[gr][ch]); i++ {
|
||||
if i == next_sfb {
|
||||
sfb++
|
||||
next_sfb = sfBandIndicesSet[sfreq].l[sfb+1]
|
||||
} /* end if */
|
||||
C.Requantize_Process_Long(gr, ch, C.unsigned(i), C.unsigned(sfb))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//export L3_Reorder
|
||||
func L3_Reorder(gr C.unsigned, ch C.unsigned) {
|
||||
re := make([]float32, 576)
|
||||
|
@ -44,10 +44,7 @@ static void audio_write(unsigned *samples,unsigned nsamples,int sample_rate);
|
||||
static void audio_write_raw(unsigned *samples,unsigned nsamples);
|
||||
static void Decode_L3_Init_Song(void);
|
||||
static void Error(const char *s,int e);
|
||||
static void L3_Requantize(unsigned gr,unsigned ch);
|
||||
static void Read_Ancillary(void);
|
||||
static void Requantize_Process_Long(unsigned gr,unsigned ch,unsigned is_pos,unsigned sfb);
|
||||
static void Requantize_Process_Short(unsigned gr,unsigned ch,unsigned is_pos,unsigned sfb,unsigned win);
|
||||
|
||||
static const unsigned g_mpeg1_bitrates[3 /* layer 1-3 */][15 /* header bitrate_index */] = {
|
||||
{ /* Layer 1 */
|
||||
@ -417,88 +414,6 @@ static void Decode_L3_Init_Song(void){
|
||||
synth_init = 1;
|
||||
}
|
||||
|
||||
/**Description: TBD
|
||||
* Parameters: TBD
|
||||
* Return value: TBD
|
||||
* Author: Krister Lagerström(krister@kmlager.com) **/
|
||||
static void L3_Requantize(unsigned gr,unsigned ch){
|
||||
unsigned sfb /* scalefac band index */,next_sfb /* frequency of next sfb */,
|
||||
sfreq,i,j,win,win_len;
|
||||
|
||||
/* Setup sampling frequency index */
|
||||
sfreq = g_frame_header.sampling_frequency;
|
||||
/* Determine type of block to process */
|
||||
if((g_side_info.win_switch_flag[gr][ch] == 1) && (g_side_info.block_type[gr][ch] == 2)) { /* Short blocks */
|
||||
/* Check if the first two subbands
|
||||
*(=2*18 samples = 8 long or 3 short sfb's) uses long blocks */
|
||||
if(g_side_info.mixed_block_flag[gr][ch] != 0) { /* 2 longbl. sb first */
|
||||
/* First process the 2 long block subbands at the start */
|
||||
sfb = 0;
|
||||
next_sfb = g_sf_band_indices[sfreq].l[sfb+1];
|
||||
for(i = 0; i < 36; i++) {
|
||||
if(i == next_sfb) {
|
||||
sfb++;
|
||||
next_sfb = g_sf_band_indices[sfreq].l[sfb+1];
|
||||
} /* end if */
|
||||
Requantize_Process_Long(gr,ch,i,sfb);
|
||||
}
|
||||
/* And next the remaining,non-zero,bands which uses short blocks */
|
||||
sfb = 3;
|
||||
next_sfb = g_sf_band_indices[sfreq].s[sfb+1] * 3;
|
||||
win_len = g_sf_band_indices[sfreq].s[sfb+1] -
|
||||
g_sf_band_indices[sfreq].s[sfb];
|
||||
|
||||
for(i = 36; i < g_side_info.count1[gr][ch]; /* i++ done below! */) {
|
||||
/* Check if we're into the next scalefac band */
|
||||
if(i == next_sfb) { /* Yes */
|
||||
sfb++;
|
||||
next_sfb = g_sf_band_indices[sfreq].s[sfb+1] * 3;
|
||||
win_len = g_sf_band_indices[sfreq].s[sfb+1] -
|
||||
g_sf_band_indices[sfreq].s[sfb];
|
||||
} /* end if(next_sfb) */
|
||||
for(win = 0; win < 3; win++) {
|
||||
for(j = 0; j < win_len; j++) {
|
||||
Requantize_Process_Short(gr,ch,i,sfb,win);
|
||||
i++;
|
||||
} /* end for(j... */
|
||||
} /* end for(win... */
|
||||
|
||||
} /* end for(i... */
|
||||
}else{ /* Only short blocks */
|
||||
sfb = 0;
|
||||
next_sfb = g_sf_band_indices[sfreq].s[sfb+1] * 3;
|
||||
win_len = g_sf_band_indices[sfreq].s[sfb+1] -
|
||||
g_sf_band_indices[sfreq].s[sfb];
|
||||
for(i = 0; i < g_side_info.count1[gr][ch]; /* i++ done below! */) {
|
||||
/* Check if we're into the next scalefac band */
|
||||
if(i == next_sfb) { /* Yes */
|
||||
sfb++;
|
||||
next_sfb = g_sf_band_indices[sfreq].s[sfb+1] * 3;
|
||||
win_len = g_sf_band_indices[sfreq].s[sfb+1] -
|
||||
g_sf_band_indices[sfreq].s[sfb];
|
||||
} /* end if(next_sfb) */
|
||||
for(win = 0; win < 3; win++) {
|
||||
for(j = 0; j < win_len; j++) {
|
||||
Requantize_Process_Short(gr,ch,i,sfb,win);
|
||||
i++;
|
||||
} /* end for(j... */
|
||||
} /* end for(win... */
|
||||
} /* end for(i... */
|
||||
} /* end else(only short blocks) */
|
||||
}else{ /* Only long blocks */
|
||||
sfb = 0;
|
||||
next_sfb = g_sf_band_indices[sfreq].l[sfb+1];
|
||||
for(i = 0; i < g_side_info.count1[gr][ch]; i++) {
|
||||
if(i == next_sfb) {
|
||||
sfb++;
|
||||
next_sfb = g_sf_band_indices[sfreq].l[sfb+1];
|
||||
} /* end if */
|
||||
Requantize_Process_Long(gr,ch,i,sfb);
|
||||
}
|
||||
} /* end else(only long blocks) */
|
||||
return; /* Done */
|
||||
}
|
||||
|
||||
/**Description: called by Read_Main_L3 to read Huffman coded data from bitstream.
|
||||
* Parameters: None
|
||||
* Return value: None. The data is stored in g_main_data.is[ch][gr][freqline].
|
||||
@ -573,7 +488,7 @@ void Read_Huffman(unsigned part_2_start,unsigned gr,unsigned ch){
|
||||
* Parameters: TBD
|
||||
* Return value: TBD
|
||||
* Author: Krister Lagerström(krister@kmlager.com) **/
|
||||
static void Requantize_Process_Long(unsigned gr,unsigned ch,unsigned is_pos,unsigned sfb){
|
||||
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 };
|
||||
|
||||
@ -592,7 +507,7 @@ static void Requantize_Process_Long(unsigned gr,unsigned ch,unsigned is_pos,unsi
|
||||
* Parameters: TBD
|
||||
* Return value: TBD
|
||||
* Author: Krister Lagerström(krister@kmlager.com) **/
|
||||
static void Requantize_Process_Short(unsigned gr,unsigned ch,unsigned is_pos,unsigned sfb,unsigned win){
|
||||
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;
|
||||
|
@ -99,6 +99,7 @@ int Read_Audio_L3(void);
|
||||
static int Read_Header(void);
|
||||
void Read_Huffman(unsigned part_2_start,unsigned gr,unsigned ch);
|
||||
|
||||
void L3_Requantize(unsigned gr,unsigned ch);
|
||||
void L3_Reorder(unsigned gr,unsigned ch);
|
||||
void L3_Stereo(unsigned gr);
|
||||
void L3_Antialias(unsigned gr,unsigned ch);
|
||||
@ -106,6 +107,9 @@ void L3_Hybrid_Synthesis(unsigned gr,unsigned ch);
|
||||
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);
|
||||
|
||||
int Huffman_Decode(unsigned table_num, int32_t* x, int32_t*y, int32_t* v, int32_t* w);
|
||||
|
Loading…
Reference in New Issue
Block a user