setPan method
Sets the stereo panning for the sound on the specified channelId
.
channelId
: The ID of the channel whose panning is to be set.pan
: The panning value, from -1.0 (full left) to 1.0 (full right). 0.0 is center. This is mapped to a 3D position for thePannerNode
to achieve stereo panning.
Implementation
void setPan(int channelId, double pan) {
// Calculate sine and cosine components for 3D positioning
// The 'pan' value is expected to be from -1.0 (full left) to 1.0 (full right).
// This maps it to an angle from -π/2 radians (-90 degrees) to π/2 radians (90 degrees).
var sinPan = sin(pan * pi / 2);
var cosPan = cos(pan * pi / 2);
_channels[channelId]
..pan = pan
..pannerNode.setPosition(sinPan, 0, -cosPan);
}