source: gs3-extensions/web-audio/trunk/js-mad/script/binarystring/bytestream.js@ 28388

Last change on this file since 28388 was 28388, checked in by davidb, 11 years ago

Set of JS, CSS, PNG etc web resources to support a mixture of audio player/document display capabilities

File size: 4.3 KB
Line 
1Mad.BinaryStrings.ByteStream = function(url) { }
2
3Mad.BinaryStrings.ByteStream.prototype.available = function(n) {
4 return this.absoluteAvailable(this.offset + n);
5}
6
7Mad.BinaryStrings.ByteStream.prototype.strEquals = function (offset, string) {
8 for (var i = 0; i < string.length; i++) {
9 if(this.getU8(offset + i, false) != string.charCodeAt(i)) return false;
10 }
11 return true;
12}
13
14Mad.BinaryStrings.ByteStream.prototype.getU8 = function(offset, bigEndian) {
15 var bytes = this.get(offset, 1);
16 return bytes.charCodeAt(0);
17}
18
19Mad.BinaryStrings.ByteStream.prototype.getU16 = function(offset, bigEndian) {
20 var bytes = this.get(offset, 2);
21
22 if (!bigEndian) {
23 bytes = bytes.reverse();
24 }
25
26 return (bytes.charCodeAt(0) << 8) | bytes.charCodeAt(1);
27}
28
29Mad.BinaryStrings.ByteStream.prototype.getU24 = function(offset, bigEndian) {
30 var bytes = this.get(offset, 3);
31
32 if (!bigEndian) {
33 bytes = bytes.reverse();
34 }
35
36 return (bytes.charCodeAt(0) << 16) | (bytes.charCodeAt(1) << 8) | bytes.charCodeAt(2);
37}
38
39Mad.BinaryStrings.ByteStream.prototype.getU32 = function(offset, bigEndian) {
40 var bytes = this.get(offset, 4);
41
42 if (!bigEndian) {
43 bytes = bytes.reverse();
44 }
45
46 return (bytes.charCodeAt(0) << 24) | (bytes.charCodeAt(1) << 16) | (bytes.charCodeAt(2) << 8) | bytes.charCodeAt(3);
47}
48
49Mad.BinaryStrings.ByteStream.prototype.getI8 = function(offset, bigEndian) {
50 return this.getU8(offset, bigEndian) - 128; // 2 ** 7
51}
52
53Mad.BinaryStrings.ByteStream.prototype.getI16 = function(offset, bigEndian) {
54 return this.getU16(offset, bigEndian) - 65536; // 2 ** 15
55}
56
57Mad.BinaryStrings.ByteStream.prototype.getI32 = function(offset, bigEndian) {
58 return this.getU32(offset, bigEndian) - 2147483648; // 2 ** 31
59}
60
61Mad.BinaryStrings.ByteStream.prototype.getSyncInteger = function(offset) {
62 var bytes = this.get(offset, 4);
63
64 return (bytes.charCodeAt(0) << 21) | (bytes.charCodeAt(1) << 14) | (bytes.charCodeAt(2) << 7) | bytes.charCodeAt(3);
65}
66
67Mad.BinaryStrings.ByteStream.prototype.peekU8 = function(bigEndian) {
68 return this.getU8(this.offset, bigEndian);
69}
70
71Mad.BinaryStrings.ByteStream.prototype.peekU16 = function(bigEndian) {
72 return this.getU16(this.offset, bigEndian);
73}
74
75Mad.BinaryStrings.ByteStream.prototype.peekU24 = function(bigEndian) {
76 return this.getU24(this.offset, bigEndian);
77}
78
79Mad.BinaryStrings.ByteStream.prototype.peekU32 = function(bigEndian) {
80 return this.getU32(this.offset, bigEndian);
81}
82
83Mad.BinaryStrings.ByteStream.prototype.peekI8 = function(bigEndian) {
84 return this.getI8(this.offset, bigEndian);
85}
86
87Mad.BinaryStrings.ByteStream.prototype.peekI16 = function(bigEndian) {
88 return this.getI16(this.offset, bigEndian);
89}
90
91Mad.BinaryStrings.ByteStream.prototype.peekI32 = function(bigEndian) {
92 return this.getI32(this.offset, bigEndian);
93}
94
95Mad.BinaryStrings.ByteStream.prototype.peekSyncInteger = function() {
96 return this.getSyncInteger(this.offset);
97}
98
99Mad.BinaryStrings.ByteStream.prototype.readU8 = function(bigEndian) {
100 var result = this.peekU8(bigEndian);
101
102 this.seek(1);
103
104 return result;
105}
106
107Mad.BinaryStrings.ByteStream.prototype.readU16 = function(bigEndian) {
108 var result = this.peekU16(bigEndian);
109
110 this.seek(2);
111
112 return result;
113}
114
115Mad.BinaryStrings.ByteStream.prototype.readU24 = function(bigEndian) {
116 var result = this.peekU24(bigEndian);
117
118 this.seek(3);
119
120 return result;
121}
122
123Mad.BinaryStrings.ByteStream.prototype.readU32 = function(bigEndian) {
124 var result = this.peekU32(bigEndian);
125
126 this.seek(4);
127
128 return result;
129}
130
131Mad.BinaryStrings.ByteStream.prototype.readI8 = function(bigEndian) {
132 var result = this.peekI8(bigEndian);
133
134 this.seek(1);
135
136 return result;
137}
138
139Mad.BinaryStrings.ByteStream.prototype.readI16 = function(bigEndian) {
140 var result = this.peekI16(bigEndian);
141
142 this.seek(2);
143
144 return result;
145}
146
147Mad.BinaryStrings.ByteStream.prototype.readI32 = function(bigEndian) {
148 var result = this.peekI32(bigEndian);
149
150 this.seek(4);
151
152 return result;
153}
154
155Mad.BinaryStrings.ByteStream.prototype.readSyncInteger = function() {
156 var result = this.getSyncInteger(this.offset);
157
158 this.seek(4);
159
160 return result;
161}
Note: See TracBrowser for help on using the repository browser.