I use Rtaudio library and I would like to implement an audio program where I can control the panning (e.g. shifting the sound from the left channel to the right channel).
In my specific case, I use a duplex mode (you can find an example here: duplex mode). It means that I link the microphone input to the speaker output.
Should I apply a filter on the output buffer? What kind of filter?
Can anyone help me?
To reduce the signal on the left, simply multiply every sample on the left by a number less than or equal to 1, let's call it l. Similarly for the right, we'll call that number r. Generally speaking you don't want to multiply by a number greater than 1, or you might cause the signal to distort.
l and r are both functions of the "pan position". How you get from pan position to your numbers is a matter of some discussion. If this is for something simple, you can just ramp the values down linearly, using these values at the extremes:
If this is something fancier, you should google for "pan law". Here's an example that looks like a good start:
http://www.kvraudio.com/forum/viewtopic.php?p=4264576
UPDATE: I've never used RT audio (I usually use PortAudio, which is similar), but I think code to pan would look something like this, with l and r as defined above (assuming a type int32_t - signed 32 bit integer):