This was suggested by the Apple Support agent.
Try deleting these files first, by running these commands in Terminal:
> sudo rm -rf /Library/Preferences/com.apple.soundpref.plist (Note: if this file is not present, continue to the next file below.)
> sudo rm -rf ~/Library/Preferences/com.apple.soundpref.plist
> sudo rm -rf /Library/Preferences/Audio/com.apple.audio.DeviceSettings.plist
> sudo rm -rf /Library/Preferences/Audio/com.apple.audio.SystemSettings.plist
If this doesn't solve the crackling sound issue, we should use Capture Data app (see below) to record the system state when the issue happens and then send it to Apple.
Please follow these instructions on how to do it:
1. Download this disk image.
2. Open the disk image, then open the application it contains. The application will automatically locate the requested files.
3. To send the files, contact Apple Support online service and ask for a link to send the files.
On top of that, it's also good that you make a small video that clearly shows the problem and also send it to the Apple Support service.