Forums > MaxMSP

need help understanding msp tutorial 22 : MIDI panning

Nov 16 2013 | 8:08 am

Hey,
i’m trying to understand the equations used in the "speaker-so-speaker xfade" subpatch of the maxMSP tutorial 22 ; about MIDI panning. It’s all about trigonometry, and so far i quite understood the equations after some time of Wikipedia trigonometry page ; but i just don’t understand what we are trying to calculate with that final equation : "a cos(y±x)/d" (see http://www.cycling74.com/docs/max5/tutorials/msp-tut/mspchapter22.html, "speaker-to-speaker crossfade" section, "technical detail" paragraph. The offline max documentation doesn’t have that paragraph, which is odd, i submitted a report about that)
Those are the left gain and right gain, only later normalized by a 2/(a+b) coefficient in order to avoid saturation ; but i don’t understand what it does relate to, geometrically. I’m not even sure it has any geometrical meaning !… (by "geometrically" i’m refering to the schema included in the tutorial)

Nov 16 2013 | 9:01 am

Well, for starters, the text in that paragraph of the Max 6 documentation is completely garbled and wrong. Here is the correct text, from the MaxMSP 4.6 documentation.

Technical detail: If we know the angle of the speakers (x and -x), we can
use the cosine function to calculate distance a relative to distance b.
Similarly we can use the tangent function to calculate distance c relative to
b. The distance between the speakers is thus 2c, and as the MIDI pan value
varies away from its center value of 64 it can be mapped as an offset (o)
from the center ranging from -c to +c. Knowing b and o, we can use the
Pythagorean theorem to obtain the distance (d) of the source from the
listener, and we can use the arctangent function to find its angle (y).
Armed with all of this information, we can finally calculate the gain for the
two channels as a cos(y±x)/d.

Nov 16 2013 | 9:59 am

Wow. Two pieces of sentences missing. But i somehow had figured out most of that… it doesn’t tell what those gains relate to ; what does that final calcul mean ?

Nov 17 2013 | 8:26 am

That formula is used to calculate the relative amplitude assigned to the two speakers. a/d is the ratio of speaker distance to source distance; that ratio increases as the source approaches the center, which makes the sound seem louder as it approaches the center (amplitude is proportional to 1/d). cos(y+x) and cos(y-x) give the relative amplitudes of the two speakers. You can see this implemented in the subpatch. As part of that calculation, the results are scaled by an overall normalizing factor to avoid clipping. Also, if the source is more than 90° from a speaker, its amplitude is set to 0.

I dare say it’s not the simplest explanation one could give. :) It’s simpler just to use the "constant-distance" panning algorithm to give the azimuth angle effect, and use the source’s distance from the listener (calculated with the Pythagorean theorem) to scale the amplitude (multiply it by 1/d), as in this example:
Example 17: Calculating doppler shift for moving virtual sound sources.

Nov 17 2013 | 8:56 am

Thanks for that explanation and the further example, it helps a lot.

Nov 17 2013 | 9:01 am

about the relative amplitude of the speakers, does that mean it’s a similar logic than the formulaes used in subpatcher "constant distance xfade", only with a a/d ratio increasing the overall amplitude as soundsource comes close to the center ? and why set volume to 0 if source is more than 90° from a speaker (maybe to avoid the recursivity of used functions, which would begin to increase the volume again, in the negative range – then is that not related to how ambisonics works with out-of-phase signals ?) ?

Nov 17 2013 | 9:16 am

what it relates to? well, the cosine function is giving you half a circle.
one time a linear to quadratic conversion, and one time a reversed linear to quadratic conversion.

you could reach the same by using [pow 2.] for each of the two halfes (right to center, center to left)

Nov 18 2013 | 7:22 pm

Thanks Roman, it’s all becoming clear, slowly.

Viewing 8 posts - 1 through 8 (of 8 total)

Forums > MaxMSP