dist/wavefile.js
function encodeSample_(sample) {
  /** @type {number} */
  let delta = sample - encoderPredicted_;
  /** @type {number} */
  let value = 0;
  if (delta >= 0) {
    value = 0;
  } else {
    value = 8;
    delta = -delta;
  }
  /** @type {number} */
  let step = STEP_TABLE[encoderIndex_];
  /** @type {number} */
  let diff = step >> 3;
  if (delta > step) {
    value |= 4;
    delta -= step;
    diff += step;
  }
  step >>= 1;
  if (delta > step) {
    value |= 2;
    delta -= step;
    diff += step;
  }
  step >>= 1;
  if (delta > step) {
    value |= 1;
    diff += step;
  }
  updateEncoder_(value, diff);
  return value;
}
function encodeSample_(sample) {
  /** @type {number} */
  let delta = sample - encoderPredicted_;
  /** @type {number} */
  let value = 0;
  if (delta >= 0) {
    value = 0;
  } else {
    value = 8;
    delta = -delta;
  }
  /** @type {number} */
  let step = STEP_TABLE[encoderIndex_];
  /** @type {number} */
  let diff = step >> 3;
  if (delta > step) {
    value |= 4;
    delta -= step;
    diff += step;
  }
  step >>= 1;
  if (delta > step) {
    value |= 2;
    delta -= step;
    diff += step;
  }
  step >>= 1;
  if (delta > step) {
    value |= 1;
    diff += step;
  }
  updateEncoder_(value, diff);
  return value;
}
function encodeSample_ ( sample ) { /** @type {number} */ let delta = sample - encoderPredicted_ ; /** @type {number} */ let value = 0 ; if ( delta >= 0 ) { value = 0 ; } else { value = 8 ; delta = - delta ; } /** @type {number} */ let step = STEP_TABLE [ encoderIndex_ ] ; /** @type {number} */ let diff = step >> 3 ; if ( delta > step ) { value |= 4 ; delta -= step ; diff += step ; } step >>= 1 ; if ( delta > step ) { value |= 2 ; delta -= step ; diff += step ; } step >>= 1 ; if ( delta > step ) { value |= 1 ; diff += step ; } updateEncoder_ ( value , diff ) ; return value ; }
Compress a 16-bit PCM sample into a 4-bit ADPCM sample.
@param {number} sample The sample.
@return {number}
@private
Compress a 16 - bit PCM sample into a 4 - bit ADPCM sample .