1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package entagged.audioformats.flac.util;
20
21 public class MetadataBlockHeader {
22
23 public final static int STREAMINFO=0,PADDING=1,APPLICATION=2,SEEKTABLE=3,VORBIS_COMMENT=4,CUESHEET=5,UNKNOWN=6;
24 private boolean isLastBlock;
25 private int blockType, dataLength;
26 private byte[] bytes;
27
28 public MetadataBlockHeader( byte[] b ) {
29 isLastBlock = ( (b[0] & 0x80)>>>7 )==1;
30
31 int type = b[0] & 0x7F;
32 switch(type) {
33 case 0: blockType = STREAMINFO;
34 break;
35 case 1: blockType = PADDING;
36 break;
37 case 2: blockType = APPLICATION;
38 break;
39 case 3: blockType = SEEKTABLE;
40 break;
41 case 4: blockType = VORBIS_COMMENT;
42 break;
43 case 5: blockType = CUESHEET;
44 break;
45 default: blockType = UNKNOWN;
46 }
47
48 dataLength = (u(b[1])<<16) + (u(b[2])<<8) + (u(b[3]));
49
50 bytes = new byte[4];
51 for(int i = 0; i< 4; i++)
52 bytes[i] = b[i];
53 }
54
55 private int u(int i) {
56 return i & 0xFF;
57 }
58
59 public int getDataLength() {
60 return dataLength;
61 }
62
63 public int getBlockType() {
64 return blockType;
65 }
66
67 public String getBlockTypeString() {
68 switch(blockType) {
69 case 0: return "STREAMINFO";
70 case 1: return "PADDING";
71 case 2: return "APPLICATION";
72 case 3: return "SEEKTABLE";
73 case 4: return "VORBIS_COMMENT";
74 case 5: return "CUESHEET";
75 default: return "UNKNOWN-RESERVED";
76 }
77 }
78
79 public boolean isLastBlock() {
80 return isLastBlock;
81 }
82
83 public byte[] getBytes() {
84 bytes[0] = (byte)(bytes[0] & 0x7F);
85 return bytes;
86 }
87 }