Pan law in MixedSound

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Pan law in MixedSound

Stéphane Rollandin
Since we are dicussing MixedSound, I have a proposal, currently
implemented in muO, for a better panning, by using a -4.5 dB pan law as
explained here:
http://www.cs.cmu.edu/~music/icm-online/readings/panlaws/index.html


So I propose in MixedSound

add: aSound pan: leftRightPan volume: volume
        "Add the given sound with the given left-right pan, where 0.0 is full
left, 1.0 is full right, and 0.5 is centered. The loudness of the sound
will be scaled by volume, which ranges from 0 to 1.0."

        |  vol |

        vol := (volume max: 0.0) min: 1.0.
        sounds := sounds copyWith: aSound.

        (self class panValuesFor: leftRightPan) allIn: [:leftPan :rightPan |
                leftVols := leftVols copyWith: (leftPan * vol) rounded.
                rightVols := rightVols copyWith: (rightPan * vol) rounded]


where, on the class side, we have

panValuesFor: aPos

        "aPos ranges from 0.0 to 1.0 (Squeak convention)"

        ^  (MusicMachine db45PanAt: (aPos * 2) - 1) collect: [:ea |
                ((ea * ScaleFactor) rounded max: 0) min: ScaleFactor]


The MusicMachine class is in muO, so it would have to be refactored
here. The code is

db45PanAt: pNumber

        "pNumber ranges from -1 (45 degrees left) to 1 (45 degrees right)"

        "Uses -4.5 dB pan law
ref: http://www.cs.cmu.edu/~music/icm-online/readings/panlaws/index.html"

        | theta |

        theta := (pNumber + 1) * Float pi / 4.

        ^ {
                "left" (theta cos * (Float halfPi - theta) / Float halfPi) sqrt.
                "right" (theta sin * theta / Float halfPi) sqrt
        }


Stef