downsampleBuffer(buffer) {
    if (this.audioContext.sampleRate === this.sampleRate) {
      return buffer;
    }
    const sampleRateRatio = this.audioContext.sampleRate / this.sampleRate;
    const newLength = Math.round(buffer.length / sampleRateRatio);
    const result = new Int16Array(newLength);
    let offsetResult = 0;
    let offsetBuffer = 0;
    while (offsetResult < result.length) {
      const nextOffsetBuffer = Math.round((offsetResult + 1) * sampleRateRatio);
      let accum = 0;
      let count = 0;
      for (
        let i = offsetBuffer;
        i < nextOffsetBuffer && i < buffer.length;
        i += 1
      ) {
        accum += buffer[i];
        count += 1;
      }
      result[offsetResult] = Math.min(1, accum / count) * 0x7fff;
      offsetResult += 1;
      offsetBuffer = nextOffsetBuffer;
    }
    return result.buffer;
  }
Downsamles the buffer if needed to right sampleRate & converts the data into an int16 buffer

@param buffer buffer