-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstreams_test.go
107 lines (88 loc) · 6.67 KB
/
streams_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
package signals
import (
"os"
"testing"
"net"
"net/url"
)
const testLocalURL="http://localhost:8086/wavs/s16/4.wav?f=8000"
const testRemoteURL="http://www.nch.com.au/acm/8k8bitpcm.wav" //const testRemoteURL="http://localhost:8086/wavs/s16/4.wav?f=8000" //
const testDataURL="data:audio/x-wav;base64,UklGRqILAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YX4LAACzAKEB+/5w93r/1QFYCRcFN/+N/gf8vfu6APYA2APh/fQBx/42AGP+rgmoEuvpu+upIa0VSej9/R77HQjp7mUNywkVyqoX1xkA7bG73Pb2afYibsrm2rMhHzUh8MLCygmPFWX94Qc583AIvPMJ/qX9T+DnBXEtATxT7rC95+0QKmcCOcOBI1kh/QZGAgbnbv78uyMJ0CLa6ez+uxYIW6n3hZmq5tMkOSIS9Hj35CdADYzZhs3s9f0h5xx0AVvmfPaRElM2JiTmxMe5ggmRVHMlGMS902wIwQwk9kn9LQhoABT5jvzgCncG1AEaBOwEBvH67YsSWASz+D0bQww07LzmVe44BvgLWf4u+NEKPgpWAPoISvyL537Zrwc1NMUed/xR2mvxGQhRBNsJLAE1/fnx8PwaFTEAqeVT/VsNIhAOD/0EtwIz3M/l3RTYHbcGaPIXBr/9ReyU5f32wgleBLAVuA8h+wbvAfcqCuX5/+Rz96AbZR87AMPpK/XT9IXwcP/CDZUPhgTWBxQDUvLO7t0Aygd+/R0H3AplAX31W/cT/8n4jAXHDUz2TvQ+AhcO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+vQBZAHEAdAHx/b/8/f3r/7AEBAbdAkUC3AAY/qT8IPzO/v4CuQSIAtMCFgSn/07+bgAF/9D9lf8kAssCNgC1/lkAzAA4AI4BigImAIn9avsK/JkBNQPPAUQCMACv/pj+VfyJ/Gr+jQHOBA=="
const testFileURL="file:///home/simon/Dropbox/github/working/signals/middlec.wav"
const testGOBFile="/home/simon/Dropbox/github/working/signals/test output/RingingTone"
func TestStreamsRemoteSave(t *testing.T) {
s,err:=NewWave(testRemoteURL)
if err!=nil{
if ue,ok:=err.(*url.Error);ok {
if oe,ok:=ue.Err.(*net.OpError);ok{
if se,ok:=oe.Err.(*os.SyscallError);ok{
if se.Err.Error()=="connection refused"{
t.Skip(ue.Error())
}
}
}
}
t.Fatal(err)
}
file, err := os.Create("./test output/remoteStream.wav")
if err != nil {panic(err)}
defer file.Close()
Encode(file, 1, 8000, unitX*3, s)
}
func TestStreamsLocalSave(t *testing.T) {
s,err:=NewWave(testLocalURL)
if err!=nil{
if ue,ok:=err.(*url.Error);ok {
if oe,ok:=ue.Err.(*net.OpError);ok{
if se,ok:=oe.Err.(*os.SyscallError);ok{
if se.Err.Error()=="connection refused"{
t.Skip(ue.Error())
}
}
}
}
t.Fatal(err)
}
file, err := os.Create("./test output/localStream.wav")
if err != nil {panic(err)}
defer file.Close()
Encode(file, 1, 8000, unitX*3, s)
}
func TestStreamsLocalRampUpSave(t *testing.T) {
fs:=Modulated{&Wave{URL:testLocalURL},RampUp{unitX}}
file, err := os.Create("./test output/localFadeInStream.wav")
if err != nil {panic(err)}
defer file.Close()
Encode(file, 1, 8000, unitX*3, fs)
}
func TestStreamsSaveDataURL(t *testing.T) {
fs:=&Wave{URL:testDataURL}
file, err := os.Create("./test output/dataURL.wav")
if err != nil {panic(err)}
defer file.Close()
Encode(file, 1, 8000, unitX*3, fs)
}
func TestStreamsSaveFileURL(t *testing.T) {
fs:=&Wave{URL:testFileURL}
file, err := os.Create("./test output/fileURL.wav")
if err != nil {panic(err)}
defer file.Close()
Encode(file, 1, 8000, unitX*3, fs)
}
func TestStreamsSaveGOBFileURL(t *testing.T) {
err := SaveGOB(testGOBFile,Looped{Modulated{Pulse{unitX}, Looped{Pulse{unitX * 4 / 10}, unitX * 6 / 10}, Stacked{Sine{unitX / 450}, Sine{unitX / 400}}}, unitX * 3})
if err != nil { t.Error(err)}
fs:=&Wave{URL:"file://"+testGOBFile+".gob"}
file, err := os.Create("./test output/GOBfileURL.wav")
if err != nil {panic(err)}
defer file.Close()
Encode(file, 2, 22050, unitX*6, fs)
}
const testPCMFile="/home/simon/Dropbox/github/working/signals/test output/16bit/22050/pcm.pcm"
func TestStreamsSavePCMFileURL(t *testing.T) {
fs:=&Wave{URL:"file://"+testPCMFile}
file, err := os.Create("./test output/PCMfileURL.wav")
if err != nil {panic(err)}
defer file.Close()
Encode(file, 2, 22050, unitX/2205, fs)
}