-
Notifications
You must be signed in to change notification settings - Fork 3
/
gotracker_test.go
117 lines (101 loc) · 2.43 KB
/
gotracker_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main_test
import (
"errors"
"testing"
"time"
"github.com/gotracker/playback/format"
"github.com/gotracker/playback/output"
"github.com/gotracker/playback/player/feature"
"github.com/gotracker/playback/player/machine"
"github.com/gotracker/playback/player/machine/settings"
"github.com/gotracker/playback/player/sampler"
"github.com/gotracker/playback/song"
"github.com/heucuva/optional"
)
func BenchmarkPlayerS3M(b *testing.B) {
var sd song.Data
var sfmt format.Format
var err error
b.Run("load_s3m", func(b *testing.B) {
sd, sfmt, err = format.Load("test/celestial_fantasia.s3m")
if err != nil {
b.Error(err)
}
})
var us settings.UserSettings
us.Reset()
if err := sfmt.ConvertFeaturesToSettings(&us, []feature.Feature{feature.SongLoop{Count: 0}}); err != nil {
b.Error(err)
}
pb, err := machine.NewMachine(sd, us)
if err != nil {
b.Error(err)
}
out := sampler.NewSampler(44100, 2, 0.5, nil)
for err == nil {
b.Run("generate_s3m", func(b *testing.B) {
b.Helper()
b.ReportAllocs()
if err := pb.Tick(out); err != nil {
if !errors.Is(err, song.ErrStopSong) {
b.Error(err)
}
return
}
})
}
}
func BenchmarkIT(b *testing.B) {
var sd song.Data
var sfmt format.Format
var err error
b.Run("load_it", func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
sd, sfmt, err = format.Load(".vscode/test/beyond_the_network.it")
if err != nil {
b.Error(err)
}
}
})
const (
sampleRate = 44100
outputChannels = 2
stereoSeparation = 0.5
stepDuration = time.Duration(sampleRate * outputChannels * 2)
)
var us settings.UserSettings
us.Reset()
if err := sfmt.ConvertFeaturesToSettings(&us, []feature.Feature{
feature.SongLoop{Count: 0},
feature.StartOrderAndRow{Order: optional.NewValue[int](38)},
}); err != nil {
b.Error(err)
}
pb, err := machine.NewMachine(sd, us)
if err != nil {
b.Error(err)
}
var step time.Duration
out := sampler.NewSampler(sampleRate, outputChannels, stereoSeparation, func(premix *output.PremixData) {
if premix != nil {
step += time.Duration(premix.SamplesLen) / stepDuration
b.SetBytes(int64(premix.SamplesLen))
}
})
for err == nil {
b.Run("generate_it", func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := pb.Tick(out); err != nil {
if !errors.Is(err, song.ErrStopSong) {
b.Error(err)
}
return
}
}
})
}
}