diff --git a/audio/context_oto.go b/audio/context.go similarity index 96% rename from audio/context_oto.go rename to audio/context.go index c0891a36e198..e25e75e118de 100644 --- a/audio/context_oto.go +++ b/audio/context.go @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !nintendosdk -// +build !nintendosdk - package audio import ( diff --git a/audio/context_nintendosdk.go b/audio/context_nintendosdk.go deleted file mode 100644 index f63c9386f98b..000000000000 --- a/audio/context_nintendosdk.go +++ /dev/null @@ -1,58 +0,0 @@ -// 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. - -//go:build nintendosdk -// +build nintendosdk - -package audio - -import ( - "io" - - "github.com/hajimehoshi/oto/v2/mux" - - "github.com/hajimehoshi/ebiten/v2/internal/nintendosdk" -) - -func newContext(sampleRate, channelCount, bitDepthInBytes int) (context, chan struct{}, error) { - ready := make(chan struct{}) - close(ready) - - c := &contextProxy{mux.New(sampleRate, channelCount, bitDepthInBytes)} - nintendosdk.OpenAudio(sampleRate, channelCount, c.mux.ReadFloat32s) - return c, ready, nil -} - -type contextProxy struct { - mux *mux.Mux -} - -// NewPlayer implements context. -func (c *contextProxy) NewPlayer(r io.Reader) player { - 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 -} diff --git a/go.mod b/go.mod index 2ac5f0ae852f..c03666251e0f 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/hajimehoshi/bitmapfont/v2 v2.2.1 github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41 github.com/hajimehoshi/go-mp3 v0.3.3 - github.com/hajimehoshi/oto/v2 v2.3.0-alpha.6.0.20220808142854-0d70fdd8205d + github.com/hajimehoshi/oto/v2 v2.3.0-alpha.6.0.20220812115039-c71b4c444598 github.com/jakecoffman/cp v1.2.1 github.com/jezek/xgb v1.0.1 github.com/jfreymuth/oggvorbis v1.0.3 diff --git a/go.sum b/go.sum index 013b97a5eb36..c5967bc1a9dc 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,8 @@ github.com/hajimehoshi/go-mp3 v0.3.3 h1:cWnfRdpye2m9ElSoVqneYRcpt/l3ijttgjMeQh+r github.com/hajimehoshi/go-mp3 v0.3.3/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/v2 v2.3.0-alpha.6.0.20220808142854-0d70fdd8205d h1:T64feTPB+qGhPnLRsyzlYNiz+jTd/pcPCqB8/VTgooY= -github.com/hajimehoshi/oto/v2 v2.3.0-alpha.6.0.20220808142854-0d70fdd8205d/go.mod h1:ZH5KyijkM53TgspdS9sArUe7vv9EP7x4aNYJAmfGhvE= +github.com/hajimehoshi/oto/v2 v2.3.0-alpha.6.0.20220812115039-c71b4c444598 h1:n0tfbT3zVTEP+9JEiZ7aMX9JzsiYBTM0jUlu8Wnjves= +github.com/hajimehoshi/oto/v2 v2.3.0-alpha.6.0.20220812115039-c71b4c444598/go.mod h1:ZH5KyijkM53TgspdS9sArUe7vv9EP7x4aNYJAmfGhvE= github.com/jakecoffman/cp v1.2.1 h1:zkhc2Gpo9l4NLUZfeG3j33+3bQD7MkqPa+n5PdX+5mI= github.com/jakecoffman/cp v1.2.1/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg= github.com/jezek/xgb v1.0.1 h1:YUGhxps0aR7J2Xplbs23OHnV1mWaxFVcOl9b+1RQkt8= diff --git a/internal/nintendosdk/nintendosdk.go b/internal/nintendosdk/nintendosdk.go index 2c491efbec76..b06e0664b381 100644 --- a/internal/nintendosdk/nintendosdk.go +++ b/internal/nintendosdk/nintendosdk.go @@ -50,21 +50,10 @@ package nintendosdk // int EbitenGetTouchNum(); // void EbitenGetTouches(struct Touch* touches); // void EbitenVibrateGamepad(int id, double durationInSeconds, double strongMagnitude, double weakMagnitude); -// -// // Audio -// typedef void (*OnReadCallback)(float* buf, size_t length); -// void EbitenOpenAudio(int sample_rate, int channel_num, OnReadCallback on_read_callback); -// -// void EbitenAudioOnReadCallback(float* buf, size_t length); -// static void EbitenOpenAudioProxy(int sample_rate, int channel_num) { -// EbitenOpenAudio(sample_rate, channel_num, EbitenAudioOnReadCallback); -// } import "C" import ( - "reflect" "time" - "unsafe" ) type Gamepad struct { @@ -161,20 +150,3 @@ func AppendTouches(touches []Touch) []Touch { func VibrateGamepad(id int, duration time.Duration, strongMagnitude float64, weakMagnitude float64) { C.EbitenVibrateGamepad(C.int(id), C.double(float64(duration)/float64(time.Second)), C.double(strongMagnitude), C.double(weakMagnitude)) } - -var onReadCallback func(buf []float32) - -func OpenAudio(sampleRate, channelCount int, onRead func(buf []float32)) { - C.EbitenOpenAudioProxy(C.int(sampleRate), C.int(channelCount)) - onReadCallback = onRead -} - -//export EbitenAudioOnReadCallback -func EbitenAudioOnReadCallback(buf *C.float, length C.size_t) { - var s []float32 - h := (*reflect.SliceHeader)(unsafe.Pointer(&s)) - h.Data = uintptr(unsafe.Pointer(buf)) - h.Len = int(length) - h.Cap = int(length) - onReadCallback(s) -}