-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrender.go
More file actions
79 lines (63 loc) · 1.77 KB
/
render.go
File metadata and controls
79 lines (63 loc) · 1.77 KB
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
package voice
import (
"github.com/gotracker/playback/mixing"
"github.com/gotracker/playback/mixing/panning"
"github.com/gotracker/playback/mixing/sampling"
"github.com/gotracker/playback/mixing/volume"
"github.com/gotracker/playback/period"
"github.com/gotracker/playback/voice/mixer"
)
func RenderAndTick[TPeriod Period](in Voice, pc period.PeriodConverter[TPeriod], centerAheadPan panning.PanMixer, details mixer.Details, out mixer.ApplyFilter) (*mixing.Data, error) {
if in.IsDone() {
return nil, nil
}
defer in.Tick()
rs, ok := in.(RenderSampler[TPeriod])
if !ok {
return nil, nil
}
if !rs.IsActive() {
return nil, nil
}
pos, err := rs.GetPos()
if err != nil {
return nil, err
}
p, err := rs.GetFinalPeriod()
if err != nil {
return nil, err
}
if err := in.SetPlaybackRate(details.SampleRate); err != nil {
return nil, err
}
samplerAdd := float32(pc.GetSamplerAdd(p, rs.GetSampleRate(), details.SampleRate))
o := mixer.Output{
Input: rs,
Output: out,
}
sampler := sampling.NewSampler(&o, pos, samplerAdd)
// ... so grab the new value now.
pan := rs.GetFinalPan()
// make a stand-alone data buffer for this channel for this tick
sampleData := mixing.SampleMixIn{
Sample: sampler,
StaticVol: volume.Volume(1.0),
PanMatrix: centerAheadPan,
MixPos: 0,
MixLen: details.Samples,
}
mixBuffer := details.Mix.NewMixBuffer(details.Samples)
mixBuffer.MixInSample(sampleData)
data := &mixing.Data{
Data: mixBuffer,
PanMatrix: details.Panmixer.GetMixingMatrix(pan, details.StereoSeparation),
Volume: volume.Volume(1.0),
Pos: 0,
SamplesLen: details.Samples,
}
// reflect the sampling position back to the voice
if err := rs.SetPos(sampler.GetPosition()); err != nil {
return nil, err
}
return data, nil
}