From a8c27b4eb1b3b137c817b3b9d2760b6fa463fffc Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 24 Jun 2018 04:33:05 +0900 Subject: [PATCH] audio/mp3: Bug fix: float32ArrayToSlice didn't work for Wasm --- audio/mp3/decode_js.go | 2 +- audio/mp3/float32_wasm.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/audio/mp3/decode_js.go b/audio/mp3/decode_js.go index d69d88fbf..7a1076a10 100644 --- a/audio/mp3/decode_js.go +++ b/audio/mp3/decode_js.go @@ -188,7 +188,7 @@ func decode(context *audio.Context, buf []byte, try int) (*Stream, error) { oc := offlineAudioContextClass.New(2, 1, context.SampleRate()) u8 := js.ValueOf(buf) - a := u8.Get("buffer").Call("slice", u8.Get("byteOffset"), u8.Get("byteOffset").Int()+len(buf)) + a := u8.Get("buffer").Call("slice", u8.Get("byteOffset"), u8.Get("byteOffset").Int()+u8.Get("byteLength").Int()) oc.Call("decodeAudioData", a, js.NewCallback(func(args []js.Value) { buf := args[0] diff --git a/audio/mp3/float32_wasm.go b/audio/mp3/float32_wasm.go index a11258c25..b68c89c63 100644 --- a/audio/mp3/float32_wasm.go +++ b/audio/mp3/float32_wasm.go @@ -24,7 +24,8 @@ import ( func float32ArrayToSlice(arr js.Value) []float32 { bytes := make([]byte, arr.Length()*4) - js.ValueOf(bytes).Call("set", arr.Get("buffer")) + buf := arr.Get("buffer").Call("slice", arr.Get("byteOffset"), arr.Get("byteOffset").Int()+arr.Get("byteLength").Int()) + js.ValueOf(bytes).Call("set", js.Global.Get("Uint8Array").New(buf)) bh := (*reflect.SliceHeader)(unsafe.Pointer(&bytes)) var f []float32