mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio: Fix examples' performance issue
This commit is contained in:
parent
00f582d435
commit
564248641b
@ -15,8 +15,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
@ -76,13 +74,14 @@ func toBytes(l, r []int16) []byte {
|
||||
if len(l) != len(r) {
|
||||
panic("len(l) must equal to len(r)")
|
||||
}
|
||||
b := &bytes.Buffer{}
|
||||
for i := 0; i < len(l); i++ {
|
||||
if err := binary.Write(b, binary.LittleEndian, []int16{l[i], r[i]}); err != nil {
|
||||
panic(err)
|
||||
b := make([]byte, len(l)*4)
|
||||
for i, _ := range l {
|
||||
b[4*i] = byte(l[i])
|
||||
b[4*i+1] = byte(l[i] >> 8)
|
||||
b[4*i+2] = byte(r[i])
|
||||
b[4*i+3] = byte(r[i] >> 8)
|
||||
}
|
||||
}
|
||||
return b.Bytes()
|
||||
return b
|
||||
}
|
||||
|
||||
func addNote() {
|
||||
|
@ -15,8 +15,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"log"
|
||||
@ -60,13 +58,14 @@ func toBytes(l, r []int16) []byte {
|
||||
if len(l) != len(r) {
|
||||
panic("len(l) must equal to len(r)")
|
||||
}
|
||||
b := &bytes.Buffer{}
|
||||
for i := 0; i < len(l); i++ {
|
||||
if err := binary.Write(b, binary.LittleEndian, []int16{l[i], r[i]}); err != nil {
|
||||
panic(err)
|
||||
b := make([]byte, len(l)*4)
|
||||
for i, _ := range l {
|
||||
b[4*i] = byte(l[i])
|
||||
b[4*i+1] = byte(l[i] >> 8)
|
||||
b[4*i+2] = byte(r[i])
|
||||
b[4*i+3] = byte(r[i] >> 8)
|
||||
}
|
||||
}
|
||||
return b.Bytes()
|
||||
return b
|
||||
}
|
||||
|
||||
func addNote(freq float64, vol float64) {
|
||||
|
Loading…
Reference in New Issue
Block a user