I made this simple test with an AudioSource with a looping AudioClip, and panning is working!
// Update is called once per frame
void Update()
{
this.transform.position = new Vector3(Mathf.Sin(Time.time) * 100, 0, 0);
}
private void OnAudioFilterRead(float[] data, int channels)
{
for (int i = 0; i < data.Length; i += 2)
{
for (uint channel = 0; channel < channels; channel++)
{
data[i + channel] = data[i + channel];
}
}
}
So like this the spatialization data is mantained (of course, it is a copy! )
So we need to take this into account, the samples we receive in the OAFR callback have to be multiplied in the output, but without increasing the overall volume…