PulseAudio 16.1

Volume Control

# Overview

Sinks, sources, sink inputs, source outputs and samples can all have their own volumes. To deal with these, The PulseAudio library contains a number of functions that ease handling.

The basic volume type in PulseAudio is the pa_volume_t type. Most of the time, applications will use the aggregated pa_cvolume structure that can store the volume of all channels at once.

Volumes commonly span between muted (0%), and normal (100%). It is possible to set volumes to higher than 100%, but clipping might occur.

There is no single well-defined meaning attached to the 100% volume for a sink input. In fact, it depends on the server configuration. With flat volumes enabled, it means the maximum volume that the sound hardware is capable of, which is usually so high that you absolutely must not set sink input volume to 100% unless the the user explicitly requests that (note that usually you shouldn't set the volume anyway if the user doesn't explicitly request it, instead, let PulseAudio decide the volume for the sink input). With flat volumes disabled the sink input volume is relative to the sink volume, so 100% sink input volume means that the sink input is played at the current sink volume level. In this case 100% is often a good default volume for a sink input, although you still should let PulseAudio decide the default volume. It is possible to figure out whether flat volume mode is in effect for a given sink by calling pa_context_get_sink_info_by_name().

# Calculations

The volumes in PulseAudio are cubic in nature and applications shouldn't perform calculations with them directly. Instead, they should be converted to and from either dB or a linear scale:

- dB - pa_sw_volume_from_dB() / pa_sw_volume_to_dB()
- Linear - pa_sw_volume_from_linear() / pa_sw_volume_to_linear()

For simple multiplication, pa_sw_volume_multiply() and pa_sw_cvolume_multiply() can be used.

It's often unknown what scale hardware volumes relate to. Don't use the above functions on sink and source volumes, unless the sink or source in question has the PA_SINK_DECIBEL_VOLUME or PA_SOURCE_DECIBEL_VOLUME flag set. The conversion functions are rarely needed anyway, most of the time it's sufficient to treat all volumes as opaque with a range from PA_VOLUME_MUTED (0%) to PA_VOLUME_NORM (100%).

# Convenience Functions

To handle the pa_cvolume structure, the PulseAudio library provides a number of convenience functions:

- pa_cvolume_valid() - Tests if a pa_cvolume structure is valid.
- pa_cvolume_equal() - Tests if two pa_cvolume structures are identical.
- pa_cvolume_channels_equal_to() - Tests if all channels of a pa_cvolume structure have a given volume.
- pa_cvolume_is_muted() - Tests if all channels of a pa_cvolume structure are muted.
- pa_cvolume_is_norm() - Tests if all channels of a pa_cvolume structure are at a normal volume.
- pa_cvolume_set() - Set the first n channels of a pa_cvolume structure to a certain volume.
- pa_cvolume_reset() - Set the first n channels of a pa_cvolume structure to a normal volume.
- pa_cvolume_mute() - Set the first n channels of a pa_cvolume structure to a muted volume.
- pa_cvolume_avg() - Return the average volume of all channels.
- pa_cvolume_snprint() - Pretty print a pa_cvolume structure.