         unless format.name == "Linear PCM"
             console.log("Not decoding Linear PCM"); debugger
         
-        output = new Float32Array(format.length / (format.bitsPerChannel / 8))
+        
+        samples = (buffer.length / (format.bitsPerChannel / 8) >> 0)
+        bytes = samples * (format.bitsPerChannel / 8)
+        
+        output = new Float32Array(samples) # TODO: Sample-align output from decoders
         
         if format.float
             switch format.bitsPerChannel
                 when 64
-                    input = new Float64Array(array)
+                    input = new Float64Array(array, 0, samples)
                 when 32
-                    input = new Float32Array(array)
+                    input = new Float32Array(array, 0, samples)
                 else
                     console.log("Unsupported Float length #{format.bitsPerChannel} bits"); debugger
                 
             
-            output[i] = input[i] for i in [0 ... input.length] by 1
+            (output[i] = input[i]) for i in [0 ... input.length] by 1
         else # TODO: Fix big unsigned formats, and 8-bit signed formats
             if format.littleEndian
                 console.log("LE is unsupported right now, on TODO list"); debugger
             
             switch format.bitsPerChannel
                 when 32
-                    input = new Int32Array(array)
+                    input = new Int32Array(array, 0, samples)
                     
-                    output[i] = input[i] / 0x7FFFFFFF for i in [0 ... input.length] by 1
+                    (output[i] = input[i] / 0x7FFFFFFF) for i in [0 ... input.length] by 1
                 when 24
                     console.log("24 bit output is unsupported right now, on TODO list"); debugger
                 when 16
-                    input = new Int16Array(array)
+                    input = new Int16Array(array, 0, samples)
                     
-                    output[i] = input[i] / 0x7FFF for i in [0 ... input.length] by 1
+                    (output[i] = input[i] / 0x7FFF) for i in [0 ... input.length] by 1
                 when 8
-                    input = new Uint8Array(array)
+                    input = new Uint8Array(array, 0, samples)
                     
-                    output[i] = input[i] / 0xFF for i in [0 ... input.length] by 1
+                    (output[i] = input[i] / 0xFF) for i in [0 ... input.length] by 1
                 else
                     console.log("Unsupported Float length #{format.bitsPerChannel} bits"); debugger
                 
             
         
-        output = new Uint8Array(output.buffer)
+        output = new Uint8Array(output.buffer, 0, bytes)
         
         result = new Aurora.Buffer(output)
         
-        result.duration  = @metadata.format.framesPerPacket / @metadata.format.samplingFrequency
-        result.timestamp = @packetsDecoded * result.duration
+        result.duration  = samples / format.samplingFrequency
+        result.timestamp = @packetsDecoded++ * result.duration
         
         result.metadata = {
             format: {


window.Aurora = {} unless window.Aurora

window.Aurora.ALACDecoder = AuroraALACDecoder

class LPCMDecoder
    constructor: (@name) ->
        @inputs = {
            data:
