DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 13.13 Creating Advanced Stereo Panning Effects

13.13.1 Problem

You want to be able to modify the panning of both the right and left channels of a stereo sound.

13.13.2 Solution

Use the setTransform( ) method.

13.13.3 Discussion

When working with monaural sounds, the basic getPan( ) and setPan( ) methods suffice. However, when dealing with stereo sounds, you can use the getTransform( ) and setTransform( ) methods to control the panning of each channel.

The setTransform( ) method takes a single parameter: a sound transform object. You can create a sound transform object by creating a generic instance of the Object class with the following properties:

ll

Percentage of the left channel playing through the left speaker

lr

Percentage of the left channel playing through the right speaker

rl

Percentage of the right channel playing through the left speaker

rr

Percentage of the right channel playing through the right speaker

Here is an example in which the right channel is played through the left speaker and the left channel is played through the right speaker:

soundTransform = {ll: 0, lr: 100, rl: 100, rr: 0};
mySound_sound.setTransform(soundTransform);

You can also use getTransform( ) in conjunction with setTransform( ) to perform changes relative to the current settings:

// Get the current transform object.
soundTransform = mySound_sound.getTransform(  );

// Add 50 to the current ll property.
soundTransform.ll += 50;

// Set the new transform object.
mySound_sound.setTransform(soundTransform);

13.13.4 See Also

Recipe 13.12

    [ Team LiB ] Previous Section Next Section