From c496d94047970e74bbcf5fd0a33935ca533fa343 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 17 Jun 2017 19:33:49 +0900 Subject: [PATCH] audio/mp3: Remove isEOF --- audio/mp3/decode_notjs.go | 14 +++++--------- audio/mp3/l3.go | 17 +++++++++-------- audio/mp3/read.go | 3 +++ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/audio/mp3/decode_notjs.go b/audio/mp3/decode_notjs.go index a6dd1eeb0..3c272708f 100644 --- a/audio/mp3/decode_notjs.go +++ b/audio/mp3/decode_notjs.go @@ -17,6 +17,7 @@ package mp3 import ( + "errors" "io" ) @@ -113,22 +114,17 @@ func getBytes(buf []int) (int, error) { return len(buf), nil } -func isEOF() bool { - if len(readerCache) == 0 && readerEOF { - return true - } - return false -} - func getFilepos() int { return readerPos } +var eof = errors.New("mp3: expected EOF") + func decode(r io.Reader, w io.Writer) error { // TODO: Decoder should know number of channels reader = r writer = w - for !isEOF() { + for { f, err := readFrame() if err == nil { if err := f.decodeL3(); err != nil { @@ -136,7 +132,7 @@ func decode(r io.Reader, w io.Writer) error { } continue } - if isEOF() { + if err == eof { break } return err diff --git a/audio/mp3/l3.go b/audio/mp3/l3.go index 378f019d7..51ecfdf85 100644 --- a/audio/mp3/l3.go +++ b/audio/mp3/l3.go @@ -378,20 +378,22 @@ func (f *frame) l3Antialias(gr int, ch int) { var store = [2][32][18]float32{} func (f *frame) l3HybridSynthesis(gr int, ch int) { - for sb := 0; sb < 32; sb++ { /* Loop through all 32 subbands */ - /* Determine blocktype for this subband */ + // Loop through all 32 subbands + for sb := 0; sb < 32; sb++ { + // Determine blocktype for this subband bt := int(f.sideInfo.block_type[gr][ch]) if (f.sideInfo.win_switch_flag[gr][ch] == 1) && (f.sideInfo.mixed_block_flag[gr][ch] == 1) && (sb < 2) { bt = 0 } - /* Do the inverse modified DCT and windowing */ + // Do the inverse modified DCT and windowing in := make([]float32, 18) for i := range in { in[i] = f.mainData.is[gr][ch][sb*18+i] } rawout := imdctWin(in, bt) - for i := 0; i < 18; i++ { /* Overlapp add with stored vector into main_data vector */ + // Overlapp add with stored vector into main_data vector + for i := 0; i < 18; i++ { f.mainData.is[gr][ch][sb*18+i] = rawout[i] + store[ch][sb][i] store[ch][sb][i] = rawout[i+18] } @@ -406,10 +408,7 @@ func (f *frame) l3FrequencyInversion(gr int, ch int) { } } -var ( - g_synth_n_win = [64][32]float32{} - v_vec = [2][1024]float32{} -) +var g_synth_n_win = [64][32]float32{} func init() { for i := 0; i < 64; i++ { @@ -551,6 +550,8 @@ var g_synth_dtbl = [512]float32{ 0.000015259, 0.000015259, 0.000015259, 0.000015259, } +var v_vec = [2][1024]float32{} + func (f *frame) l3SubbandSynthesis(gr int, ch int, out []uint32) { u_vec := make([]float32, 512) s_vec := make([]float32, 32) diff --git a/audio/mp3/read.go b/audio/mp3/read.go index 3b6e0ebc5..5fb4a9c90 100644 --- a/audio/mp3/read.go +++ b/audio/mp3/read.go @@ -97,6 +97,9 @@ func (f *frame) readHeader() error { } if n < 4 { if err == io.EOF { + if n == 0 { + return eof + } return fmt.Errorf("mp3: unexpected EOF at readHeader") } return err