audio: Use a new implentation for go2cpp in Oto

This commit is contained in:
Hajime Hoshi 2020-12-30 19:21:15 +09:00
parent 2ea360b921
commit f292594184
5 changed files with 4 additions and 83 deletions

View File

@ -41,7 +41,7 @@ func newContext(sampleRate int) context {
})
return nil
})
return newContextImpl(sampleRate, ch)
return newOtoContext(sampleRate, ch)
}
type hook interface {

View File

@ -1,58 +0,0 @@
// Copyright 2020 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.
package audio
import (
"io"
"syscall/js"
"time"
)
type nullContext struct {
sampleRate int
}
type nullPlayer struct {
sampleRate int
}
func (c *nullContext) NewPlayer() io.WriteCloser {
return &nullPlayer{
sampleRate: c.sampleRate,
}
}
func (c *nullContext) Close() error {
return nil
}
func (p *nullPlayer) Write(data []byte) (int, error) {
time.Sleep(time.Second * time.Duration(len(data)) / time.Duration(p.sampleRate*4))
return len(data), nil
}
func (p *nullPlayer) Close() error {
return nil
}
func newContextImpl(sampleRate int, initCh chan struct{}) context {
if js.Global().Get("go2cpp").Truthy() {
return &nullContext{
sampleRate: sampleRate,
}
}
return newOtoContext(sampleRate, initCh)
}

View File

@ -1,21 +0,0 @@
// Copyright 2020 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
func newContextImpl(sampleRate int, initCh chan struct{}) context {
return newOtoContext(sampleRate, initCh)
}

2
go.mod
View File

@ -8,7 +8,7 @@ require (
github.com/hajimehoshi/bitmapfont/v2 v2.1.2
github.com/hajimehoshi/file2byteslice v0.0.0-20200812174855-0e5e8a80490e
github.com/hajimehoshi/go-mp3 v0.3.1
github.com/hajimehoshi/oto v0.7.1-0.20201228073136-270ab3177703
github.com/hajimehoshi/oto v0.7.1-0.20201230101839-5e94ce585867
github.com/jakecoffman/cp v1.0.0
github.com/jfreymuth/oggvorbis v1.0.1
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect

4
go.sum
View File

@ -11,8 +11,8 @@ github.com/hajimehoshi/go-mp3 v0.3.1 h1:pn/SKU1+/rfK8KaZXdGEC2G/KCB2aLRjbTCrwKco
github.com/hajimehoshi/go-mp3 v0.3.1/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/oto v0.6.1 h1:7cJz/zRQV4aJvMSSRqzN2TImoVVMpE0BCY4nrNJaDOM=
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/hajimehoshi/oto v0.7.1-0.20201228073136-270ab3177703 h1:Nh8XNwz8eZpMkLwFdUSaRuSSQPUqFxtd3tvx/8lp5zw=
github.com/hajimehoshi/oto v0.7.1-0.20201228073136-270ab3177703/go.mod h1:wovJ8WWMfFKvP587mhHgot/MBr4DnNy9m6EepeVGnos=
github.com/hajimehoshi/oto v0.7.1-0.20201230101839-5e94ce585867 h1:Qw98pkw5fCNsyXu5wZXF4k4KrSWVP2sSb+o6Znn2te0=
github.com/hajimehoshi/oto v0.7.1-0.20201230101839-5e94ce585867/go.mod h1:wovJ8WWMfFKvP587mhHgot/MBr4DnNy9m6EepeVGnos=
github.com/jakecoffman/cp v1.0.0 h1:4qi6RDQxnEgH2aonA5Wa67VYy9onrlzsIg0Uk7tlf0o=
github.com/jakecoffman/cp v1.0.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
github.com/jfreymuth/oggvorbis v1.0.1 h1:NT0eXBgE2WHzu6RT/6zcb2H10Kxj6Fm3PccT0LE6bqw=