# Accessing the line gain

CX 2000 boards support input and output gain configurations on network voice ports (timeslots) from -6 dB to +6 dB in one dB increments.

Input gain is applied to the signal received from the network. Output gain is applied to the signal transmitted to the network. The default value for both input line gain and output line gain on CX 2000 boards is nominally 0 dB.

Caution: | Increasing gain can also increase noise, echo, degrade DTMF detection, and possibly cause oscillations on the telephone network. There also may be regulatory authority implications. Use gain with caution.

Decreasing gain may reduce echo and other noise.

This topic describes:

- Getting the line gain

- Setting the line gain

## Getting the line gain

Use swiGetLocalTimeslotInfo to query the input or output line gain. Set the arguments for this function as follows:

Argument | Field | Value
--- | --- | ---
swihd |  | Handle returned by swiOpenSwitch.
args | localstream | 0 or 1. Refer to the CX 2000 switch model.
| localtimeslot | 0..47. Refer to the CX 2000 switch model.
| deviceid | MVIP95_ANALOG_LINE_DEVICE
| parameterid | MVIP95_INPUT_GAIN or MVIP95_OUTPUT_GAIN
buffer |  | Points to the NMS_LINE_GAIN_PARMS structure.
size |  | Size of buffer, in bytes.

The NMS_LINE_GAIN_PARMS structure is:

typedef struct
{
INT32 gain;
} NMS_LINE_GAIN_PARMS;

The value returned in the gain component of NMS_LINE_GAIN_PARMS represents the gain in dB multiplied by 1000. For example, if the input gain on a particular network timeslot is currently set to -3 dB, after calling swiGetLocalTimeslotInfo for parameter MVIP95_INPUT_GAIN, the gain field is -3000.

The following sample code shows how to retrieve line gain applied to a signal received from the network:

#include "swidef.h" /* Natural Access Switching service */
#include "mvip95.h" /* MVIP-95 definitions */
#include "nmshw.h" /* NMS hardware-specific definitions */
DWORD myGetReceiveGain ( SWIHD swihd, SWI_TERMINUS terminus, INT32*
gain_dB )
{
SWI_LOCALTIMESLOT_ARGS args;
NMS_LINE_GAIN_PARMS device ;
DWORD rc ;
args.localstream = terminus.stream ;
args.localtimeslot = terminus.timeslot ;
args.deviceid = MVIP95_ANALOG_LINE_DEVICE ;
args.parameterid = MVIP95_INPUT_GAIN ;
rc = swiGetLocalTimeslotInfo(
swihd, /* Natural Access switch handle */
& args, /* target device and config item */
(void*) & device, /* buffer (defined by parameterid) */
sizeof(device)); /* buffer size in bytes */
*gain_dB = device.gain / 1000 ;
return rc ;
}

The following sample code shows how to retrieve line gain applied to a signal transmitted to the network:

#include "swidef.h" /* Natural Access Switching service */
#include "mvip95.h" /* MVIP-95 definitions */
#include "nmshw.h" /* NMS hardware-specific definitions */
DWORD myGetTransmitGain ( SWIHD swihd, SWI_TERMINUS terminus,
INT32* gain_dB )
{
SWI_LOCALTIMESLOT_ARGS args;
NMS_LINE_GAIN_PARMS device ;
DWORD rc ;
args.localstream = terminus.stream ;
args.localtimeslot = terminus.timeslot ;
args.deviceid = MVIP95_ANALOG_LINE_DEVICE ;
args.parameterid = MVIP95_OUTPUT_GAIN ;
rc = swiGetLocalTimeslotInfo(
swihd, /* Natural Access switch handle */
& args, /* target device and config item */
(void*) & device, /* buffer (defined by parameterid) */
sizeof(device)); /* buffer size in bytes */
*gain_dB = device.gain / 1000 ;
return rc ;
}

## Setting the line gain

Use swiConfigLocalTimeslot to set the input or output line gain. Set the arguments for this function as follows:

Argument | Field | Value
--- | --- | ---
swihd |  | Handle returned by swiOpenSwitch.
args | localstream | 0 or 1. Refer to the CX 2000 switch model.
| localtimeslot | 0..47 (maximum 31 in 32 station models). Refer to the CX 2000 switch model.
| deviceid | MVIP95_ANALOG_LINE_DEVICE
| parameterid | MVIP95_INPUT_GAIN or MVIP95_OUTPUT_GAIN
buffer |  | Points to the NMS_LINE_GAIN_PARMS structure.
size |  | Size of buffer, in bytes.

The NMS_LINE_GAIN_PARMS structure is:

typedef struct
{
INT32 gain;
} NMS_LINE_GAIN_PARMS;

Multiply the desired gain setting in dB by 1000. For example, to set the input line gain on a network voice port to -4 dB, set the gain field of NMS_LINE_GAIN_PARMS to -4000.

The following sample code shows how to configure gain applied to a signal received from the network:

#include "swidef.h" /* Natural Access Switching service */
#include "mvip95.h" /* MVIP-95 definitions */
#include "nmshw.h" /* NMS hardware-specific definitions */
*/
DWORD mySetReceiveGain ( SWIHD swihd, SWI_TERMINUS terminus, INT32 gain_dB )
{
SWI_LOCALTIMESLOT_ARGS args;
NMS_LINE_GAIN_PARMS device ;
args.localstream = terminus.stream ;
args.localtimeslot = terminus.timeslot ;
args.deviceid = MVIP95_ANALOG_LINE_DEVICE ;
args.parameterid = MVIP95_INPUT_GAIN ;
device.gain = gain_dB * 1000 ;
return swiConfigLocalTimeslot (
swihd, /* Natural Access switch handle */
& args, /* target device and config item */
(void*) & device, /* buffer (defined by parameterid) */
sizeof(device)); /* buffer size in bytes */
}

The following sample code shows how to configure line gain applied to a signal transmitted to the network:

#include "swidef.h" /* Natural Access Switching service */
#include "mvip95.h" /* MVIP-95 definitions */
#include "nmshw.h" /* NMS hardware-specific definitions */
*/
DWORD mySetTransmitGain ( SWIHD swihd, SWI_TERMINUS terminus, INT32 gain_dB )
{
SWI_LOCALTIMESLOT_ARGS args;
NMS_LINE_GAIN_PARMS device ;
args.localstream = terminus.stream ;
args.localtimeslot = terminus.timeslot ;
args.deviceid = MVIP95_ANALOG_LINE_DEVICE ;
args.parameterid = MVIP95_OUTPUT_GAIN ;
device.gain = gain_dB * 1000 ;
return swiConfigLocalTimeslot (
swihd, /* Natural Access switch handle */
& args, /* target device and config item */
(void*) & device, /* buffer (defined by parameterid) */
sizeof(device)); /* buffer size in bytes */
}