mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
audio/internal/convert: Use byte instead of uint8
This commit is contained in:
parent
45deaced69
commit
611cbad5d7
@ -80,8 +80,8 @@ func (f *f32Reader) Read(buf []byte) (int, error) {
|
|||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
f := f.fbuf[i]
|
f := f.fbuf[i]
|
||||||
s := int16(f * (1<<15 - 1))
|
s := int16(f * (1<<15 - 1))
|
||||||
b[2*i] = uint8(s)
|
b[2*i] = byte(s)
|
||||||
b[2*i+1] = uint8(s >> 8)
|
b[2*i+1] = byte(s >> 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(buf) == 1 && len(b) == 2 {
|
if len(buf) == 1 && len(b) == 2 {
|
||||||
|
@ -110,7 +110,7 @@ func (r *Resampling) src(i int64) (float64, float64, error) {
|
|||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf := make([]uint8, resamplingBufferSize*4)
|
buf := make([]byte, resamplingBufferSize*4)
|
||||||
c := 0
|
c := 0
|
||||||
for c < len(buf) {
|
for c < len(buf) {
|
||||||
n, err := r.source.Read(buf[c:])
|
n, err := r.source.Read(buf[c:])
|
||||||
@ -202,7 +202,7 @@ func (r *Resampling) at(t int64) (float64, float64, error) {
|
|||||||
return lv, rv, nil
|
return lv, rv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resampling) Read(b []uint8) (int, error) {
|
func (r *Resampling) Read(b []byte) (int, error) {
|
||||||
if r.pos == r.Length() {
|
if r.pos == r.Length() {
|
||||||
return 0, io.EOF
|
return 0, io.EOF
|
||||||
}
|
}
|
||||||
@ -217,10 +217,10 @@ func (r *Resampling) Read(b []uint8) (int, error) {
|
|||||||
}
|
}
|
||||||
l16 := int16(l * (1<<15 - 1))
|
l16 := int16(l * (1<<15 - 1))
|
||||||
r16 := int16(r * (1<<15 - 1))
|
r16 := int16(r * (1<<15 - 1))
|
||||||
b[4*i] = uint8(l16)
|
b[4*i] = byte(l16)
|
||||||
b[4*i+1] = uint8(l16 >> 8)
|
b[4*i+1] = byte(l16 >> 8)
|
||||||
b[4*i+2] = uint8(r16)
|
b[4*i+2] = byte(r16)
|
||||||
b[4*i+3] = uint8(r16 >> 8)
|
b[4*i+3] = byte(r16 >> 8)
|
||||||
}
|
}
|
||||||
r.pos += int64(n)
|
r.pos += int64(n)
|
||||||
return n, nil
|
return n, nil
|
||||||
|
@ -32,7 +32,7 @@ func NewStereo16(source io.ReadSeeker, mono, eight bool) *Stereo16 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stereo16) Read(b []uint8) (int, error) {
|
func (s *Stereo16) Read(b []byte) (int, error) {
|
||||||
l := len(b)
|
l := len(b)
|
||||||
if s.mono {
|
if s.mono {
|
||||||
l /= 2
|
l /= 2
|
||||||
@ -40,7 +40,7 @@ func (s *Stereo16) Read(b []uint8) (int, error) {
|
|||||||
if s.eight {
|
if s.eight {
|
||||||
l /= 2
|
l /= 2
|
||||||
}
|
}
|
||||||
buf := make([]uint8, l)
|
buf := make([]byte, l)
|
||||||
n, err := s.source.Read(buf)
|
n, err := s.source.Read(buf)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -49,10 +49,10 @@ func (s *Stereo16) Read(b []uint8) (int, error) {
|
|||||||
case s.mono && s.eight:
|
case s.mono && s.eight:
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
v := int16(int(buf[i])*0x101 - (1 << 15))
|
v := int16(int(buf[i])*0x101 - (1 << 15))
|
||||||
b[4*i] = uint8(v)
|
b[4*i] = byte(v)
|
||||||
b[4*i+1] = uint8(v >> 8)
|
b[4*i+1] = byte(v >> 8)
|
||||||
b[4*i+2] = uint8(v)
|
b[4*i+2] = byte(v)
|
||||||
b[4*i+3] = uint8(v >> 8)
|
b[4*i+3] = byte(v >> 8)
|
||||||
}
|
}
|
||||||
case s.mono && !s.eight:
|
case s.mono && !s.eight:
|
||||||
for i := 0; i < n/2; i++ {
|
for i := 0; i < n/2; i++ {
|
||||||
@ -65,10 +65,10 @@ func (s *Stereo16) Read(b []uint8) (int, error) {
|
|||||||
for i := 0; i < n/2; i++ {
|
for i := 0; i < n/2; i++ {
|
||||||
v0 := int16(int(buf[2*i])*0x101 - (1 << 15))
|
v0 := int16(int(buf[2*i])*0x101 - (1 << 15))
|
||||||
v1 := int16(int(buf[2*i+1])*0x101 - (1 << 15))
|
v1 := int16(int(buf[2*i+1])*0x101 - (1 << 15))
|
||||||
b[4*i] = uint8(v0)
|
b[4*i] = byte(v0)
|
||||||
b[4*i+1] = uint8(v0 >> 8)
|
b[4*i+1] = byte(v0 >> 8)
|
||||||
b[4*i+2] = uint8(v1)
|
b[4*i+2] = byte(v1)
|
||||||
b[4*i+3] = uint8(v1 >> 8)
|
b[4*i+3] = byte(v1 >> 8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s.mono {
|
if s.mono {
|
||||||
|
Loading…
Reference in New Issue
Block a user