ffmpeg: aphasemeter, meaning of measurement

I tried really hard to find information online about phase and stereo imaging, but information is rather vague. I have been asked to keep the stereo image of an audio track between +0.5 and +1.0 but in the audio engineering world I keep hearing about a stereo image range of 180 degrees broken down into "center 90 range, left 45 range and right 45 range". I can't quite figure out what's asked of me exactly, beyond "don't make things too out of phase" which isn't very specific, especially after the numbers 0.5 and 1.0 have been thrown at me.

So, I remembered that outside of DAWs and goniometers plugins, ffmpeg's aphasemeter filter provides values between 1 and -1 where 1 is totally in phase (mono) and -1 is totally out of phase (I guess left channel and right channel are exactly opposite). This looks like the "between +0.5 and +1.0" requirement I've been asked to abide by.

  1. Over what time span is the output of aphasemeter calculated ? What time span is sensible to use ? Is it good to measure over 300ms like RMS ? Or 50ms because that's the time a 20Hz signal (lowest audible) does a full cycle ?
  2. How is this number between -1 and 1 calculated ?
  3. The phasing detection option of aphasemeter accepts a parameter between 90 and 180: how does that relate to -1 and 1 ?
  4. How does this relate to "center 90, left 45 and right 45", you see in all phase plugins ? I know a hard panned left (signal fully left, right channel muted) would be at the edge of the "center 90 range" and the goniometer would be leaning left at a 45 degree angle. Does that result in aphasemeter outputting 0.5 ? Edit: no it does not, I've tried to discard the right channel of an audio and evaluate phase with a phase meter, and it is not constant. Also I tried make left and right channel identical: the output is always 1.0 which is expected, but when I make left and right channel perfectly opposite, I don't always get -1.0 as output (actually I get it only rarely) but the output values are consistently negative. I don't really understand then what aphasemeter is outputting

Thank you for shedding some light on what these numbers really mean.


Solution 1:

Audio is comprised of samples. A 48000 Hz stereo stream has 48000 samples in each channel (left and right) for each second of audio. However, these samples are chunked into frames; a typical frame size is 1024 samples (of each channel) but different codecs use different sizes. These samples may have varying bit depth and be either integer or floating-point values.

What the aphasemeter filter does is first convert the source stream to floating point so each sample value is between +1 and -1. It also converts it to a stereo stream. This means that all other channel layouts (mono, 5.1 ..etc) are rematrixed to stereo. Then for each pair of samples in a frame, it will calculate

   left * right * 2
-----------------------
left*left + right*right

This is the phase difference for a pair of samples. If the denominator is 0, then phase difference is 1. The mean phase across all pairs of samples in a frame is the phase difference measurement for that frame.

As for how these values correspond to angles, this answer may be of use: https://dsp.stackexchange.com/a/10916