]> code.delx.au - pulseaudio/blob - polyp/volume.h
b2a4808485b5de9e8a53ba3ba94dbe3d6d62c3f4
[pulseaudio] / polyp / volume.h
1 #ifndef foovolumehfoo
2 #define foovolumehfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of polypaudio.
8
9 polypaudio 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 polypaudio 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 polypaudio; 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 <polyp/cdecl.h>
27 #include <polyp/sample.h>
28
29 /** \file
30 * Constants and routines for volume handling */
31
32 PA_C_DECL_BEGIN
33
34 /** Volume specification:
35 * PA_VOLUME_MUTED: silence;
36 * < PA_VOLUME_NORM: decreased volume;
37 * PA_VOLUME_NORM: normal volume;
38 * > PA_VOLUME_NORM: increased volume */
39 typedef uint32_t pa_volume_t;
40
41 /** Normal volume (100%) */
42 #define PA_VOLUME_NORM (0x10000)
43
44 /** Muted volume (0%) */
45 #define PA_VOLUME_MUTED (0)
46
47 /** A structure encapsulating a per-channel volume */
48 typedef struct pa_cvolume {
49 uint8_t channels;
50 pa_volume_t values[PA_CHANNELS_MAX];
51 } pa_cvolume;
52
53 /** Return non-zero when *a == *b */
54 int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b);
55
56 /** Set the volume of all channels to PA_VOLUME_NORM */
57 #define pa_cvolume_reset(a, n) pa_cvolume_set((a), (n), PA_VOLUME_NORM)
58
59 /** Set the volume of all channels to PA_VOLUME_MUTED */
60 #define pa_cvolume_mute(a, n) pa_cvolume_set((a), (n), PA_VOLUME_MUTED)
61
62 /** Set the volume of all channels to the specified parameter */
63 pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v);
64
65 /** Pretty print a volume structure */
66 #define PA_CVOLUME_SNPRINT_MAX 64
67 char *pa_cvolume_snprint(char *s, size_t l, const pa_cvolume *c);
68
69 /** Return the average volume of all channels */
70 pa_volume_t pa_cvolume_avg(const pa_cvolume *a);
71
72 /** Return TRUE when the passed cvolume structure is valid, FALSE otherwise */
73 int pa_cvolume_valid(const pa_cvolume *v);
74
75 /** Return non-zero if the volume of all channels is equal to the specified value */
76 int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v);
77
78 #define pa_cvolume_is_muted(a) pa_cvolume_channels_equal_to((a), PA_VOLUME_MUTED)
79 #define pa_cvolume_is_norm(a) pa_cvolume_channels_equal_to((a), PA_VOLUME_NORM)
80
81 /** Multiply two volumes specifications, return the result. This uses PA_VOLUME_NORM as neutral element of multiplication. */
82 pa_volume_t pa_sw_volume_multiply(pa_volume_t a, pa_volume_t b);
83
84 pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b);
85
86 /** Convert a decibel value to a volume. \since 0.4 */
87 pa_volume_t pa_sw_volume_from_dB(double f);
88
89 /** Convert a volume to a decibel value. \since 0.4 */
90 double pa_sw_volume_to_dB(pa_volume_t v);
91
92 /** Convert a linear factor to a volume. \since 0.8 */
93 pa_volume_t pa_sw_volume_from_linear(double v);
94
95 /** Convert a volume to a linear factor. \since 0.8 */
96 double pa_sw_volume_to_linear(pa_volume_t v);
97
98 #ifdef INFINITY
99 #define PA_DECIBEL_MININFTY (-INFINITY)
100 #else
101 /** This value is used as minus infinity when using pa_volume_{to,from}_dB(). \since 0.4 */
102 #define PA_DECIBEL_MININFTY (-200)
103 #endif
104
105 PA_C_DECL_END
106
107 #endif