audio: Reduce the buffer size (OpenAL)

This commit is contained in:
Hajime Hoshi 2015-01-26 10:14:03 +09:00
parent 6a0c5dfb03
commit 17b7969764
3 changed files with 7 additions and 5 deletions

View File

@ -20,7 +20,6 @@ import (
var audioEnabled = false
const bufferSize = 1024
const SampleRate = 44100
var currentPosition = 0
@ -140,7 +139,7 @@ func isChannelsEmpty() bool {
return true
}
func loadChannelBuffer(channel int) (l, r []int16) {
func loadChannelBuffer(channel int, bufferSize int) (l, r []int16) {
channelsLock.Lock()
defer channelsLock.Unlock()

View File

@ -24,6 +24,8 @@ import (
var nodes = []js.Object{}
var context js.Object
const bufferSize = 1024
func audioProcess(channel int) func(e js.Object) {
return func(e js.Object) {
defer func() {
@ -32,7 +34,7 @@ func audioProcess(channel int) func(e js.Object) {
l := e.Get("outputBuffer").Call("getChannelData", 0)
r := e.Get("outputBuffer").Call("getChannelData", 1)
inputL, inputR := loadChannelBuffer(channel)
inputL, inputR := loadChannelBuffer(channel, bufferSize)
const max = 1 << 15
for i := 0; i < bufferSize; i++ {
// TODO: Use copyFromChannel?

View File

@ -59,12 +59,13 @@ func initialize() {
sources := openal.NewSources(MaxChannel)
close(ch)
const bufferSize = 512
emptyBytes := make([]byte, 4*bufferSize)
for _, source := range sources {
// 3 is the least number?
// http://stackoverflow.com/questions/14932004/play-sound-with-openalstream
const bufferNum = 3
const bufferNum = 4
buffers := openal.NewBuffers(bufferNum)
for _, buffer := range buffers {
buffer.SetData(openal.FormatStereo16, emptyBytes, SampleRate)
@ -88,7 +89,7 @@ func initialize() {
buffers := make([]openal.Buffer, processed)
source.UnqueueBuffers(buffers)
for _, buffer := range buffers {
l, r := loadChannelBuffer(channel)
l, r := loadChannelBuffer(channel, bufferSize)
b := toBytes(l, r)
buffer.SetData(openal.FormatStereo16, b, SampleRate)
source.QueueBuffer(buffer)