mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
audio/mp3: Refactoring getByte(s)
This commit is contained in:
parent
e41c0d3514
commit
e5fbcd50de
@ -59,7 +59,7 @@ func Get_Byte() C.unsigned {
|
||||
}
|
||||
readerCache = buf[:n]
|
||||
}
|
||||
if readerEOF {
|
||||
if len(readerCache) == 0 {
|
||||
return eof
|
||||
}
|
||||
b := readerCache[0]
|
||||
@ -68,16 +68,15 @@ func Get_Byte() C.unsigned {
|
||||
return C.unsigned(b)
|
||||
}
|
||||
|
||||
func getBytes(num int) ([]int, error) {
|
||||
r := make([]int, num)
|
||||
for i := 0; i < num; i++ {
|
||||
func getBytes(buf []int) (int, error) {
|
||||
for i := range buf {
|
||||
v := Get_Byte()
|
||||
if v == eof {
|
||||
return r, io.EOF
|
||||
return i, io.EOF
|
||||
}
|
||||
r[i] = int(v)
|
||||
buf[i] = int(v)
|
||||
}
|
||||
return r, nil
|
||||
return len(buf), nil
|
||||
}
|
||||
|
||||
//export Get_Filepos
|
||||
|
@ -25,6 +25,7 @@ import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
var mpeg1_scalefac_sizes = [16][2]int{
|
||||
@ -183,12 +184,13 @@ func getMainData(size int, begin int) int {
|
||||
// No,there is not,so we skip decoding this frame,but we have to
|
||||
// read the main_data bits from the bitstream in case they are needed
|
||||
// for decoding the next frame.
|
||||
b, err := getBytes(size)
|
||||
if err != nil {
|
||||
buf := make([]int, size)
|
||||
n, err := getBytes(buf)
|
||||
if err != nil && err != io.EOF {
|
||||
g_error = err
|
||||
return C.ERROR
|
||||
}
|
||||
copy(theMainDataBytes.vec[theMainDataBytes.top:], b)
|
||||
copy(theMainDataBytes.vec[theMainDataBytes.top:], buf[:n])
|
||||
/* Set up pointers */
|
||||
theMainDataBytes.ptr = theMainDataBytes.vec[0:]
|
||||
theMainDataBytes.pos = 0
|
||||
@ -201,12 +203,13 @@ func getMainData(size int, begin int) int {
|
||||
theMainDataBytes.vec[i] = theMainDataBytes.vec[theMainDataBytes.top-begin+i]
|
||||
}
|
||||
/* Read the main_data from file */
|
||||
b, err := getBytes(int(size))
|
||||
if err != nil {
|
||||
buf := make([]int, size)
|
||||
n, err := getBytes(buf)
|
||||
if err != nil && err != io.EOF {
|
||||
g_error = err
|
||||
return C.ERROR
|
||||
}
|
||||
copy(theMainDataBytes.vec[begin:], b)
|
||||
copy(theMainDataBytes.vec[begin:], buf[:n])
|
||||
/* Set up pointers */
|
||||
theMainDataBytes.ptr = theMainDataBytes.vec[0:]
|
||||
theMainDataBytes.pos = 0
|
||||
|
@ -24,6 +24,7 @@ import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
var g_mpeg1_bitrates = [3][15]int{
|
||||
@ -138,13 +139,14 @@ type sideInfo struct {
|
||||
var theSideInfo sideInfo
|
||||
|
||||
func getSideinfo(size int) {
|
||||
var err error
|
||||
theSideInfo.vec, err = getBytes(int(size))
|
||||
if err != nil {
|
||||
buf := make([]int, size)
|
||||
n, err := getBytes(buf)
|
||||
if err != nil && err != io.EOF {
|
||||
g_error = fmt.Errorf("mp3: couldn't read sideinfo %d bytes at pos %d: %v",
|
||||
size, Get_Filepos(), err)
|
||||
return
|
||||
}
|
||||
theSideInfo.vec = buf[:n]
|
||||
theSideInfo.idx = 0
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user