Logo Search packages:      
Sourcecode: pulseaudio version File versions  Download package

pa_cvolume* pa_cvolume_set_balance ( pa_cvolume v,
const pa_channel_map map,
float  new_balance 
)

Adjust the 'balance' value for the specified volume with the specified channel map. v will be modified in place and returned. The balance is a value between -1.0f and +1.0f. This operation might not be reversible! Also, after this call pa_cvolume_get_balance() is not guaranteed to actually return the requested balance value (e.g. when the input volume was zero anyway for all channels). If no balance value is applicable to this channel map the volume will not be modified. See pa_channel_map_can_balance().

Since:
0.9.15

Definition at line 639 of file volume.c.

References pa_channel_map::channels, pa_channel_map::map, pa_volume_t, and pa_cvolume::values.

                                                                                                {
    pa_volume_t left, nleft, right, nright, m;
    unsigned c;

    pa_assert(map);
    pa_assert(v);

    pa_return_val_if_fail(pa_cvolume_compatible_with_channel_map(v, map), NULL);
    pa_return_val_if_fail(new_balance >= -1.0f, NULL);
    pa_return_val_if_fail(new_balance <= 1.0f, NULL);

    if (!pa_channel_map_can_balance(map))
        return v;

    get_avg_lr(map, v, &left, &right);

    m = PA_MAX(left, right);

    if (new_balance <= 0) {
        nright  = (new_balance + 1.0f) * m;
        nleft = m;
    } else  {
        nleft = (1.0f - new_balance) * m;
        nright = m;
    }

    for (c = 0; c < map->channels; c++) {
        if (on_left(map->map[c])) {
            if (left == 0)
                v->values[c] = nleft;
            else
                v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nleft) / (uint64_t) left);
        } else if (on_right(map->map[c])) {
            if (right == 0)
                v->values[c] = nright;
            else
                v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nright) / (uint64_t) right);
        }
    }

    return v;
}

Generated by  Doxygen 1.6.0   Back to index