audio: Fix examples' performance issue

This commit is contained in:
Hajime Hoshi 2015-06-14 03:27:02 +09:00
parent 00f582d435
commit 564248641b
2 changed files with 14 additions and 16 deletions

View File

@ -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() {

View File

@ -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) {