Skip to content

Commit

Permalink
audio: move the implementation for NintendoSDK to Oto
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Aug 12, 2022
1 parent 8081d06 commit dd29255
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 92 deletions.
3 changes: 0 additions & 3 deletions audio/context_oto.go → audio/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
58 changes: 0 additions & 58 deletions audio/context_nintendosdk.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
28 changes: 0 additions & 28 deletions internal/nintendosdk/nintendosdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

0 comments on commit dd29255

Please sign in to comment.