13.13. Creating Advanced Stereo Panning Effects
Problem
You want to be able to modify the panning of both the right and left channels of a stereo sound.
Solution
Use the setTransform( )
method.
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);See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access