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