mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
parent
8081d0636a
commit
dd292552d5
@ -12,9 +12,6 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//go:build !nintendosdk
|
|
||||||
// +build !nintendosdk
|
|
||||||
|
|
||||||
package audio
|
package audio
|
||||||
|
|
||||||
import (
|
import (
|
@ -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
|
|
||||||
}
|
|
2
go.mod
2
go.mod
@ -8,7 +8,7 @@ require (
|
|||||||
github.com/hajimehoshi/bitmapfont/v2 v2.2.1
|
github.com/hajimehoshi/bitmapfont/v2 v2.2.1
|
||||||
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41
|
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41
|
||||||
github.com/hajimehoshi/go-mp3 v0.3.3
|
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/jakecoffman/cp v1.2.1
|
||||||
github.com/jezek/xgb v1.0.1
|
github.com/jezek/xgb v1.0.1
|
||||||
github.com/jfreymuth/oggvorbis v1.0.3
|
github.com/jfreymuth/oggvorbis v1.0.3
|
||||||
|
4
go.sum
4
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/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 h1:7cJz/zRQV4aJvMSSRqzN2TImoVVMpE0BCY4nrNJaDOM=
|
||||||
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
|
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.20220812115039-c71b4c444598 h1:n0tfbT3zVTEP+9JEiZ7aMX9JzsiYBTM0jUlu8Wnjves=
|
||||||
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/go.mod h1:ZH5KyijkM53TgspdS9sArUe7vv9EP7x4aNYJAmfGhvE=
|
||||||
github.com/jakecoffman/cp v1.2.1 h1:zkhc2Gpo9l4NLUZfeG3j33+3bQD7MkqPa+n5PdX+5mI=
|
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/jakecoffman/cp v1.2.1/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
|
||||||
github.com/jezek/xgb v1.0.1 h1:YUGhxps0aR7J2Xplbs23OHnV1mWaxFVcOl9b+1RQkt8=
|
github.com/jezek/xgb v1.0.1 h1:YUGhxps0aR7J2Xplbs23OHnV1mWaxFVcOl9b+1RQkt8=
|
||||||
|
@ -50,21 +50,10 @@ package nintendosdk
|
|||||||
// int EbitenGetTouchNum();
|
// int EbitenGetTouchNum();
|
||||||
// void EbitenGetTouches(struct Touch* touches);
|
// void EbitenGetTouches(struct Touch* touches);
|
||||||
// void EbitenVibrateGamepad(int id, double durationInSeconds, double strongMagnitude, double weakMagnitude);
|
// 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 "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Gamepad struct {
|
type Gamepad struct {
|
||||||
@ -161,20 +150,3 @@ func AppendTouches(touches []Touch) []Touch {
|
|||||||
func VibrateGamepad(id int, duration time.Duration, strongMagnitude float64, weakMagnitude float64) {
|
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))
|
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)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user