-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtzx_block_gen.go
101 lines (83 loc) · 1.72 KB
/
tzx_block_gen.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
package tzx
func (t *tzx_block_11) generate(stream audioStream) {
if t.pilotLen != 0 {
// PILOT
for i := 0; i < int(t.pilotLen); i++ {
stream.addEdge(int(t.pilotPulseLen))
}
stream.addEdge(int(t.firstSyncLen))
stream.addEdge(int(t.secondSyncLen))
}
for i := 0; i < len(t.data)-1; i++ {
d := t.data[i]
for i := 7; i >= 0; i-- {
bit := d&(1<<i) != 0
if bit {
stream.addEdge(int(t.oneLen))
stream.addEdge(int(t.oneLen))
} else {
stream.addEdge(int(t.zeroLen))
stream.addEdge(int(t.zeroLen))
}
}
}
// Last byte
d := t.data[len(t.data)-1]
for i := 7; i >= (8 - int(t.rem)); i-- {
bit := d&(1<<i) != 0
if bit {
stream.addEdge(int(t.oneLen))
stream.addEdge(int(t.oneLen))
} else {
stream.addEdge(int(t.zeroLen))
stream.addEdge(int(t.zeroLen))
}
}
if t.tailMs != 0 {
stream.addPause(int(t.tailMs))
}
}
func (t *tzx_block_12) generate(stream audioStream) {
for i := uint16(0); i < t.pulses; i++ {
stream.addEdge(int(t.pulselen))
}
}
func (t *tzx_block_13) generate(stream audioStream) {
plen := len(t.pulses)
for i := 0; i < plen; i++ {
stream.addEdge(int(t.pulses[i]))
}
}
func (t *tzx_block_19) generate(stream audioStream) {
for _, v := range t.data {
for i, s := range v.d {
if s == 0 {
break
}
if i != 0 {
stream.addEdge(int(s))
continue
}
switch v.t {
case 0:
stream.addEdge(int(s))
break
case 1:
stream.continuePrevious(int(s))
break
case 2:
stream.setLevel(false, int(s))
break
case 3:
stream.setLevel(true, int(s))
break
}
}
}
if t.tailMs != 0 {
stream.addPause(int(t.tailMs))
}
}
func (t *tzx_block_20) generate(stream audioStream) {
stream.addPause(int(t.duration))
}