Files
aego/audio/edit/codecsource/analysis_test.go
sanspie 50be5c04bc
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
Stage 12.5: Art Workspace and asset authoring
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.
2026-11-15 10:37:50 +03:00

97 lines
3.1 KiB
Go

package codecsource
import (
"bytes"
"context"
"crypto/sha256"
"fmt"
"math"
"os"
"path/filepath"
"testing"
"aego/audio/codec"
_ "aego/audio/codec/vorbis"
"aego/audio/codec/wav"
"aego/audio/edit"
)
// Compare the bounded random-access analysis to independently decoded PCM,
// not to RenderWindow, on actual WAV and Vorbis decoders.
func TestAnalyzeRealWAVAndOgg(t *testing.T) {
pcm := make([]float32, 2048*2)
for i := range pcm {
pcm[i] = float32(i%41-20) / 24
}
ogg, err := os.ReadFile(filepath.Join("..", "..", "codec", "testdata", "tone.ogg"))
if err != nil {
t.Fatal(err)
}
for _, tc := range []struct {
name string
raw []byte
}{{"synthetic.wav", wav.Encode(pcm, 48000, 2, wav.EncodeOptions{Float: true})}, {"fixture.ogg", ogg}} {
t.Run(tc.name, func(t *testing.T) {
before := sha256.Sum256(tc.raw)
full, err := codec.Open(bytes.NewReader(tc.raw), tc.name)
if err != nil {
t.Fatal(err)
}
info := full.Info()
decoded, err := codec.DecodeAll(full, 0)
closeErr := full.Close()
if err != nil || closeErr != nil || info.Frames < 32 || int64(len(decoded.PCM)) != info.Frames*int64(info.Channels) {
t.Fatalf("cannot sequentially decode source: info=%+v decode=%v close=%v", info, err, closeErr)
}
doc, err := audioedit.New(audioedit.Source{AssetID: "synthetic", Path: tc.name,
SHA256: fmt.Sprintf("%x", before), Codec: "fixture", SampleRate: info.SampleRate,
Channels: info.Channels, Frames: info.Frames})
if err != nil {
t.Fatal(err)
}
region := audioedit.Range{Start: info.Frames / 3, End: info.Frames * 4 / 5}
doc.Trim = region
doc.Operations = []audioedit.Operation{
{Kind: audioedit.Gain, Region: audioedit.Range{Start: 0, End: info.Frames}, Value: .5},
{Kind: audioedit.Reverse, Region: audioedit.Range{Start: 0, End: info.Frames}},
{Kind: audioedit.FadeIn, Region: region},
}
dec, err := codec.Open(bytes.NewReader(tc.raw), tc.name)
if err != nil {
t.Fatal(err)
}
defer dec.Close()
reader, err := New(dec)
if err != nil {
t.Fatal(err)
}
got, err := audioedit.Analyze(context.Background(), reader, doc, region)
if err != nil || got.Frames != region.Length() || len(got.Channels) != info.Channels {
t.Fatalf("analysis dimensions: %+v, %v", got, err)
}
for c := range info.Channels {
peak, sum := 0.0, 0.0
clipped := int64(0)
for frame := region.Start; frame < region.End; frame++ {
original := info.Frames - 1 - frame
fade := float64(frame-region.Start) / float64(region.Length()-1)
value := float64(decoded.PCM[original*int64(info.Channels)+int64(c)]) * .5 * fade
peak = max(peak, math.Abs(value))
sum += value * value
if math.Abs(value) >= 1 {
clipped++
}
}
wantRMS := math.Sqrt(sum / float64(region.Length()))
channel := got.Channels[c]
if math.Abs(channel.Peak-peak) > 1e-6 || math.Abs(channel.RMS-wantRMS) > 1e-6 || channel.ClippedFrames != clipped {
t.Fatalf("channel %d: got %+v, want peak=%g RMS=%g clipped=%d", c, channel, peak, wantRMS, clipped)
}
}
if sha256.Sum256(tc.raw) != before {
t.Fatal("analysis changed the encoded source")
}
})
}
}