-
Notifications
You must be signed in to change notification settings - Fork 0
/
spatialize_test.go
144 lines (115 loc) · 5.13 KB
/
spatialize_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package sound
import (
"testing"
"time"
"os"
"github.com/splace/signals"
)
func TestSpatializeReceeding(t *testing.T) {
s:=NewCompositor()
s.Composite=append(s.Composite,Spatialized(NewSound(NewTone(time.Second/440, 1), time.Second/2), vector{0, 0}))
for location:=(vector{2,0}); location.x<10;location.x=location.x+1{
fs := Spatialized(NewSound(NewTone(time.Second/440, 1), time.Second/2), location)
s.Composite=append(s.Composite,After(s.Composite[len(s.Composite)-1].(Sound),fs))
}
wavFile, err := os.Create("./test output/receeding.wav")
if err != nil {
panic(err)
}
defer wavFile.Close()
Encode(wavFile, 1, 8000, s)
}
func TestSpatializeStereo(t *testing.T) {
wavFile, err := os.Create("./test output/stereo.wav")
if err != nil {
panic(err)
}
defer wavFile.Close()
l1,r1:=Stereo(NewSound(NewTone(time.Second/300, 1), time.Second*1), vector{4,1})
l2,r2:=Stereo(Delayed(NewSound(NewTone(time.Second/300, 1), time.Second*1),time.Second*11/10), vector{-4,1})
Encode(wavFile, 1, 16000, NewCompositor(l1,l2),NewCompositor(r1,r2))
}
func TestSpatializeStereoNarrow(t *testing.T) {
wavFile, err := os.Create("./test output/stereoNarrow.wav")
if err != nil {
panic(err)
}
defer wavFile.Close()
l1,r1:=Stereo(NewSound(NewTone(time.Second/300, 1), time.Second*1), vector{1,4})
l2,r2:=Stereo(Delayed(NewSound(NewTone(time.Second/300, 1), time.Second*1),time.Second*11/10), vector{-1,4})
Encode(wavFile, 1, 16000, NewCompositor(l1,l2),NewCompositor(r1,r2))
}
func TestSpatializeStereoVeryNarrow(t *testing.T) {
wavFile, err := os.Create("./test output/stereoVeryNarrow.wav")
if err != nil {
panic(err)
}
defer wavFile.Close()
l1,r1:=Stereo(NewSound(NewTone(time.Second/300, 1), time.Second*1), vector{.25,4})
l2,r2:=Stereo(Delayed(NewSound(NewTone(time.Second/300, 1), time.Second*1),time.Second*11/10), vector{-.25,4})
Encode(wavFile, 1, 16000, NewCompositor(l1,l2),NewCompositor(r1,r2))
}
func TestSpatializeStereoNoise(t *testing.T) {
wavFile, err := os.Create("./test output/stereoNoise.wav")
if err != nil {
panic(err)
}
defer wavFile.Close()
// noise is segmented at 2k, to remove high frequencies, otherwise since noise is white and procedural, it will have infinity frequency components, distroying any phasing.
l1,r1:=Stereo(NewSound(&signals.Segmented{Signal:signals.NewNoise(),Width:signals.X(.0005)}, time.Second/10), vector{4,1})
l2,r2:=Stereo(Delayed(NewSound(&signals.Segmented{Signal:signals.NewNoise(),Width:signals.X(.0005)}, time.Second/10),time.Second*11/100), vector{-4,1})
Encode(wavFile, 4, 44100, NewCompositor(l1,l2),NewCompositor(r1,r2))
}
func TestSpatializeStereoNoiseNarrow(t *testing.T) {
wavFile, err := os.Create("./test output/stereoNoiseNarrow.wav")
if err != nil {
panic(err)
}
defer wavFile.Close()
// noise is segmented at 2k, to remove high frequencies, otherwise since noise is white and procedural, it will have infinity frequency components, distroying any phasing.
l1,r1:=Stereo(NewSound(&signals.Segmented{Signal:signals.NewNoise(),Width:signals.X(.0005)}, time.Second/10), vector{1,4})
l2,r2:=Stereo(Delayed(NewSound(&signals.Segmented{Signal:signals.NewNoise(),Width:signals.X(.0005)}, time.Second/10),time.Second*11/100), vector{-1,4})
Encode(wavFile, 4, 44100, NewCompositor(l1,l2),NewCompositor(r1,r2))
}
func TestSpatializeStereoNoiseVeryNarrow(t *testing.T) {
wavFile, err := os.Create("./test output/stereoNoiseVeryNarrow.wav")
if err != nil {
panic(err)
}
defer wavFile.Close()
// noise is sampled, in a PCM, at the same rate as the eventual encoding, to stop encode sampling from infinite frequencies, and distroying phasing.
l1,r1:=Stereo(signals.NewPCMSignal(signals.NewNoise(), signals.X(.1), 22050, 2) , vector{.25,4})
l2,r2:=Stereo(Delayed(signals.NewPCMSignal(signals.NewNoise(), signals.X(.1), 22050, 2),time.Second*11/100), vector{-.25,4})
Encode(wavFile, 2, 22050, NewCompositor(l1,l2),NewCompositor(r1,r2))
}
func TestSpatializeStereoFrontBackTone(t *testing.T) {
wavFile, err := os.Create("./test output/stereoFrontBackTone.wav")
if err != nil {
panic(err)
}
defer wavFile.Close()
l1,r1:=Stereo(NewSound(NewTone(time.Second/440, 1), time.Second*1), vector{0,4})
l2,r2:=Stereo(Delayed(NewSound(NewTone(time.Second/440, 1), time.Second*1),time.Second*11/10), vector{0,-4})
Encode(wavFile, 2, 22050, NewCompositor(l1,l2),NewCompositor(r1,r2))
}
//
//func TestSpatializePanning(t *testing.T) {
// s1:=NewCompositor()
// s1.Composite=append(s1.Composite,Spatialized(NewSound(NewTone(time.Second/440, 1), time.Second/2), vector{1,0}))
// for location:=(vector{1,1}); location.y<=5;location.y=location.y+1{
// fs := Spatialized(NewSound(NewTone(time.Second/440, 1), time.Second/2), location)
// s1.Composite=append(s1.Composite,After(s1.Composite[len(s1.Composite)-1].(Sound),fs))
// }
// s2:=NewCompositor()
// for si :=range(s1.Composite){
// s2.Composite=append(s2.Composite,Spatialized([]signals.Signal(s1.Composite[si].(signals.Modulated)).[0], location))
// }
// //s2:=NewCompositor(signals.PromoteToSignals(s1)...)
// wavFile, err := os.Create("./test output/panning.wav")
// if err != nil {
// panic(err)
// }
// defer wavFile.Close()
// Encode(wavFile, 1, 8000, s1,s2)
//
//}