ci-platforms / darwin amd64 smoke (push) Skipped
ci-platforms / windows amd64 smoke (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
ci / checks (push) Successful in 8m33s
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m38s
ci / release (push) Successful in 9m25s
make web-bench measures the exported platformer in Chromium and Firefox in lockstep, with exact WebGL counters against a per-mode baseline, time compared with Mann-Whitney and a profile pass that gates allocations in the engine frame to zero, except listed first-decode and growth sites. On the web the frame loop fills the audio output, the stream feeder waits for ring space, per-event allocations are gone and Go allocations per frame drop from 7.2 to 3.8 in Chromium. The pixel ratio is capped at 1.5 by default (display.maxPixelRatio) and Frame Limit works on the web. The game loop stays on the main thread; a Worker is not built (D391).
80 lines
1.9 KiB
Go
80 lines
1.9 KiB
Go
package pump
|
|
|
|
import (
|
|
"testing"
|
|
"testing/synctest"
|
|
"time"
|
|
|
|
"aego/audio/mix"
|
|
)
|
|
|
|
type sink struct {
|
|
channels int
|
|
muted bool
|
|
writes int
|
|
}
|
|
|
|
func (s *sink) Write(samples []float32) int {
|
|
s.writes++
|
|
return len(samples) / s.channels
|
|
}
|
|
func (*sink) Queued() int { return 0 }
|
|
func (*sink) Close() {}
|
|
func (s *sink) Muted() bool { return s.muted }
|
|
|
|
func TestPumpSleepsWithoutVoices(t *testing.T) {
|
|
synctest.Test(t, func(t *testing.T) {
|
|
m, err := mix.New(mix.Config{SampleRate: 48000, Channels: 2})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p := New(m, &sink{channels: 2}, Config{})
|
|
p.Start()
|
|
defer p.Stop()
|
|
synctest.Wait()
|
|
idle := p.Stats().Blocks
|
|
if idle == 0 {
|
|
t.Fatal("the pump did not prime the output")
|
|
}
|
|
time.Sleep(time.Second)
|
|
synctest.Wait()
|
|
if got := p.Stats().Blocks; got != idle {
|
|
t.Fatalf("an idle pump mixed %d blocks in a second", got-idle)
|
|
}
|
|
m.PauseAll()
|
|
synctest.Wait()
|
|
if got := p.Stats().Blocks; got == idle {
|
|
t.Fatal("a command did not wake the pump")
|
|
}
|
|
})
|
|
}
|
|
|
|
// While the output is muted the pump writes nothing and moves voices on by the time that passed, so they still end.
|
|
func TestPumpSkipsWhileMuted(t *testing.T) {
|
|
synctest.Test(t, func(t *testing.T) {
|
|
m, err := mix.New(mix.Config{SampleRate: 48000, Channels: 2})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out := &sink{channels: 2, muted: true}
|
|
p := New(m, out, Config{})
|
|
pcm := make([]float32, 48000)
|
|
id := m.Play(mix.PlayParams{Memory: &mix.Memory{PCM: pcm, Rate: 48000, Channels: 1}, Gain: 1})
|
|
p.Start()
|
|
defer p.Stop()
|
|
time.Sleep(500 * time.Millisecond)
|
|
synctest.Wait()
|
|
if !m.Live(id) {
|
|
t.Fatal("a one-second voice ended after half a second")
|
|
}
|
|
time.Sleep(time.Second)
|
|
synctest.Wait()
|
|
if m.Live(id) || m.Active() != 0 {
|
|
t.Fatal("the voice did not end while muted")
|
|
}
|
|
if out.writes != 0 {
|
|
t.Fatalf("the pump wrote %d blocks to a muted output", out.writes)
|
|
}
|
|
})
|
|
}
|