From 8efd0e725ff6f6f4c1ce18b95ff0320911de42d3 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 18 Jun 2017 17:13:38 +0900 Subject: [PATCH] audio/mp3: Remove global variables 'v_vec' and 'store' --- audio/mp3/l3.go | 16 ++++++---------- audio/mp3/read.go | 4 ++++ audio/mp3/types.go | 2 ++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/audio/mp3/l3.go b/audio/mp3/l3.go index d627016f6..fa4d582ba 100644 --- a/audio/mp3/l3.go +++ b/audio/mp3/l3.go @@ -375,8 +375,6 @@ func (f *frame) l3Antialias(gr int, ch int) { } } -var store = [2][32][18]float32{} - func (f *frame) l3HybridSynthesis(gr int, ch int) { // Loop through all 32 subbands for sb := 0; sb < 32; sb++ { @@ -394,8 +392,8 @@ func (f *frame) l3HybridSynthesis(gr int, ch int) { rawout := imdctWin(in, bt) // 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] + f.mainData.is[gr][ch][sb*18+i] = rawout[i] + f.store[ch][sb][i] + f.store[ch][sb][i] = rawout[i+18] } } } @@ -550,8 +548,6 @@ 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 []uint8) { u_vec := make([]float32, 512) s_vec := make([]float32, 32) @@ -560,7 +556,7 @@ func (f *frame) l3SubbandSynthesis(gr int, ch int, out []uint8) { /* Setup the n_win windowing vector and the v_vec intermediate vector */ for ss := 0; ss < 18; ss++ { /* Loop through 18 samples in 32 subbands */ for i := 1023; i > 63; i-- { /* Shift up the V vector */ - v_vec[ch][i] = v_vec[ch][i-64] + f.v_vec[ch][i] = f.v_vec[ch][i-64] } for i := 0; i < 32; i++ { /* Copy next 32 time samples to a temp vector */ s_vec[i] = f.mainData.is[gr][ch][i*18+ss] @@ -570,12 +566,12 @@ func (f *frame) l3SubbandSynthesis(gr int, ch int, out []uint8) { for j := 0; j < 32; j++ { sum += g_synth_n_win[i][j] * s_vec[j] } - v_vec[ch][i] = sum + f.v_vec[ch][i] = sum } for i := 0; i < 8; i++ { /* Build the U vector */ for j := 0; j < 32; j++ { /* <<7 == *128 */ - u_vec[(i<<6)+j] = v_vec[ch][(i<<7)+j] - u_vec[(i<<6)+j+32] = v_vec[ch][(i<<7)+j+96] + u_vec[(i<<6)+j] = f.v_vec[ch][(i<<7)+j] + u_vec[(i<<6)+j+32] = f.v_vec[ch][(i<<7)+j+96] } } for i := 0; i < 512; i++ { /* Window by u_vec[i] with g_synth_dtbl[i] */ diff --git a/audio/mp3/read.go b/audio/mp3/read.go index 1c38b7c41..c36b90259 100644 --- a/audio/mp3/read.go +++ b/audio/mp3/read.go @@ -46,6 +46,10 @@ func (f *frame) readNextFrame() (*frame, error) { nf := &frame{ prev: f, } + if nf.prev != nil { + nf.store = nf.prev.store + nf.v_vec = nf.prev.v_vec + } if err := nf.readHeader(); err != nil { return nil, err } diff --git a/audio/mp3/types.go b/audio/mp3/types.go index 6b336d650..5deaaff6e 100644 --- a/audio/mp3/types.go +++ b/audio/mp3/types.go @@ -91,4 +91,6 @@ type frame struct { mainData mpeg1MainData mainDataBytes *mainDataBytes + store [2][32][18]float32 + v_vec [2][1024]float32 }