mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
audio/mp3: Refactoring: Remove mainDataBytes.ptr
This commit is contained in:
parent
ff4529f1e7
commit
782284efd9
@ -148,8 +148,6 @@ func (f *frame) readMainL3() error {
|
|||||||
type mainDataBytes struct {
|
type mainDataBytes struct {
|
||||||
// Large static data
|
// Large static data
|
||||||
vec []int
|
vec []int
|
||||||
// Pointer into the reservoir
|
|
||||||
ptr []int
|
|
||||||
// Index into the current byte(0-7)
|
// Index into the current byte(0-7)
|
||||||
idx int
|
idx int
|
||||||
|
|
||||||
@ -183,7 +181,6 @@ func getMainData(size int, offset int) error {
|
|||||||
}
|
}
|
||||||
theMainDataBytes.vec = append(theMainDataBytes.vec, buf...)
|
theMainDataBytes.vec = append(theMainDataBytes.vec, buf...)
|
||||||
// Set up pointers
|
// Set up pointers
|
||||||
theMainDataBytes.ptr = theMainDataBytes.vec
|
|
||||||
theMainDataBytes.pos = 0
|
theMainDataBytes.pos = 0
|
||||||
theMainDataBytes.idx = 0
|
theMainDataBytes.idx = 0
|
||||||
// TODO: Define a special error and enable to continue the next frame.
|
// TODO: Define a special error and enable to continue the next frame.
|
||||||
@ -208,16 +205,14 @@ func getMainData(size int, offset int) error {
|
|||||||
}
|
}
|
||||||
theMainDataBytes.vec = append(theMainDataBytes.vec, buf...)
|
theMainDataBytes.vec = append(theMainDataBytes.vec, buf...)
|
||||||
// Set up pointers
|
// Set up pointers
|
||||||
theMainDataBytes.ptr = theMainDataBytes.vec
|
|
||||||
theMainDataBytes.pos = 0
|
theMainDataBytes.pos = 0
|
||||||
theMainDataBytes.idx = 0
|
theMainDataBytes.idx = 0
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMainBit() int {
|
func getMainBit() int {
|
||||||
tmp := uint(theMainDataBytes.ptr[0]) >> (7 - uint(theMainDataBytes.idx))
|
tmp := uint(theMainDataBytes.vec[theMainDataBytes.pos]) >> (7 - uint(theMainDataBytes.idx))
|
||||||
tmp &= 0x01
|
tmp &= 0x01
|
||||||
theMainDataBytes.ptr = theMainDataBytes.ptr[(theMainDataBytes.idx+1)>>3:]
|
|
||||||
theMainDataBytes.pos += (theMainDataBytes.idx + 1) >> 3
|
theMainDataBytes.pos += (theMainDataBytes.idx + 1) >> 3
|
||||||
theMainDataBytes.idx = (theMainDataBytes.idx + 1) & 0x07
|
theMainDataBytes.idx = (theMainDataBytes.idx + 1) & 0x07
|
||||||
return int(tmp)
|
return int(tmp)
|
||||||
@ -229,11 +224,7 @@ func getMainBits(num int) int {
|
|||||||
}
|
}
|
||||||
// Form a word of the next four bytes
|
// Form a word of the next four bytes
|
||||||
b := make([]int, 4)
|
b := make([]int, 4)
|
||||||
for i := range b {
|
copy(b, theMainDataBytes.vec[theMainDataBytes.pos:])
|
||||||
if len(theMainDataBytes.ptr) > i {
|
|
||||||
b[i] = theMainDataBytes.ptr[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tmp := (uint32(b[0]) << 24) | (uint32(b[1]) << 16) | (uint32(b[2]) << 8) | (uint32(b[3]) << 0)
|
tmp := (uint32(b[0]) << 24) | (uint32(b[1]) << 16) | (uint32(b[2]) << 8) | (uint32(b[3]) << 0)
|
||||||
|
|
||||||
// Remove bits already used
|
// Remove bits already used
|
||||||
@ -243,7 +234,6 @@ func getMainBits(num int) int {
|
|||||||
tmp = tmp >> (32 - uint(num))
|
tmp = tmp >> (32 - uint(num))
|
||||||
|
|
||||||
// Update pointers
|
// Update pointers
|
||||||
theMainDataBytes.ptr = theMainDataBytes.ptr[(theMainDataBytes.idx+num)>>3:]
|
|
||||||
theMainDataBytes.pos += (theMainDataBytes.idx + num) >> 3
|
theMainDataBytes.pos += (theMainDataBytes.idx + num) >> 3
|
||||||
theMainDataBytes.idx = (theMainDataBytes.idx + num) & 0x07
|
theMainDataBytes.idx = (theMainDataBytes.idx + num) & 0x07
|
||||||
return int(tmp)
|
return int(tmp)
|
||||||
@ -257,7 +247,6 @@ func getMainPos() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setMainPos(bit_pos int) {
|
func setMainPos(bit_pos int) {
|
||||||
theMainDataBytes.ptr = theMainDataBytes.vec[bit_pos>>3:]
|
|
||||||
theMainDataBytes.pos = bit_pos >> 3
|
theMainDataBytes.pos = bit_pos >> 3
|
||||||
theMainDataBytes.idx = bit_pos & 0x7
|
theMainDataBytes.idx = bit_pos & 0x7
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user