ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Add dockable Art tools, animation and previews, guarded asset workflows, and the Web Asset Studio built on the shared Art Core. Expand English and Russian documentation, interactive Try scenes, examples and editor icons. Add audio waveform navigation, source analysis, guarded previews and a browser Worker mixer. Preserve source changes and recovery with bounded checks, and strengthen native, browser and interoperability CI. Prepare version 0.12.5 and manually built native artifact candidates. Fix the production site image demo build dependency. Reuse immutable scene indices when capturing keyframes. Wait for real Persist save/load completion in component tests. Stabilize browser Game View captures outside pointer hover. Aseprite interchange and persistent Audio EDL recovery remain limited; the artifact workflow does not publish releases or change stable.
105 lines
3.1 KiB
Go
105 lines
3.1 KiB
Go
package codec_test
|
|
|
|
import (
|
|
"math"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"aego/audio/codec"
|
|
"aego/audio/codec/wav"
|
|
"aego/audio/mix"
|
|
)
|
|
|
|
// Decode sequentially from frame zero, independently of SeekFrame.
|
|
func sequentialFramesAt(t *testing.T, data []byte, hint string, start int64, count int) []float32 {
|
|
t.Helper()
|
|
d := open(t, data, hint)
|
|
defer d.Close()
|
|
ch := d.Info().Channels
|
|
buf := make([]float32, 4096*ch)
|
|
for pos := int64(0); pos < start; {
|
|
frames := int(min(int64(4096), start-pos))
|
|
n, err := d.Read(buf[:frames*ch])
|
|
if err != nil || n <= 0 {
|
|
t.Fatalf("sequential reference at %d: %d frames, %v", pos, n, err)
|
|
}
|
|
pos += int64(n)
|
|
}
|
|
out := make([]float32, count*ch)
|
|
for pos := 0; pos < count; {
|
|
n, err := d.Read(out[pos*ch:])
|
|
if err != nil || n <= 0 {
|
|
t.Fatalf("sequential reference at %d+%d: %d frames, %v", start, pos, n, err)
|
|
}
|
|
pos += n
|
|
}
|
|
return out
|
|
}
|
|
|
|
func checkRealStreamStart(t *testing.T, data []byte, hint string, start, loopStart int64, first, count int, tolerance float64) {
|
|
t.Helper()
|
|
d := open(t, data, hint)
|
|
info := d.Info()
|
|
if start+int64(first) > info.Frames || loopStart+int64(count-first) > info.Frames {
|
|
t.Fatalf("fixture too short: %+v", info)
|
|
}
|
|
want := sequentialFramesAt(t, data, hint, start, first)
|
|
want = append(want, sequentialFramesAt(t, data, hint, loopStart, count-first)...)
|
|
s := mix.NewStream(info.SampleRate, info.Channels, count)
|
|
cancel := make(chan struct{})
|
|
done := codec.Stream(d, s, codec.StreamOptions{StartFrame: start, Loop: true,
|
|
LoopStart: loopStart, LoopEnd: start + int64(first), Chunk: 64}, cancel)
|
|
t.Cleanup(func() {
|
|
close(cancel)
|
|
select {
|
|
case err := <-done:
|
|
if err != nil {
|
|
t.Errorf("stream: %v", err)
|
|
}
|
|
case <-time.After(10 * time.Second):
|
|
t.Error("stream did not cancel")
|
|
}
|
|
if err := d.Close(); err != nil {
|
|
t.Error(err)
|
|
}
|
|
})
|
|
deadline := time.NewTimer(10 * time.Second)
|
|
defer deadline.Stop()
|
|
tick := time.NewTicker(time.Millisecond)
|
|
defer tick.Stop()
|
|
for s.Ring.Len() < count {
|
|
select {
|
|
case <-deadline.C:
|
|
t.Fatalf("stream buffered %d frames, want %d", s.Ring.Len(), count)
|
|
case <-tick.C:
|
|
}
|
|
}
|
|
got := make([]float32, count*info.Channels)
|
|
if n := s.Ring.Read(got); n != count {
|
|
t.Fatalf("stream read %d frames, want %d", n, count)
|
|
}
|
|
for i, sample := range got {
|
|
if diff := math.Abs(float64(sample - want[i])); diff > tolerance {
|
|
t.Fatalf("sample %d = %v, sequential reference %v (difference %v)", i, sample, want[i], diff)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestStreamStartRealWAVAndLongVorbis(t *testing.T) {
|
|
t.Run("synthetic stereo WAV", func(t *testing.T) {
|
|
pcm := ramp(2048, 2)
|
|
data := wav.Encode(pcm, 48000, 2, wav.EncodeOptions{Float: true})
|
|
checkRealStreamStart(t, data, "synthetic.wav", 700, 200, 32, 128, 0)
|
|
})
|
|
t.Run("stereo Vorbis at 100 seconds", func(t *testing.T) {
|
|
// Decode the tracked, licensed fixture in memory only; no audio device
|
|
// or user-authored asset is opened for writing.
|
|
data, err := os.ReadFile("../../examples/platformer/assets/audio/glorious-morning.ogg")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
checkRealStreamStart(t, data, "glorious-morning.ogg", 100*44100, 2*44100, 80, 256, 1e-3)
|
|
})
|
|
}
|