need help understanding msp tutorial 22 : MIDI panning

    Nov 16 2013 | 4:08 pm
    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, "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 | 5:01 pm
      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 tob. 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 | 5:59 pm
      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 | 4:26 pm
      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 | 4:56 pm
      Thanks for that explanation and the further example, it helps a lot.
    • Nov 17 2013 | 5:01 pm
      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 | 5:16 pm
      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 19 2013 | 3:22 am
      Thanks Roman, it's all becoming clear, slowly.