acl-js/src-js/decoder.js
// The decompressed sample will be written to the DecompressedTracks instance where it belongs.
The decompressed sample will be written to the DecompressedTracks instance where it belongs.
The decompressed sample will be written to the DecompressedTracks instance where it belongs .
decompressTrack(compressedTracks, trackIndex, sampleTime, roundingPolicy, decompressedTracks) {
    if (!wasmState.module) {
      throw new Error('WASM module not ready')
    }
    if (!compressedTracks || !(compressedTracks instanceof CompressedTracks)) {
      throw new TypeError("'compressedTracks' must be a CompressedTracks instance")
    }
    if (!compressedTracks.isBound) {
      throw new Error("'compressedTracks' must be bound")
    }
    if (!Number.isInteger(trackIndex) || trackIndex < 0 || trackIndex >= this._numTracks) {
      throw new RangeError(`Invalid track index: ${trackIndex}`);
    }
    if (!Number.isFinite(sampleTime)) {
      throw new RangeError(`Invalid sample time: ${sampleTime}`)
    }
    if (!isRoundingPolicy(roundingPolicy)) {
      throw new TypeError("'roundingPolicy' must be a RoundingPolicy")
    }
    const sampleSize = compressedTracks.sampleSize
    let resultBufferU8 = null
    let resultBufferOffset = 0
    if (decompressedTracks) {
      if (decompressedTracks instanceof DecompressedTracks) {
        const outputBufferSize = compressedTracks.outputBufferSize
        if (decompressedTracks.byteLength < outputBufferSize) {
          decompressedTracks.resize(outputBufferSize)
        }
        resultBufferU8 = decompressedTracks._mem.array
        resultBufferOffset = trackIndex * sampleSize
      }
      else {
        throw new TypeError("'decompressedTracks' must be a DecompressedTracks instance")
      }
      if (resultBufferOffset + sampleSize > resultBufferU8.byteLength) {
        throw new Error(`'decompressedTracks' must be at least ${sampleSize} bytes`)
      }
    }
    else {
      throw new Error("Must provide a 'decompressedTracks' output value")
    }
    const compressedTracksSize = compressedTracks._mem.byteLength
    const compressedTracksBuffer = compressedTracks._mem.byteOffset
    const outputBuffer = this._decompressTrackTmpBuffer
    const result = wasmState.instance.exports.decompress_track(compressedTracksBuffer, compressedTracksSize, sampleTime, roundingPolicy.value, trackIndex, outputBuffer, sampleSize)
    if (result != 0) {
      throw new Error(`Decompression failed: ${result}`)
    }
    resultBufferU8.set(wasmState.heap.subarray(outputBuffer, outputBuffer + sampleSize), resultBufferOffset)
    return decompressedTracks
  }
decompressTrack ( compressedTracks , trackIndex , sampleTime , roundingPolicy , decompressedTracks ) { if ( ! wasmState . module ) { throw new Error ( 'WASM module not ready' ) } if ( ! compressedTracks || ! ( compressedTracks instanceof CompressedTracks ) ) { throw new TypeError ( "'compressedTracks' must be a CompressedTracks instance" ) } if ( ! compressedTracks . isBound ) { throw new Error ( "'compressedTracks' must be bound" ) } if ( ! Number . isInteger ( trackIndex ) || trackIndex < 0 || trackIndex >= this . _numTracks ) { throw new RangeError ( ` ${ trackIndex } ` ) ; } if ( ! Number . isFinite ( sampleTime ) ) { throw new RangeError ( ` ${ sampleTime } ` ) } if ( ! isRoundingPolicy ( roundingPolicy ) ) { throw new TypeError ( "'roundingPolicy' must be a RoundingPolicy" ) } const sampleSize = compressedTracks . sampleSize let resultBufferU8 = null let resultBufferOffset = 0 if ( decompressedTracks ) { if ( decompressedTracks instanceof DecompressedTracks ) { const outputBufferSize = compressedTracks . outputBufferSize if ( decompressedTracks . byteLength < outputBufferSize ) { decompressedTracks . resize ( outputBufferSize ) } resultBufferU8 = decompressedTracks . _mem . array resultBufferOffset = trackIndex * sampleSize } else { throw new TypeError ( "'decompressedTracks' must be a DecompressedTracks instance" ) } if ( resultBufferOffset + sampleSize > resultBufferU8 . byteLength ) { throw new Error ( ` ${ sampleSize } ` ) } } else { throw new Error ( "Must provide a 'decompressedTracks' output value" ) } const compressedTracksSize = compressedTracks . _mem . byteLength const compressedTracksBuffer = compressedTracks . _mem . byteOffset const outputBuffer = this . _decompressTrackTmpBuffer const result = wasmState . instance . exports . decompress_track ( compressedTracksBuffer , compressedTracksSize , sampleTime , roundingPolicy . value , trackIndex , outputBuffer , sampleSize ) if ( result != 0 ) { throw new Error ( ` ${ result } ` ) } resultBufferU8 . set ( wasmState . heap . subarray ( outputBuffer , outputBuffer + sampleSize ) , resultBufferOffset ) return decompressedTracks }
The decompressed sample will be written to the DecompressedTracks instance where it belongs.
The decompressed sample will be written to the DecompressedTracks instance where it belongs .
// Make sure we can store our result //console.log(`Decompression result: ${result}`) // Copy our decompressed tracks out of the WASM heap //console.log(`Reading decompressed tracks from WASM heap offset ${outputBuffer}, ${outputBufferSize} bytes`)