From 02e284ea9dca79c1f638a0eee40393aad36937f8 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 17 Jun 2017 06:43:50 +0900 Subject: [PATCH] audio/mp3: Refactoring --- audio/mp3/decode_notjs.go | 15 ++++++++------- audio/mp3/l3.go | 18 ++++++------------ audio/mp3/pdmp3.h | 9 --------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/audio/mp3/decode_notjs.go b/audio/mp3/decode_notjs.go index d48e5e6d7..6d806eec7 100644 --- a/audio/mp3/decode_notjs.go +++ b/audio/mp3/decode_notjs.go @@ -41,22 +41,23 @@ var ( func decodeL3() error { out := make([]int, 576) - /* Number of channels(1 for mono and 2 for stereo) */ + // Number of channels(1 for mono and 2 for stereo) nch := 2 if C.g_frame_header.mode == C.mpeg1_mode_single_channel { nch = 1 } for gr := 0; gr < 2; gr++ { for ch := 0; ch < nch; ch++ { - L3_Requantize(C.uint(gr), C.uint(ch)) /* Requantize samples */ - L3_Reorder(C.uint(gr), C.uint(ch)) /* Reorder short blocks */ + l3Requantize(gr, ch) + // Reorder short blocks + l3Reorder(gr, ch) } - L3_Stereo(C.uint(gr)) /* Stereo processing */ + l3Stereo(gr) for ch := 0; ch < nch; ch++ { - L3_Antialias(C.uint(gr), C.uint(ch)) + l3Antialias(gr, ch) // (IMDCT,windowing,overlapp add) - L3_Hybrid_Synthesis(C.uint(gr), C.uint(ch)) - L3_Frequency_Inversion(C.uint(gr), C.uint(ch)) + l3HybridSynthesis(gr, ch) + l3FrequencyInversion(gr, ch) // Polyphase subband synthesis l3SubbandSynthesis(gr, ch, out) } diff --git a/audio/mp3/l3.go b/audio/mp3/l3.go index a35701c90..7d9038e1f 100644 --- a/audio/mp3/l3.go +++ b/audio/mp3/l3.go @@ -102,8 +102,7 @@ var ( } ) -//export L3_Requantize -func L3_Requantize(gr C.unsigned, ch C.unsigned) { +func l3Requantize(gr int, ch int) { /* Setup sampling frequency index */ sfreq := C.g_frame_header.sampling_frequency /* Determine type of block to process */ @@ -177,8 +176,7 @@ func L3_Requantize(gr C.unsigned, ch C.unsigned) { } } -//export L3_Reorder -func L3_Reorder(gr C.unsigned, ch C.unsigned) { +func l3Reorder(gr int, ch int) { re := make([]float32, 576) sfreq := C.g_frame_header.sampling_frequency /* Setup sampling freq index */ @@ -284,8 +282,7 @@ func stereoProcessIntensityShort(gr int, sfb int) { } } -//export L3_Stereo -func L3_Stereo(gr C.unsigned) { +func l3Stereo(gr int) { /* Do nothing if joint stereo is not enabled */ if (C.g_frame_header.mode != 1) || (C.g_frame_header.mode_extension == 0) { return @@ -358,8 +355,7 @@ var ( ca = [8]float32{-0.514496, -0.471732, -0.313377, -0.181913, -0.094574, -0.040966, -0.014199, -0.003700} ) -//export L3_Antialias -func L3_Antialias(gr C.unsigned, ch C.unsigned) { +func l3Antialias(gr int, ch int) { /* No antialiasing is done for short blocks */ if (C.g_side_info.win_switch_flag[gr][ch] == 1) && (C.g_side_info.block_type[gr][ch] == 2) && @@ -388,8 +384,7 @@ func L3_Antialias(gr C.unsigned, ch C.unsigned) { var store = [2][32][18]float32{} -//export L3_Hybrid_Synthesis -func L3_Hybrid_Synthesis(gr C.unsigned, ch C.unsigned) { +func l3HybridSynthesis(gr int, ch int) { for sb := 0; sb < 32; sb++ { /* Loop through all 32 subbands */ /* Determine blocktype for this subband */ bt := int(C.g_side_info.block_type[gr][ch]) @@ -410,8 +405,7 @@ func L3_Hybrid_Synthesis(gr C.unsigned, ch C.unsigned) { } } -//export L3_Frequency_Inversion -func L3_Frequency_Inversion(gr C.unsigned, ch C.unsigned) { +func l3FrequencyInversion(gr int, ch int) { for sb := 1; sb < 32; sb += 2 { //OPT? : for(sb = 18; sb < 576; sb += 36) for i := 1; i < 18; i += 2 { C.g_main_data.is[gr][ch][sb*18+i] = -C.g_main_data.is[gr][ch][sb*18+i] diff --git a/audio/mp3/pdmp3.h b/audio/mp3/pdmp3.h index dc0aea7ec..4c74b0740 100644 --- a/audio/mp3/pdmp3.h +++ b/audio/mp3/pdmp3.h @@ -89,13 +89,4 @@ unsigned Get_Filepos(void); unsigned Get_Main_Pos(void); int Set_Main_Pos(unsigned bit_pos); -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); -void L3_Hybrid_Synthesis(unsigned gr,unsigned ch); -void L3_Frequency_Inversion(unsigned gr,unsigned ch); - -int Read_CRC(void); - #endif