Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Arraybuffer variant almost works, and it looks real fast too!

  • Loading branch information...
commit 8e6d2c57f7157eb888b239172eca70dc07a216c9 1 parent 3c93635
@nddrylliog nddrylliog authored
View
2  experiments/experiment.js
@@ -14,7 +14,7 @@ var domReady = function ()
console.log("File loaded");
var mpeg = mp3.getMpegStream();
- var howmuch = 1;
+ var howmuch = 1000;
var ss1 = Date.now();
console.log("Decoding first " + howmuch + " frames");
var frame = new Mad.Frame();
View
1  experiments/index.html
@@ -16,6 +16,7 @@
<script type="text/javascript" src="/src/arraybuffer/bytestream.js"></script>
<script type="text/javascript" src="/src/arraybuffer/filestream.js"></script>
<script type="text/javascript" src="/src/arraybuffer/substream.js"></script>
+ <script type="text/javascript" src="/src/arraybuffer/arraystream.js"></script>
<script type="text/javascript" src="/src/binarystring/bytestream.js"></script>
<script type="text/javascript" src="/src/binarystring/filestream.js"></script>
View
55 src/arraybuffer/arraystream.js
@@ -0,0 +1,55 @@
+
+Mad.ArrayBuffers.ArrayStream = Mad.ArrayBuffers.ByteStream.extend({
+ init: function (buffer) {
+ this.offset = 0;
+ this.buffer = buffer;
+ this.amountRead = this.buffer.length;
+ this.contentLength = this.buffer.length;
+ this.length = this.amountRead;
+ },
+
+ substream: function (offset, length) {
+ return new Mad.ArrayBuffers.SubStream(this, offset, length);
+ },
+
+ absoluteAvailable: function(n, updated) {
+ return n < this.amountRead;
+ },
+
+ getU8: function(offset, bigEndian) {
+ return this.buffer[offset];
+ },
+
+ seek: function(n) {
+ this.offset += n;
+ },
+
+ read: function(n) {
+ var result = this.peek(n);
+
+ this.seek(n);
+
+ return result;
+ },
+
+ peek: function(n) {
+ if (this.available(n)) {
+ var offset = this.offset;
+
+ var result = this.get(offset, n);
+
+ return result;
+ } else {
+ throw 'TODO: THROW PEEK ERROR!';
+ }
+ },
+
+ get: function(offset, length) {
+ if (offset + length < this.contentLength) {
+ var subarr = this.buffer.subarray(offset, offset + length);
+ return subarr;
+ } else {
+ throw 'TODO: THROW GET ERROR!';
+ }
+ }
+});
View
9 src/arraybuffer/filestream.js 100755 → 100644
@@ -1,6 +1,4 @@
-Mad.uglyDebug = 200;
-
Mad.ArrayBuffers.FileStream = Mad.ArrayBuffers.ByteStream.extend({
init: function (file, callback) {
this.offset = 0;
@@ -41,12 +39,7 @@ Mad.ArrayBuffers.FileStream = Mad.ArrayBuffers.ByteStream.extend({
},
getU8: function(offset, bigEndian) {
- var result = this.buffer[offset];
- if(Mad.uglyDebug >= 0) {
- console.log("get(" + offset + ") = " + result);
- Mad.uglyDebug--;
- }
- return result;
+ return this.buffer[offset];
},
seek: function(n) {
View
4 src/bit.js
@@ -7,8 +7,10 @@ var CHAR_BIT = 8;
* DESCRIPTION: initialize bit pointer struct
*/
Mad.Bit = function (stream, offset) {
- if (typeof(stream) == 'string') {
+ if (stream instanceof String) {
this.stream = new Mad.BinaryStrings.StringStream(stream);
+ } else if(stream instanceof Uint8Array) {
+ this.stream = new Mad.ArrayBuffers.ArrayStream(stream);
} else {
this.stream = stream;
}
View
10 src/mad.js
@@ -20,9 +20,15 @@ if (!Mad.enforceBinaryString && typeof(ArrayBuffer) === 'function' && typeof(Uin
return new Uint8Array(length);
},
- memcpy: function (dst, dstOffset, src, srcOffset, length) {
+ memcpy: function (dst, dstOffset, pSrc, srcOffset, length) {
+ while (pSrc.parentStream) {
+ srcOffset += pSrc.start;
+ pSrc = pSrc.parentStream;
+ }
+ var src = pSrc.buffer;
+
// oh my, memcpy actually exists in JavaScript?
- dst.set(src.subarray(srcOffset), dstOffset);
+ dst.set(src.subarray(srcOffset, length), dstOffset);
return dst;
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.