-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchain.go
77 lines (62 loc) · 1.98 KB
/
chain.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
package liblsdj
import (
"errors"
"fmt"
)
const (
chainCount = 0x7F + 1 //! The amount of chains in a song, UNUSED MAY BE 0X80
chainLength = 16 //! The number of steps in a chain
chainNoPhrase = 0xFF //! The value of "no Phrase" at a given step
chainAssignLength = 0x100
)
type Chain struct {
phrase [chainLength]byte
transposition [chainLength]byte
}
func setChains(phrases, transpositions []byte) ([]Chain, error) {
if len(phrases) != chainCount*chainLength {
return nil, fmt.Errorf("unexpected chain phrases length; expected: %v, got: %v", len(phrases), chainCount*chainLength)
} else if len(transpositions) != chainCount*chainLength {
return nil, fmt.Errorf("unexpected chain transpositions length; expected: %v, got: %v", len(transpositions), chainCount*chainLength)
}
// ChainPhrases Format: [0..15 for 00, 0..15 for 01 etc]
c := make([]Chain, chainCount)
for i := 0; i < chainCount; i++ {
copy(c[i].phrase[:], phrases[i*chainLength:chainLength*(i+1)])
copy(c[i].transposition[:], transpositions[i*chainLength:chainLength*(i+1)])
}
return c, nil
}
type ChainAssignments struct {
Pulse1 []byte
Pulse2 []byte
Wave []byte
Noise []byte
}
// Set La struttura dei ChainAssignments [P1 P2 W N] e si ripete per tutte le righe possibili
func (c *ChainAssignments) Set(b []byte) error {
if len(b) != 4*chainAssignLength {
return errors.New(fmt.Sprintf("unexpected length: %v, %v", len(b), 4*chainAssignLength))
}
c.Pulse1 = make([]byte, 0)
c.Pulse2 = make([]byte, 0)
c.Wave = make([]byte, 0)
c.Noise = make([]byte, 0)
for i := 0; i < len(b)/4; i++ {
c.Pulse1 = append(c.Pulse1, b[4*i])
c.Pulse2 = append(c.Pulse1, b[4*i+1])
c.Wave = append(c.Pulse1, b[4*i+2])
c.Noise = append(c.Pulse1, b[4*i+3])
}
return nil
}
func (c *ChainAssignments) Get() []byte {
b := make([]byte, 0)
for i := 0; i < chainAssignLength; i++ {
b = append(b, c.Pulse1[i])
b = append(b, c.Pulse2[i])
b = append(b, c.Wave[i])
b = append(b, c.Noise[i])
}
return b
}