def adjust_volume(buf, mult)
      # We don't need to adjust anything if the buf is nil so just return in that case
      return unless buf

      # buf is s16le so use 's<' for signed, 16 bit, LE
      result = buf.unpack('s<*').map do |sample|
        sample *= mult

        # clamp to s16 range
        [32_767, [-32_768, sample].max].min
      end

      # After modification, make it s16le again
      result.pack('s<*')
    end
def adjust_volume(buf, mult)
      # We don't need to adjust anything if the buf is nil so just return in that case
      return unless buf

      # buf is s16le so use 's<' for signed, 16 bit, LE
      result = buf.unpack('s<*').map do |sample|
        sample *= mult

        # clamp to s16 range
        [32_767, [-32_768, sample].max].min
      end

      # After modification, make it s16le again
      result.pack('s<*')
    end
Adjusts the volume of a given buffer of s16le PCM data.
 @param buf [String] An unencoded PCM (s16le) buffer.
 @param mult [Float] The volume multiplier, 1 for same volume.
 @return [String] The buffer with adjusted volume, s16le again