igorski / MWEngine

Audio engine and DSP library for Android, written in C++ providing low latency performance within a musical context, while providing a Java/Kotlin API. Supports both OpenSL and AAudio.
MIT License
264 stars 45 forks source link

Issues with panning #148

Closed vustav closed 2 years ago

vustav commented 2 years ago

Not sure if I'm doing something wrong or if panning isn't working properly. I'm setting up the engine with two output channels and changing pan by calling the instruments getAudioChannel().setPan(pan) with a value between -1 and 1.

Max left and right sounds good but the closer it gets to 0 zero the lower it gets and there might also be some phasing or something going on, not sure but it sounds bad.

So: the actual location(?) of the sound works, but it sounds bad centered.

igorski commented 2 years ago

Hm, that's a good observation.

I have updated the panning algorithm to use equal power panning (there was also quite the volume jump when moving to the extremes of each channel) and I have adopted Pro Tools style panning where the left and right channel amplitudes are handled differently depending on the pan direction.

I still need to update the unit test, but perhaps you can check out the panning branch (also see https://github.com/igorski/MWEngine/pull/150) and verify whether the update contents work to your expectation.

vustav commented 2 years ago

Much better!

On a related note I have some automation going on and if a panning is set to happen at a certain step it seems to go of just after the start of the sound, ex. the sound starts at the previous pan and a few ms after the sound starts it pans to the new position. I'm not sure if this was present before, it might have been that the lower sound quality masked it.

igorski commented 2 years ago

Cool (and merged to master branch) :)

For the out of sync automation that would have been present before as the panning calculations have been updated, but not the way they were applied onto the audio buffers.

I think we'd better tackle that in a separate issue. If you can provide how you are applying automation when you describe the issue, we have something to go by. If you are automating, it's best to perform the update in the audio engine's render method where it can be sample accurate and thus in-sync with the render.