audio: Refactor test files

This commit is contained in:
Hajime Hoshi 2021-01-07 01:37:29 +09:00
parent bda285b376
commit e04e709a10
3 changed files with 15 additions and 30 deletions

View File

@ -55,7 +55,7 @@ const (
//
// For a typical usage example, see examples/wav/main.go.
type Context struct {
c writerContext
wc writerContext
// inited represents whether the audio device is initialized and available or not.
// On Android, audio loop cannot be started unless JVM is accessible. After updating one frame, JVM should exist.
@ -97,7 +97,7 @@ func NewContext(sampleRate int) *Context {
c := &Context{
sampleRate: sampleRate,
c: newWriterContext(sampleRate),
wc: newWriterContext(sampleRate),
players: map[playerImpl]struct{}{},
inited: make(chan struct{}),
semaphore: make(chan struct{}, 1),
@ -268,7 +268,7 @@ type playerImpl interface {
// A Player doesn't close src even if src implements io.Closer.
// Closing the source is src owner's responsibility.
func NewPlayer(context *Context, src io.Reader) (*Player, error) {
pi, err := newWriterContextPlayerImpl(context, context.c, src)
pi, err := newWriterContextPlayerImpl(context, context.wc, src)
if err != nil {
return nil, err
}

View File

@ -69,3 +69,15 @@ func UpdateForTesting() error {
}
return nil
}
func PlayersNumForTesting() int {
c := CurrentContext()
c.m.Lock()
n := len(c.players)
c.m.Unlock()
return n
}
func ResetContext() {
theContext = nil
}

View File

@ -1,27 +0,0 @@
// Copyright 2018 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
func PlayersNumForTesting() int {
c := CurrentContext()
c.m.Lock()
n := len(c.players)
c.m.Unlock()
return n
}
func ResetContext() {
theContext = nil
}