1 /* PipeWire
2  *
3  * Copyright © 2020 Wim Taymans
4  * Copyright © 2021 Sanchayan Maity <sanchayan@asymptotic.io>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  */
25 
26 #ifndef PULSE_SERVER_VOLUME_H
27 #define PULSE_SERVER_VOLUME_H
28 
29 #include <stdbool.h>
30 #include <stdint.h>
31 
32 #include "format.h"
33 
34 struct spa_pod;
35 
36 struct volume {
37 	uint8_t channels;
38 	float values[CHANNELS_MAX];
39 };
40 
41 #define VOLUME_INIT		\
42 	(struct volume) {	\
43 		.channels = 0,	\
44 	}
45 
46 struct volume_info {
47 	struct volume volume;
48 	struct channel_map map;
49 	bool mute;
50 	float level;
51 	float base;
52 	uint32_t steps;
53 #define VOLUME_HW_VOLUME	(1<<0)
54 #define VOLUME_HW_MUTE		(1<<1)
55 	uint32_t flags;
56 };
57 
58 #define VOLUME_INFO_INIT		\
59 	(struct volume_info) {		\
60 		.volume = VOLUME_INIT,	\
61 		.mute = false,		\
62 		.level = 1.0,		\
63 		.base = 1.0,		\
64 		.steps = 256,		\
65 	}
66 
volume_valid(const struct volume * vol)67 static inline bool volume_valid(const struct volume *vol)
68 {
69 	if (vol->channels == 0 || vol->channels > CHANNELS_MAX)
70 		return false;
71 	return true;
72 }
73 
volume_make(struct volume * vol,uint8_t channels)74 static inline void volume_make(struct volume *vol, uint8_t channels)
75 {
76 	uint8_t i;
77 	for (i = 0; i < channels; i++)
78 		vol->values[i] = 1.0f;
79 	vol->channels = channels;
80 }
81 
82 int volume_compare(struct volume *vol, struct volume *other);
83 int volume_parse_param(const struct spa_pod *param, struct volume_info *info, bool monitor);
84 
85 #endif
86