audio/mp3: Bug fix: float32ArrayToSlice didn't work for Wasm

This commit is contained in:
Hajime Hoshi 2018-06-24 04:33:05 +09:00
parent baee2ba4c9
commit a8c27b4eb1
2 changed files with 3 additions and 2 deletions

View File

@ -188,7 +188,7 @@ func decode(context *audio.Context, buf []byte, try int) (*Stream, error) {
oc := offlineAudioContextClass.New(2, 1, context.SampleRate()) oc := offlineAudioContextClass.New(2, 1, context.SampleRate())
u8 := js.ValueOf(buf) 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) { oc.Call("decodeAudioData", a, js.NewCallback(func(args []js.Value) {
buf := args[0] buf := args[0]

View File

@ -24,7 +24,8 @@ import (
func float32ArrayToSlice(arr js.Value) []float32 { func float32ArrayToSlice(arr js.Value) []float32 {
bytes := make([]byte, arr.Length()*4) 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)) bh := (*reflect.SliceHeader)(unsafe.Pointer(&bytes))
var f []float32 var f []float32