audio/mp3: Remove audioWriteRaw

This commit is contained in:
Hajime Hoshi 2017-06-17 23:58:15 +09:00
parent ae85ec991c
commit 19b3df1da3
2 changed files with 15 additions and 33 deletions

View File

@ -37,7 +37,6 @@ func (f *frame) numberOfChannels() int {
} }
func (f *frame) decodeL3() error { func (f *frame) decodeL3() error {
out := make([]uint32, 576)
nch := f.numberOfChannels() nch := f.numberOfChannels()
for gr := 0; gr < 2; gr++ { for gr := 0; gr < 2; gr++ {
for ch := 0; ch < nch; ch++ { for ch := 0; ch < nch; ch++ {
@ -46,6 +45,7 @@ func (f *frame) decodeL3() error {
f.l3Reorder(gr, ch) f.l3Reorder(gr, ch)
} }
f.l3Stereo(gr) f.l3Stereo(gr)
out := make([]uint8, 576*4)
for ch := 0; ch < nch; ch++ { for ch := 0; ch < nch; ch++ {
f.l3Antialias(gr, ch) f.l3Antialias(gr, ch)
// (IMDCT,windowing,overlapp add) // (IMDCT,windowing,overlapp add)
@ -54,33 +54,13 @@ func (f *frame) decodeL3() error {
// Polyphase subband synthesis // Polyphase subband synthesis
f.l3SubbandSynthesis(gr, ch, out) f.l3SubbandSynthesis(gr, ch, out)
} }
if err := f.audioWriteRaw(out); err != nil { if _, err := writer.Write(out); err != nil {
return err return err
} }
} }
return nil return nil
} }
func (f *frame) audioWriteRaw(samples []uint32) error {
nch := f.numberOfChannels()
s := make([]uint8, len(samples)*2*nch)
for i, v := range samples {
if nch == 1 {
s[2*i] = uint8(v)
s[2*i+1] = uint8(v >> 8)
} else {
s[4*i] = uint8(v)
s[4*i+1] = uint8(v >> 8)
s[4*i+2] = uint8(v >> 16)
s[4*i+3] = uint8(v >> 24)
}
}
if _, err := writer.Write(s); err != nil {
return err
}
return nil
}
func getByte() (uint8, error) { func getByte() (uint8, error) {
for len(readerCache) == 0 && !readerEOF { for len(readerCache) == 0 && !readerEOF {
buf := make([]uint8, 4096) buf := make([]uint8, 4096)

View File

@ -552,7 +552,7 @@ var g_synth_dtbl = [512]float32{
var v_vec = [2][1024]float32{} var v_vec = [2][1024]float32{}
func (f *frame) l3SubbandSynthesis(gr int, ch int, out []uint32) { func (f *frame) l3SubbandSynthesis(gr int, ch int, out []uint8) {
u_vec := make([]float32, 512) u_vec := make([]float32, 512)
s_vec := make([]float32, 32) s_vec := make([]float32, 32)
@ -595,18 +595,20 @@ func (f *frame) l3SubbandSynthesis(gr int, ch int, out []uint32) {
} }
samp &= 0xffff samp &= 0xffff
s := uint32(samp) s := uint32(samp)
// This function must be called for channel 0 first. if nch == 1 {
// We always run in stereo mode and duplicate channels here for mono.
out[4*(32*ss+i)] = uint8(s)
out[4*(32*ss+i)+1] = uint8(s >> 8)
out[4*(32*ss+i)+2] = uint8(s)
out[4*(32*ss+i)+3] = uint8(s >> 8)
continue
}
if ch == 0 { if ch == 0 {
// We always run in stereo mode,& duplicate channels here for mono. out[4*(32*ss+i)] = uint8(s)
if nch == 1 { out[4*(32*ss+i)+1] = uint8(s >> 8)
out[32*ss+i] = (s << 16) | (s)
} else {
// Note that this is different from original PDMP3.
// Samples are set in little endian order here.
out[32*ss+i] = s
}
} else { } else {
out[32*ss+i] |= (s << 16) out[4*(32*ss+i)+2] = uint8(s)
out[4*(32*ss+i)+3] = uint8(s >> 8)
} }
} }
} }