-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaiff.go
78 lines (65 loc) · 2.09 KB
/
aiff.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
package aiff
import "errors"
var (
formID = [4]byte{'F', 'O', 'R', 'M'}
aiffID = [4]byte{'A', 'I', 'F', 'F'}
aifcID = [4]byte{'A', 'I', 'F', 'C'}
// COMMID is the common chunk ID
COMMID = [4]byte{'C', 'O', 'M', 'M'}
COMTID = [4]byte{'C', 'O', 'M', 'T'}
SSNDID = [4]byte{'S', 'S', 'N', 'D'}
// Apple stuff
chanID = [4]byte{'C', 'H', 'A', 'N'}
bascID = [4]byte{'b', 'a', 's', 'c'}
trnsID = [4]byte{'t', 'r', 'n', 's'}
cateID = [4]byte{'c', 'a', 't', 'e'}
// AIFC encodings
encNotSet = [4]byte{}
encNone = [4]byte{'N', 'O', 'N', 'E'}
// inverted byte order LE instead of BE (not really compression)
encSowt = [4]byte{'s', 'o', 'w', 't'}
// inverted byte order LE instead of BE (not really compression)
encTwos = [4]byte{'t', 'w', 'o', 's'}
encRaw = [4]byte{'r', 'a', 'w', ' '}
encIn24 = [4]byte{'i', 'n', '2', '4'}
enc42n1 = [4]byte{'4', '2', 'n', '1'}
encIn32 = [4]byte{'i', 'n', '3', '2'}
enc23ni = [4]byte{'2', '3', 'n', 'i'}
encFl32 = [4]byte{'f', 'l', '3', '2'}
encFL32 = [4]byte{'F', 'L', '3', '2'}
encFl64 = [4]byte{'f', 'l', '6', '4'}
encFL64 = [4]byte{'F', 'L', '6', '4'}
envUlaw = [4]byte{'u', 'l', 'a', 'w'}
encULAW = [4]byte{'U', 'L', 'A', 'W'}
encAlaw = [4]byte{'a', 'l', 'a', 'w'}
encALAW = [4]byte{'A', 'L', 'A', 'W'}
encDwvw = [4]byte{'D', 'W', 'V', 'W'}
encGsm = [4]byte{'G', 'S', 'M', ' '}
encIma4 = [4]byte{'i', 'm', 'a', '4'}
// encAble
encAble = [4]byte{'a', 'b', 'l', 'e'}
// ErrFmtNotSupported is a generic error reporting an unknown format.
ErrFmtNotSupported = errors.New("format not supported")
// ErrUnexpectedData is a generic error reporting that the parser encountered unexpected data.
ErrUnexpectedData = errors.New("unexpected data content")
// Debug is a flag that can be turned on to see more logs
Debug = false
)
func round(v float64, decimals int) float64 {
var pow float64 = 1
for i := 0; i < decimals; i++ {
pow *= 10
}
return float64(int((v*pow)+0.5)) / pow
}
func nullTermStr(b []byte) string {
return string(b[:clen(b)])
}
func clen(n []byte) int {
for i := 0; i < len(n); i++ {
if n[i] == 0 {
return i
}
}
return len(n)
}