examples/video: use NewPlayerF32

Updates #2160
This commit is contained in:
Hajime Hoshi 2024-07-22 23:02:47 +09:00
parent b78475ed78
commit e2a93b5d30

View File

@ -18,6 +18,7 @@ import (
"fmt" "fmt"
"image" "image"
"io" "io"
"math"
"sync" "sync"
"time" "time"
@ -108,9 +109,9 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
return nil, fmt.Errorf("video: mpeg audio stream sample rate %d doesn't match with audio context sample rate %d", mpg.Samplerate(), ctx.SampleRate()) return nil, fmt.Errorf("video: mpeg audio stream sample rate %d doesn't match with audio context sample rate %d", mpg.Samplerate(), ctx.SampleRate())
} }
mpg.SetAudioFormat(mpeg.AudioS16) mpg.SetAudioFormat(mpeg.AudioF32N)
audioPlayer, err := ctx.NewPlayer(&mpegAudio{ audioPlayer, err := ctx.NewPlayerF32(&mpegAudio{
audio: mpg.Audio(), audio: mpg.Audio(),
m: &p.m, m: &p.m,
}) })
@ -269,10 +270,13 @@ func (a *mpegAudio) Read(buf []byte) (int, error) {
break break
} }
bs := make([]byte, len(mpegSamples.S16)*2) bs := make([]byte, len(mpegSamples.Interleaved)*4)
for i, s := range mpegSamples.S16 { for i, s := range mpegSamples.Interleaved {
bs[i*2] = byte(s) v := math.Float32bits(s)
bs[i*2+1] = byte(s >> 8) bs[4*i] = byte(v)
bs[4*i+1] = byte(v >> 8)
bs[4*i+2] = byte(v >> 16)
bs[4*i+3] = byte(v >> 24)
} }
n := copy(buf, bs) n := copy(buf, bs)