Loud squealing noise in headphone/speaker followed by computer freezing
Notice: Although it seems unlikely it is possible there is a fault with the machine that could escalate, so if you haven't already please make sure to take a backup of your important documents.


There are a few things you could try:


Perform a PRAM reset by following Apple's instructions: http://support.apple.com/kb/HT1379
Perform an SMC reset by following Apple's instructions: http://support.apple.com/kb/HT1543


Test for a period


Run Apple Hardware Test by following Apple's instructions, running the full/extended test: https://support.apple.com/en-gb/HT201257


Review the results for any obvious hardware faults


Take a backup and reinstall macOS, I can provide instructions here if you get that far, but let's see the results of the hardware fault and screenshots, you can add them to your original post as an edit.