dist/wavefile.js
function bitDepth(input, original, target, output) {
  validateBitDepth_(original);
  validateBitDepth_(target);
  /** @type {!Function} */
  let toFunction = getBitDepthFunction_(original, target);
  /** @type {!Object<string, number>} */
  let options = {
    oldMin: Math.pow(2, parseInt(original, 10)) / 2,
    newMin: Math.pow(2, parseInt(target, 10)) / 2,
    oldMax: (Math.pow(2, parseInt(original, 10)) / 2) - 1,
    newMax: (Math.pow(2, parseInt(target, 10)) / 2) - 1,
  };
  /** @type {number} */
  const len = input.length;
  // sign the samples if original is 8-bit
  if (original == "8") {
    for (let i=0; i<len; i++) {
      output[i] = input[i] -= 128;
    }
  }
  // change the resolution of the samples
  for (let i=0; i<len; i++) {        
    output[i] = toFunction(input[i], options);
  }
  // unsign the samples if target is 8-bit
  if (target == "8") {
    for (let i=0; i<len; i++) {
      output[i] = output[i] += 128;
    }
  }
}
function bitDepth(input, original, target, output) {
  validateBitDepth_(original);
  validateBitDepth_(target);
  /** @type {!Function} */
  let toFunction = getBitDepthFunction_(original, target);
  /** @type {!Object<string, number>} */
  let options = {
    oldMin: Math.pow(2, parseInt(original, 10)) / 2,
    newMin: Math.pow(2, parseInt(target, 10)) / 2,
    oldMax: (Math.pow(2, parseInt(original, 10)) / 2) - 1,
    newMax: (Math.pow(2, parseInt(target, 10)) / 2) - 1,
  };
  /** @type {number} */
  const len = input.length;
  // sign the samples if original is 8-bit
  if (original == "8") {
    for (let i=0; i<len; i++) {
      output[i] = input[i] -= 128;
    }
  }
  // change the resolution of the samples
  for (let i=0; i<len; i++) {        
    output[i] = toFunction(input[i], options);
  }
  // unsign the samples if target is 8-bit
  if (target == "8") {
    for (let i=0; i<len; i++) {
      output[i] = output[i] += 128;
    }
  }
}
function bitDepth ( input , original , target , output ) { validateBitDepth_ ( original ) ; validateBitDepth_ ( target ) ; /** @type {!Function} */ let toFunction = getBitDepthFunction_ ( original , target ) ; /** @type {!Object<string, number>} */ let options = { oldMin : Math . pow ( 2 , parseInt ( original , 10 ) ) / 2 , newMin : Math . pow ( 2 , parseInt ( target , 10 ) ) / 2 , oldMax : ( Math . pow ( 2 , parseInt ( original , 10 ) ) / 2 ) - 1 , newMax : ( Math . pow ( 2 , parseInt ( target , 10 ) ) / 2 ) - 1 , } ; /** @type {number} */ const len = input . length ; // sign the samples if original is 8-bit if ( original == "8" ) { for ( let i = 0 ; i < len ; i ++ ) { output [ i ] = input [ i ] -= 128 ; } } // change the resolution of the samples for ( let i = 0 ; i < len ; i ++ ) { output [ i ] = toFunction ( input [ i ] , options ) ; } // unsign the samples if target is 8-bit if ( target == "8" ) { for ( let i = 0 ; i < len ; i ++ ) { output [ i ] = output [ i ] += 128 ; } } }
Change the bit depth of samples. The input array.
@param {!TypedArray} input The samples.
@param {string} original The original bit depth of the data.
One of "8" ... "53", "32f", "64"
@param {string} target The desired bit depth for the data.
One of "8" ... "53", "32f", "64"
@param {!TypedArray} output The output array.
Change the bit depth of samples . The input array .