Distorted Audio when recording external microphones using AVCaptureSession

In certain situations, when recording audio on macOS using AVCaptureSession and AVAssetWriter, the resulting audio file can sound distorted. This issue is caused by AVCaptureSession reporting CMSampleBuffers of different audio formats.