mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 17:32:02 +01:00
parent
bd1fc4439a
commit
1cf3022ce6
@ -38,28 +38,51 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DecodeVorbis(buf []byte) ([]float32, int, int, error) {
|
func DecodeVorbis(buf []byte) ([]float32, int, int, error) {
|
||||||
var r js.Value
|
ch := make(chan error)
|
||||||
ch := make(chan struct{})
|
data := []float32{}
|
||||||
arr := js.TypedArrayOf(buf)
|
channels := 0
|
||||||
|
sampleRate := 0
|
||||||
|
|
||||||
var f js.Callback
|
var f js.Callback
|
||||||
f = js.NewCallback(func(args []js.Value) {
|
f = js.NewCallback(func(args []js.Value) {
|
||||||
r = args[0]
|
r := args[0]
|
||||||
|
|
||||||
|
if e := r.Get("error"); e != js.Null() {
|
||||||
|
ch <- fmt.Errorf("audio/vorbis/internal/stb: decode error: %s", e.String())
|
||||||
close(ch)
|
close(ch)
|
||||||
f.Release()
|
f.Release()
|
||||||
})
|
return
|
||||||
js.Global().Get("stbvorbis").Call("decode", arr).Call("then", f)
|
}
|
||||||
arr.Release()
|
|
||||||
<-ch
|
if r.Get("eof").Bool() {
|
||||||
|
close(ch)
|
||||||
if r == js.Null() {
|
f.Release()
|
||||||
return nil, 0, 0, fmt.Errorf("audio/vorbis/internal/stb: decode failed")
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if channels == 0 {
|
||||||
|
channels = r.Get("data").Length()
|
||||||
|
}
|
||||||
|
if sampleRate == 0 {
|
||||||
|
sampleRate = r.Get("sampleRate").Int()
|
||||||
}
|
}
|
||||||
|
|
||||||
channels := r.Get("data").Length()
|
|
||||||
flattened := flatten.Invoke(r.Get("data"))
|
flattened := flatten.Invoke(r.Get("data"))
|
||||||
data := make([]float32, flattened.Length())
|
d := make([]float32, flattened.Length())
|
||||||
arr = js.TypedArrayOf(data)
|
arr := js.TypedArrayOf(d)
|
||||||
arr.Call("set", flattened)
|
arr.Call("set", flattened)
|
||||||
arr.Release()
|
arr.Release()
|
||||||
return data, channels, r.Get("sampleRate").Int(), nil
|
|
||||||
|
data = append(data, d...)
|
||||||
|
})
|
||||||
|
|
||||||
|
arr := js.TypedArrayOf(buf)
|
||||||
|
js.Global().Get("stbvorbis").Call("decode", arr, f)
|
||||||
|
arr.Release()
|
||||||
|
|
||||||
|
if err := <-ch; err != nil {
|
||||||
|
return nil, 0, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, channels, sampleRate, nil
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user