mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
audio: Adjust the buffer size
This commit is contained in:
parent
3454b32cb6
commit
c3202b8e58
@ -250,10 +250,7 @@ func (c *Context) loop() {
|
|||||||
// e.g. a variable for JVM on Android might not be set.
|
// e.g. a variable for JVM on Android might not be set.
|
||||||
<-c.initCh
|
<-c.initCh
|
||||||
|
|
||||||
// The buffer size is 1/15 sec.
|
p, err := oto.NewPlayer(c.sampleRate, channelNum, bytesPerSample, c.bufferSize())
|
||||||
// It looks like 1/20 sec is too short for Android.
|
|
||||||
s := c.sampleRate * channelNum * bytesPerSample / 15
|
|
||||||
p, err := oto.NewPlayer(c.sampleRate, channelNum, bytesPerSample, s)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.errCh <- err
|
c.errCh <- err
|
||||||
return
|
return
|
||||||
|
22
audio/buffersize.go
Normal file
22
audio/buffersize.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2017 The Ebiten Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build !js
|
||||||
|
// +build !ios
|
||||||
|
|
||||||
|
package audio
|
||||||
|
|
||||||
|
func (c *Context) bufferSize() int {
|
||||||
|
return c.sampleRate * channelNum * bytesPerSample / 30
|
||||||
|
}
|
22
audio/buffersize_ios.go
Normal file
22
audio/buffersize_ios.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2017 The Ebiten Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build ios
|
||||||
|
|
||||||
|
package audio
|
||||||
|
|
||||||
|
func (c *Context) bufferSize() int {
|
||||||
|
// TODO: Fix after oto uses HAL on Darwin.
|
||||||
|
return c.sampleRate * channelNum * bytesPerSample / 20
|
||||||
|
}
|
29
audio/buffersize_js.go
Normal file
29
audio/buffersize_js.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2017 The Ebiten Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build js
|
||||||
|
|
||||||
|
package audio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/web"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Context) bufferSize() int {
|
||||||
|
n := 30
|
||||||
|
if web.IsMobileBrowser() {
|
||||||
|
n = 10
|
||||||
|
}
|
||||||
|
return c.sampleRate * channelNum * bytesPerSample / n
|
||||||
|
}
|
@ -17,32 +17,11 @@
|
|||||||
package restorable
|
package restorable
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"github.com/hajimehoshi/ebiten/internal/web"
|
||||||
|
|
||||||
"github.com/gopherjs/gopherjs/js"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func isIOS() bool {
|
|
||||||
ua := js.Global.Get("navigator").Get("userAgent").String()
|
|
||||||
if !strings.Contains(ua, "iPhone") {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func isAndroidChrome() bool {
|
|
||||||
ua := js.Global.Get("navigator").Get("userAgent").String()
|
|
||||||
if !strings.Contains(ua, "Android") {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if !strings.Contains(ua, "Chrome") {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if isIOS() || isAndroidChrome() {
|
if web.IsMobileBrowser() {
|
||||||
restoringEnabled = false
|
restoringEnabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
46
internal/web/mobile.go
Normal file
46
internal/web/mobile.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright 2017 The Ebiten Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build js
|
||||||
|
|
||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gopherjs/gopherjs/js"
|
||||||
|
)
|
||||||
|
|
||||||
|
func isIOS() bool {
|
||||||
|
ua := js.Global.Get("navigator").Get("userAgent").String()
|
||||||
|
if !strings.Contains(ua, "iPhone") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func isAndroidChrome() bool {
|
||||||
|
ua := js.Global.Get("navigator").Get("userAgent").String()
|
||||||
|
if !strings.Contains(ua, "Android") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !strings.Contains(ua, "Chrome") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsMobileBrowser() bool {
|
||||||
|
return isIOS() || isAndroidChrome()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user