audio/mp3: Refactoring: Add frame.numberOfChannels

This commit is contained in:
Hajime Hoshi 2017-06-17 23:33:29 +09:00
parent 76320010f4
commit ae85ec991c
4 changed files with 12 additions and 25 deletions

View File

@ -29,13 +29,16 @@ var (
writer io.Writer writer io.Writer
) )
func (f *frame) numberOfChannels() int {
if f.header.mode == mpeg1ModeSingleChannel {
return 1
}
return 2
}
func (f *frame) decodeL3() error { func (f *frame) decodeL3() error {
out := make([]uint32, 576) out := make([]uint32, 576)
// Number of channels(1 for mono and 2 for stereo) nch := f.numberOfChannels()
nch := 2
if f.header.mode == mpeg1ModeSingleChannel {
nch = 1
}
for gr := 0; gr < 2; gr++ { for gr := 0; gr < 2; gr++ {
for ch := 0; ch < nch; ch++ { for ch := 0; ch < nch; ch++ {
f.l3Requantize(gr, ch) f.l3Requantize(gr, ch)
@ -59,10 +62,7 @@ func (f *frame) decodeL3() error {
} }
func (f *frame) audioWriteRaw(samples []uint32) error { func (f *frame) audioWriteRaw(samples []uint32) error {
nch := 2 nch := f.numberOfChannels()
if f.header.mode == mpeg1ModeSingleChannel {
nch = 1
}
s := make([]uint8, len(samples)*2*nch) s := make([]uint8, len(samples)*2*nch)
for i, v := range samples { for i, v := range samples {
if nch == 1 { if nch == 1 {
@ -121,7 +121,6 @@ func getFilepos() int {
var eof = errors.New("mp3: expected EOF") var eof = errors.New("mp3: expected EOF")
func decode(r io.Reader, w io.Writer) error { func decode(r io.Reader, w io.Writer) error {
// TODO: Decoder should know number of channels
reader = r reader = r
writer = w writer = w
for { for {

View File

@ -556,11 +556,7 @@ func (f *frame) l3SubbandSynthesis(gr int, ch int, out []uint32) {
u_vec := make([]float32, 512) u_vec := make([]float32, 512)
s_vec := make([]float32, 32) s_vec := make([]float32, 32)
/* Number of channels(1 for mono and 2 for stereo) */ nch := f.numberOfChannels()
nch := 2
if f.header.mode == mpeg1ModeSingleChannel {
nch = 1
}
/* Setup the n_win windowing vector and the v_vec intermediate vector */ /* 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 ss := 0; ss < 18; ss++ { /* Loop through 18 samples in 32 subbands */
for i := 1023; i > 63; i-- { /* Shift up the V vector */ for i := 1023; i > 63; i-- { /* Shift up the V vector */

View File

@ -27,12 +27,7 @@ var mpeg1_scalefac_sizes = [16][2]int{
} }
func (f *frame) readMainL3() error { func (f *frame) readMainL3() error {
/* Number of channels(1 for mono and 2 for stereo) */ nch := f.numberOfChannels()
nch := 2
if f.header.mode == mpeg1ModeSingleChannel {
nch = 1
}
/* Calculate header audio data size */ /* Calculate header audio data size */
framesize := (144* framesize := (144*
g_mpeg1_bitrates[f.header.layer][f.header.bitrate_index])/ g_mpeg1_bitrates[f.header.layer][f.header.bitrate_index])/

View File

@ -39,10 +39,7 @@ var g_mpeg1_bitrates = map[mpeg1Layer][15]int{
var g_sampling_frequency = [3]int{44100, 48000, 32000} var g_sampling_frequency = [3]int{44100, 48000, 32000}
func (f *frame) readAudioL3() error { func (f *frame) readAudioL3() error {
nch := 2 nch := f.numberOfChannels()
if f.header.mode == mpeg1ModeSingleChannel {
nch = 1
}
/* Calculate header audio data size */ /* Calculate header audio data size */
framesize := (144* framesize := (144*
g_mpeg1_bitrates[f.header.layer][f.header.bitrate_index])/ g_mpeg1_bitrates[f.header.layer][f.header.bitrate_index])/