mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
audio/mp3: Refactoring
This commit is contained in:
parent
d43df208d2
commit
7b1f3fae99
@ -43,33 +43,24 @@ func readCRC() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *frame) readNextFrame() (*frame, error) {
|
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
|
|
||||||
}
|
|
||||||
h, err := readHeader()
|
h, err := readHeader()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nf.header = h
|
|
||||||
// Get CRC word if present
|
// Get CRC word if present
|
||||||
if nf.header.protection_bit == 0 {
|
if h.protection_bit == 0 {
|
||||||
if err := readCRC(); err != nil {
|
if err := readCRC(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if nf.header.layer != mpeg1Layer3 {
|
if h.layer != mpeg1Layer3 {
|
||||||
return nil, fmt.Errorf("mp3: only layer3 (want %d; got %d) is supported!", mpeg1Layer3, nf.header.layer)
|
return nil, fmt.Errorf("mp3: only layer3 (want %d; got %d) is supported!", mpeg1Layer3, h.layer)
|
||||||
}
|
}
|
||||||
// Get side info
|
// Get side info
|
||||||
s, err := readSideInfo(nf.header)
|
s, err := readSideInfo(h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nf.sideInfo = s
|
|
||||||
// If there's not enough main data in the bit reservoir,
|
// If there's not enough main data in the bit reservoir,
|
||||||
// signal to calling function so that decoding isn't done!
|
// signal to calling function so that decoding isn't done!
|
||||||
// Get main data(scalefactors and Huffman coded frequency data)
|
// Get main data(scalefactors and Huffman coded frequency data)
|
||||||
@ -81,8 +72,17 @@ func (f *frame) readNextFrame() (*frame, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nf.mainData = md
|
nf := &frame{
|
||||||
nf.mainDataBytes = mdb
|
prev: f,
|
||||||
|
header: h,
|
||||||
|
sideInfo: s,
|
||||||
|
mainData: md,
|
||||||
|
mainDataBytes: mdb,
|
||||||
|
}
|
||||||
|
if nf.prev != nil {
|
||||||
|
nf.store = nf.prev.store
|
||||||
|
nf.v_vec = nf.prev.v_vec
|
||||||
|
}
|
||||||
return nf, nil
|
return nf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user