So there's this thing called a Fourier series...
Basically any wave can be created by adding together individual frequencies, and with some fancy math it's possible to go the other way with a Fourier transform and get how loud every frequency is (like is displayed in a spectrogram).
I think the real black magic is in how our ears and brains can decode the mess of information coming in and identify meaningful patterns.