]> code.delx.au - pulseaudio/blob - src/pulse/volume.h
Huge trailing whitespace cleanup. Let's keep the tree pure from here on,
[pulseaudio] / src / pulse / volume.h
1 #ifndef foovolumehfoo
2 #define foovolumehfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of PulseAudio.
8
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
13
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 #include <inttypes.h>
26 #include <pulse/cdecl.h>
27 #include <pulse/sample.h>
28
29 /** \page volume Volume Control
30 *
31 * \section overv_sec Overview
32 *
33 * Sinks, sources, sink inputs and samples can all have their own volumes.
34 * To deal with these, The PulseAudio libray contains a number of functions
35 * that ease handling.
36 *
37 * The basic volume type in PulseAudio is the \ref pa_volume_t type. Most of
38 * the time, applications will use the aggregated pa_cvolume structure that
39 * can store the volume of all channels at once.
40 *
41 * Volumes commonly span between muted (0%), and normal (100%). It is possible
42 * to set volumes to higher than 100%, but clipping might occur.
43 *
44 * \section calc_sec Calculations
45 *
46 * The volumes in PulseAudio are logarithmic in nature and applications
47 * shouldn't perform calculations with them directly. Instead, they should
48 * be converted to and from either dB or a linear scale:
49 *
50 * \li dB - pa_sw_volume_from_dB() / pa_sw_volume_to_dB()
51 * \li Linear - pa_sw_volume_from_linear() / pa_sw_volume_to_linear()
52 *
53 * For simple multiplication, pa_sw_volume_multiply() and
54 * pa_sw_cvolume_multiply() can be used.
55 *
56 * Calculations can only be reliably performed on software volumes
57 * as it is commonly unknown what scale hardware volumes relate to.
58 *
59 * The functions described above are only valid when used with
60 * software volumes. Hence it is usually a better idea to treat all
61 * volume values as opaque with a range from PA_VOLUME_MUTE (0%) to
62 * PA_VOLUME_NORM (100%) and to refrain from any calculations with
63 * them.
64 *
65 * \section conv_sec Convenience Functions
66 *
67 * To handle the pa_cvolume structure, the PulseAudio library provides a
68 * number of convenienc functions:
69 *
70 * \li pa_cvolume_valid() - Tests if a pa_cvolume structure is valid.
71 * \li pa_cvolume_equal() - Tests if two pa_cvolume structures are identical.
72 * \li pa_cvolume_channels_equal_to() - Tests if all channels of a pa_cvolume
73 * structure have a given volume.
74 * \li pa_cvolume_is_muted() - Tests if all channels of a pa_cvolume
75 * structure are muted.
76 * \li pa_cvolume_is_norm() - Tests if all channels of a pa_cvolume structure
77 * are at a normal volume.
78 * \li pa_cvolume_set() - Set all channels of a pa_cvolume structure to a
79 * certain volume.
80 * \li pa_cvolume_reset() - Set all channels of a pa_cvolume structure to a
81 * normal volume.
82 * \li pa_cvolume_mute() - Set all channels of a pa_cvolume structure to a
83 * muted volume.
84 * \li pa_cvolume_avg() - Return the average volume of all channels.
85 * \li pa_cvolume_snprint() - Pretty print a pa_cvolume structure.
86 */
87
88 /** \file
89 * Constants and routines for volume handling */
90
91 PA_C_DECL_BEGIN
92
93 /** Volume specification:
94 * PA_VOLUME_MUTED: silence;
95 * < PA_VOLUME_NORM: decreased volume;
96 * PA_VOLUME_NORM: normal volume;
97 * > PA_VOLUME_NORM: increased volume */
98 typedef uint32_t pa_volume_t;
99
100 /** Normal volume (100%) */
101 #define PA_VOLUME_NORM (0x10000)
102
103 /** Muted volume (0%) */
104 #define PA_VOLUME_MUTED (0)
105
106 /** A structure encapsulating a per-channel volume */
107 typedef struct pa_cvolume {
108 uint8_t channels; /**< Number of channels */
109 pa_volume_t values[PA_CHANNELS_MAX]; /**< Per-channel volume */
110 } pa_cvolume;
111
112 /** Return non-zero when *a == *b */
113 int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b);
114
115 /** Set the volume of all channels to PA_VOLUME_NORM */
116 #define pa_cvolume_reset(a, n) pa_cvolume_set((a), (n), PA_VOLUME_NORM)
117
118 /** Set the volume of all channels to PA_VOLUME_MUTED */
119 #define pa_cvolume_mute(a, n) pa_cvolume_set((a), (n), PA_VOLUME_MUTED)
120
121 /** Set the volume of all channels to the specified parameter */
122 pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v);
123
124 /** Maximum length of the strings returned by pa_cvolume_snprint() */
125 #define PA_CVOLUME_SNPRINT_MAX 64
126
127 /** Pretty print a volume structure */
128 char *pa_cvolume_snprint(char *s, size_t l, const pa_cvolume *c);
129
130 /** Return the average volume of all channels */
131 pa_volume_t pa_cvolume_avg(const pa_cvolume *a);
132
133 /** Return TRUE when the passed cvolume structure is valid, FALSE otherwise */
134 int pa_cvolume_valid(const pa_cvolume *v);
135
136 /** Return non-zero if the volume of all channels is equal to the specified value */
137 int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v);
138
139 /** Return 1 if the specified volume has all channels muted */
140 #define pa_cvolume_is_muted(a) pa_cvolume_channels_equal_to((a), PA_VOLUME_MUTED)
141
142 /** Return 1 if the specified volume has all channels on normal level */
143 #define pa_cvolume_is_norm(a) pa_cvolume_channels_equal_to((a), PA_VOLUME_NORM)
144
145 /** Multiply two volumes specifications, return the result. This uses PA_VOLUME_NORM as neutral element of multiplication. This is only valid for software volumes! */
146 pa_volume_t pa_sw_volume_multiply(pa_volume_t a, pa_volume_t b);
147
148 /** Multiply to per-channel volumes and return the result in *dest. This is only valid for software volumes! */
149 pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b);
150
151 /** Convert a decibel value to a volume. This is only valid for software volumes! \since 0.4 */
152 pa_volume_t pa_sw_volume_from_dB(double f);
153
154 /** Convert a volume to a decibel value. This is only valid for software volumes! \since 0.4 */
155 double pa_sw_volume_to_dB(pa_volume_t v);
156
157 /** Convert a linear factor to a volume. This is only valid for software volumes! \since 0.8 */
158 pa_volume_t pa_sw_volume_from_linear(double v);
159
160 /** Convert a volume to a linear factor. This is only valid for software volumes! \since 0.8 */
161 double pa_sw_volume_to_linear(pa_volume_t v);
162
163 #ifdef INFINITY
164 #define PA_DECIBEL_MININFTY (-INFINITY)
165 #else
166 /** This value is used as minus infinity when using pa_volume_{to,from}_dB(). \since 0.4 */
167 #define PA_DECIBEL_MININFTY (-200)
168 #endif
169
170 PA_C_DECL_END
171
172 #endif