-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathxing.go
51 lines (44 loc) · 888 Bytes
/
xing.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
package mp3
import (
"bytes"
"encoding/binary"
)
type XingHeader struct {
Frames, Bytes, Quality int
}
// Parse an Xing header from the first frame of an mp3
func (this *XingHeader) Parse(src []byte) bool {
if len(src) == 0 {
return false
}
// parse header id
idx := bytes.Index(src, []byte("Xing"))
if idx < 0 {
idx = bytes.Index(src, []byte("Info"))
}
if idx < 0 {
return false
}
src = src[idx+4:]
flags := binary.BigEndian.Uint32(src[:4])
src = src[4:]
// Frames
if flags&1 == 1 {
this.Frames = int(binary.BigEndian.Uint32(src[:4]))
src = src[4:]
}
// Bytes
if flags&2 == 2 {
this.Bytes = int(binary.BigEndian.Uint32(src[:4]))
src = src[4:]
}
// TOC
if flags&4 == 4 {
src = src[4:]
}
// Quality
if flags&8 == 8 {
this.Quality = int(binary.BigEndian.Uint32(src[:4]))
}
return true
}