-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
89 lines (62 loc) · 1.54 KB
/
main.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
package main
import (
"context"
"fmt"
"os"
"time"
"pipelined.dev/audio"
"pipelined.dev/audio/wav"
"pipelined.dev/pipe"
)
var (
numChannels = 2
bufferSize = 512
)
func main() {
defer PrintElapsedTime(time.Now(), "complete")
PrintMemoryUsage("Start")
mixer := audio.NewMixer(numChannels)
var lines []pipe.Line
for i := 0; i < 4; i++ {
track := &audio.Track{
SampleRate: 22050,
Channels: 2,
}
// This should use a repeat rather than multiple assets
for j := 0; j < 20; j++ {
f, _ := os.Open("./sample.wav")
source := wav.Source{ReadSeeker: f}
asset := audio.Asset{}
// This feels like an unnessecary extra step and causes a copy
l, _ := pipe.Routing{
Source: source.Source(),
Sink: asset.Sink(),
}.Line(bufferSize)
pipe.New(context.Background(), pipe.WithLines(l)).Wait()
f.Close()
// just use the entire asset for now
PrintMemoryUsage(fmt.Sprintf("Track %d - Load asset", i))
track.AddClip(j*4, asset.Floating)
PrintMemoryUsage(fmt.Sprintf("Track %d - Add clip", i))
}
line, _ := pipe.Routing{
Source: track.Source(0, 0),
Sink: mixer.Sink(),
}.Line(bufferSize)
lines = append(lines, line)
}
PrintMemoryUsage("Pre mix")
out, _ := os.Create("demo.wav")
defer out.Close()
sink := &wav.Sink{
WriteSeeker: out,
BitDepth: 16,
}
line, _ := pipe.Routing{
Source: mixer.Source(),
Sink: sink.Sink(),
}.Line(bufferSize)
lines = append(lines, line)
pipe.New(context.Background(), pipe.WithLines(lines...)).Wait()
PrintMemoryUsage("Post mix")
}