Skip to content

BalanceFract32

Overview

Smooth Stereo Balance Module

Discussion

The Fractional Balance module smoothly scales left and right channels as specified by the balance parameter. The module has two multichannel input pins and two multichannel output pins. All dimensions of input and output pins are identical. The balance setting is automatically converted to target gains for left and right channels: gainL and gainR. gainL,R are computed from balance using the sine/cosine panning law: gainL = cos((1+balance)pi/4), and gainR = sin((1+balance)pi/4). Thus: full pan left-->gainL=1,gainR=0; full pan right-->gainL=0, gainR=1; balance=0, (centered) -->gainL=gainR=.707 . Internally currentGainL, currentGainR represent the instaneous smoothed gains applied to the left and right channels. currentGainL,R exponentially approach gainL,R with a time constant equal to smoothingTime. Note: we have only one time constant controlling both left and right channels. currentGainL,R also serve as the starting point of the module. If currentGainL,R = gainL,R then the module starts up in a converged state. If currentGain != gain for either left or right channels then currentGain will smoothly vary until the value of gain is reached.

Module Pack

Standard

ClassID

classID = 136

Type Definition

typedef struct _ModuleBalanceFract32
{
ModuleInstanceDescriptor instance;            // Common Audio Weaver module instance structure
FLOAT32 balance;                              // Left/Right Balance
FLOAT32 smoothingTime;                        // Time constant of the smoothing process
fract32 currentGainLFract32;                  // Instantaneous gain applied to left channel.  This is also the starting gain of the left channel.
fract32 currentGainRFract32;                  // Instantaneous gain applied to right channel.  This is also the starting gain of the right channel.
fract32 smoothingCoeff;                       // Smoothing coefficient
fract32 gainLFract32;                         // Target gain left channel
fract32 gainRFract32;                         // Target gain right channel
} ModuleBalanceFract32Class;

Variables

Properties

Name Type Usage isHidden Default Value Range Units
balance float parameter 0 0 -1:1 linear
smoothingTime float parameter 0 10 0:1000 msec
currentGainLFract32 fract32 state 0 0.707 0:0.9999 linear
currentGainRFract32 fract32 state 0 0.707 0:0.9999 linear
smoothingCoeff fract32 derived 1 0.0020811 Unrestricted
gainLFract32 fract32 derived 1 0.70711 0:0.9999 linear
gainRFract32 fract32 derived 1 0.70711 0:0.9999 linear

Pins

Input Pins

Name in1
Description audio input
Data type fract32
Channel range Unrestricted
Block size range Unrestricted
Sample rate range Unrestricted
Complex support Real
Name in2
Description audio input
Data type fract32
Channel range Unrestricted
Block size range Unrestricted
Sample rate range Unrestricted
Complex support Real

Output Pins

Name out1
Description audio output
Data Type fract32
Name out2
Description audio output
Data Type fract32

Matlab Usage

File Name: balance_fract32_module.m 
 M=balance_fract32_module(NAME) 
 Creates a Fractional balance module for use in the  
 Audio Engine. The module has two multichannel inputs and two 
 multichannel stereo outputs.  Each channel is scaled according to 
 the value of a balance parameter. 
 Arguments: 
   NAME - name of the module. 

Copyright (c) 2026 DSP Concepts, Inc.