dist/wavefile.js
function encodeSample(sample) {
  /** @type {number} */
  let compandedValue; 
  sample = (sample ==-32768) ? -32767 : sample;
  /** @type {number} */
  let sign = ((~sample) >> 8) & 0x80; 
  if (!sign) {
    sample = sample * -1; 
  }
  if (sample > 32635) {
    sample = 32635; 
  }
  if (sample >= 256)  {
    /** @type {number} */
    let exponent = LOG_TABLE[(sample >> 8) & 0x7F];
    /** @type {number} */
    let mantissa = (sample >> (exponent + 3) ) & 0x0F; 
    compandedValue = ((exponent << 4) | mantissa); 
  } else {
    compandedValue = sample >> 4; 
  } 
  return compandedValue ^ (sign ^ 0x55);
}
function encodeSample(sample) {
  /** @type {number} */
  let compandedValue; 
  sample = (sample ==-32768) ? -32767 : sample;
  /** @type {number} */
  let sign = ((~sample) >> 8) & 0x80; 
  if (!sign) {
    sample = sample * -1; 
  }
  if (sample > 32635) {
    sample = 32635; 
  }
  if (sample >= 256)  {
    /** @type {number} */
    let exponent = LOG_TABLE[(sample >> 8) & 0x7F];
    /** @type {number} */
    let mantissa = (sample >> (exponent + 3) ) & 0x0F; 
    compandedValue = ((exponent << 4) | mantissa); 
  } else {
    compandedValue = sample >> 4; 
  } 
  return compandedValue ^ (sign ^ 0x55);
}
function encodeSample ( sample ) { /** @type {number} */ let compandedValue ; sample = ( sample == - 32768 ) ? - 32767 : sample ; /** @type {number} */ let sign = ( ( ~ sample ) >> 8 ) & 0x80 ; if ( ! sign ) { sample = sample * - 1 ; } if ( sample > 32635 ) { sample = 32635 ; } if ( sample >= 256 ) { /** @type {number} */ let exponent = LOG_TABLE [ ( sample >> 8 ) & 0x7F ] ; /** @type {number} */ let mantissa = ( sample >> ( exponent + 3 ) ) & 0x0F ; compandedValue = ( ( exponent << 4 ) | mantissa ) ; } else { compandedValue = sample >> 4 ; } return compandedValue ^ ( sign ^ 0x55 ) ; }
Encode a 16-bit linear PCM sample as 8-bit A-Law.
@param {number} sample A 16-bit PCM sample
@return {number}
Encode a 16 - bit linear PCM sample as 8 - bit A - Law .