Audio from Scratch with Go: Stereo Panning
dylanmeeus.github.io
dylanmeeus.github.io
* https://en.wikipedia.org/wiki/Pan_law
* https://www.image-line.com/support/flstudio_online_manual/ht... (search for "panning law")
The two important missing pieces are phase delay and frequency-specific attenuation (the "head" model). Audio coming from the left side of your head reaches your left ear first, then your right ear later. Also, your head blocks certain frequencies more than others. Both of these effects are super noticeable and necessary to make panning sound "3D".
Adding these things to the Go code would actually be fairly straightforward, you just need to add a filter to `applyPan`. The filter would only need around 12 taps to sound good.
Here's a javascript tutorial which includes both of these additional features:
https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_A...
HRTF is a blunt instrument anyway. It's supposed to model your head and not just a standard imaginary generic head, and that's impossible without sticking a microphone inside each ear.
It's also a headphone-only effect. As soon as you play the sound through speakers you get room reflections and all kinds of other artefacts which wash out the spatial detail.
[1] Almost never. There are HRTF plugins, but they're hardly ever used in music mixing.
[2] Apple has some HRTF patents for recording audio on multiple channels - not just two - using HRTFs to capture apparent depth.
I agree that HRTFs are uncommon in mixing, but spatialization without some frequency dependent attenuation generally sounds "flat" with headphones.
Although VR systems and big budget spatialization like Atmos will account for speaker distance (so called near field effects) it's almost impossible to notice those effects for stationary sources and no head-tracking.
Glad you liked it! I don't have concrete plans actually, just doing this for fun so we'll see how far I get :)
(Sorry, this refers to the first entry in your audio/go series)
if there was a single format supported everywhere, minimum buffer sizes and a common API for all OSes, it would be a whole another, much more pleasant story
"There is actually a flaw with this panning function that we are using. However it is not apparent to us yet because we can only set a pan for an entire audio source"
I'm working from something simple up to something more complex, but tackling it in small parts. Next I'm writing about applying breakpoints where the pan can be set throughout the track and you can notice the power dip - and then we'll work on fixing that. ;-)
So I take back what I said about it being a balance control entirely. Sorry for that.