2021-12-17 07:03:23 +01:00
|
|
|
// Copyright 2021 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.
|
|
|
|
|
2022-07-09 08:19:47 +02:00
|
|
|
//go:build ebitenginecbackend || ebitencbackend
|
|
|
|
// +build ebitenginecbackend ebitencbackend
|
2021-12-17 07:03:23 +01:00
|
|
|
|
|
|
|
package audio
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2022-08-08 16:57:01 +02:00
|
|
|
"github.com/hajimehoshi/oto/v2/mux"
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/cbackend"
|
2021-12-17 07:03:23 +01:00
|
|
|
)
|
|
|
|
|
2022-07-12 19:08:38 +02:00
|
|
|
func newContext(sampleRate, channelCount, bitDepthInBytes int) (context, chan struct{}, error) {
|
2022-08-08 16:57:01 +02:00
|
|
|
ready := make(chan struct{})
|
|
|
|
close(ready)
|
|
|
|
|
|
|
|
c := &contextProxy{mux.New(sampleRate, channelCount, bitDepthInBytes)}
|
|
|
|
cbackend.OpenAudio(sampleRate, channelCount, c.mux.ReadFloat32s)
|
|
|
|
return c, ready, nil
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// contextProxy is a proxy between cbackend.Context and context.
|
|
|
|
type contextProxy struct {
|
2022-08-08 16:57:01 +02:00
|
|
|
mux *mux.Mux
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewPlayer implements context.
|
|
|
|
func (c *contextProxy) NewPlayer(r io.Reader) player {
|
2022-08-08 16:57:01 +02:00
|
|
|
return c.mux.NewPlayer(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *contextProxy) Suspend() error {
|
|
|
|
// Do nothing so far.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *contextProxy) Resume() error {
|
|
|
|
// Do nothing so far.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *contextProxy) Err() error {
|
|
|
|
return nil
|
2021-12-17 07:03:23 +01:00
|
|
|
}
|