mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
audio: Better conversion from 8bit to 16bit
This commit is contained in:
parent
f9ab7d9043
commit
abd0958566
@ -50,7 +50,7 @@ func (s *Stereo16) Read(b []uint8) (int, error) {
|
|||||||
switch {
|
switch {
|
||||||
case s.mono && s.eight:
|
case s.mono && s.eight:
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
v := (int16(buf[i]) - 128) << 8
|
v := int16(int(buf[i])*0x101 - (1 << 15))
|
||||||
b[4*i] = uint8(v)
|
b[4*i] = uint8(v)
|
||||||
b[4*i+1] = uint8(v >> 8)
|
b[4*i+1] = uint8(v >> 8)
|
||||||
b[4*i+2] = uint8(v)
|
b[4*i+2] = uint8(v)
|
||||||
@ -65,8 +65,8 @@ func (s *Stereo16) Read(b []uint8) (int, error) {
|
|||||||
}
|
}
|
||||||
case !s.mono && s.eight:
|
case !s.mono && s.eight:
|
||||||
for i := 0; i < n/2; i++ {
|
for i := 0; i < n/2; i++ {
|
||||||
v0 := (int16(buf[2*i]) - 128) << 8
|
v0 := int16(int(buf[2*i])*0x101 - (1 << 15))
|
||||||
v1 := (int16(buf[2*i+1]) - 128) << 8
|
v1 := int16(int(buf[2*i+1])*0x101 - (1 << 15))
|
||||||
b[4*i] = uint8(v0)
|
b[4*i] = uint8(v0)
|
||||||
b[4*i+1] = uint8(v0 >> 8)
|
b[4*i+1] = uint8(v0 >> 8)
|
||||||
b[4*i+2] = uint8(v1)
|
b[4*i+2] = uint8(v1)
|
||||||
|
Loading…
Reference in New Issue
Block a user