xref: /freebsd/lib/libmixer/mixer.h (revision fff236e89d8af195e9fc7b458841522e8a5378b6)
1903873ceSHans Petter Selasky /*-
2903873ceSHans Petter Selasky  * Copyright (c) 2021 Christos Margiolis <christos@FreeBSD.org>
3903873ceSHans Petter Selasky  *
4903873ceSHans Petter Selasky  * Permission is hereby granted, free of charge, to any person obtaining a copy
5903873ceSHans Petter Selasky  * of this software and associated documentation files (the "Software"), to deal
6903873ceSHans Petter Selasky  * in the Software without restriction, including without limitation the rights
7903873ceSHans Petter Selasky  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8903873ceSHans Petter Selasky  * copies of the Software, and to permit persons to whom the Software is
9903873ceSHans Petter Selasky  * furnished to do so, subject to the following conditions:
10903873ceSHans Petter Selasky  *
11903873ceSHans Petter Selasky  * The above copyright notice and this permission notice shall be included in
12903873ceSHans Petter Selasky  * all copies or substantial portions of the Software.
13903873ceSHans Petter Selasky  *
14903873ceSHans Petter Selasky  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15903873ceSHans Petter Selasky  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16903873ceSHans Petter Selasky  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17903873ceSHans Petter Selasky  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18903873ceSHans Petter Selasky  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19903873ceSHans Petter Selasky  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20903873ceSHans Petter Selasky  * THE SOFTWARE.
21903873ceSHans Petter Selasky  *
22903873ceSHans Petter Selasky  * $FreeBSD$
23903873ceSHans Petter Selasky  */
24903873ceSHans Petter Selasky 
25903873ceSHans Petter Selasky #ifndef _MIXER_H_
26903873ceSHans Petter Selasky #define _MIXER_H_
27903873ceSHans Petter Selasky 
28903873ceSHans Petter Selasky #include <sys/cdefs.h>
29903873ceSHans Petter Selasky #include <sys/queue.h>
30*fff236e8SHans Petter Selasky #include <sys/soundcard.h>
31903873ceSHans Petter Selasky 
32903873ceSHans Petter Selasky #include <limits.h>
33903873ceSHans Petter Selasky 
34903873ceSHans Petter Selasky #define MIX_ISSET(n,f)		(((1U << (n)) & (f)) ? 1 : 0)
35903873ceSHans Petter Selasky #define MIX_ISDEV(m,n)		MIX_ISSET(n, (m)->devmask)
36903873ceSHans Petter Selasky #define MIX_ISMUTE(m,n)		MIX_ISSET(n, (m)->mutemask)
37903873ceSHans Petter Selasky #define MIX_ISREC(m,n)		MIX_ISSET(n, (m)->recmask)
38903873ceSHans Petter Selasky #define MIX_ISRECSRC(m,n)	MIX_ISSET(n, (m)->recsrc)
39903873ceSHans Petter Selasky 
40903873ceSHans Petter Selasky /* Forward declarations */
41903873ceSHans Petter Selasky struct mixer;
42903873ceSHans Petter Selasky struct mix_dev;
43903873ceSHans Petter Selasky 
44903873ceSHans Petter Selasky typedef struct mix_ctl mix_ctl_t;
45903873ceSHans Petter Selasky typedef struct mix_volume mix_volume_t;
46903873ceSHans Petter Selasky 
47903873ceSHans Petter Selasky /* User-defined controls */
48903873ceSHans Petter Selasky struct mix_ctl {
49903873ceSHans Petter Selasky 	struct mix_dev *parent_dev;		/* parent device */
50903873ceSHans Petter Selasky 	int id;					/* control id */
51903873ceSHans Petter Selasky 	char name[NAME_MAX];			/* control name */
52903873ceSHans Petter Selasky 	int (*mod)(struct mix_dev *, void *);	/* modify control values */
53903873ceSHans Petter Selasky 	int (*print)(struct mix_dev *, void *);	/* print control */
54903873ceSHans Petter Selasky 	TAILQ_ENTRY(mix_ctl) ctls;
55903873ceSHans Petter Selasky };
56903873ceSHans Petter Selasky 
57903873ceSHans Petter Selasky struct mix_dev {
58903873ceSHans Petter Selasky 	struct mixer *parent_mixer;		/* parent mixer */
59903873ceSHans Petter Selasky 	char name[NAME_MAX];			/* device name (e.g "vol") */
60903873ceSHans Petter Selasky 	int devno;				/* device number */
61903873ceSHans Petter Selasky 	struct mix_volume {
62903873ceSHans Petter Selasky #define MIX_VOLMIN		0.0f
63903873ceSHans Petter Selasky #define MIX_VOLMAX		1.0f
64903873ceSHans Petter Selasky #define MIX_VOLNORM(v)		((v) / 100.0f)
65903873ceSHans Petter Selasky #define MIX_VOLDENORM(v)	((int)((v) * 100.0f + 0.5f))
66903873ceSHans Petter Selasky 		float left;			/* left volume */
67903873ceSHans Petter Selasky 		float right;			/* right volume */
68903873ceSHans Petter Selasky 	} vol;
69903873ceSHans Petter Selasky 	int nctl;				/* number of controls */
70903873ceSHans Petter Selasky 	TAILQ_HEAD(, mix_ctl) ctls;		/* control list */
71903873ceSHans Petter Selasky 	TAILQ_ENTRY(mix_dev) devs;
72903873ceSHans Petter Selasky };
73903873ceSHans Petter Selasky 
74903873ceSHans Petter Selasky struct mixer {
75903873ceSHans Petter Selasky 	TAILQ_HEAD(, mix_dev) devs;		/* device list */
76903873ceSHans Petter Selasky 	struct mix_dev *dev;			/* selected device */
77903873ceSHans Petter Selasky 	oss_mixerinfo mi;			/* mixer info */
78903873ceSHans Petter Selasky 	oss_card_info ci;			/* audio card info */
79903873ceSHans Petter Selasky 	char name[NAME_MAX];			/* mixer name (e.g /dev/mixer0) */
80903873ceSHans Petter Selasky 	int fd;					/* file descriptor */
81903873ceSHans Petter Selasky 	int unit;				/* audio card unit */
82903873ceSHans Petter Selasky 	int ndev;				/* number of devices */
83903873ceSHans Petter Selasky 	int devmask;				/* supported devices */
84903873ceSHans Petter Selasky #define MIX_MUTE		0x01
85903873ceSHans Petter Selasky #define MIX_UNMUTE		0x02
86903873ceSHans Petter Selasky #define MIX_TOGGLEMUTE		0x04
87903873ceSHans Petter Selasky 	int mutemask;				/* muted devices */
88903873ceSHans Petter Selasky 	int recmask;				/* recording devices */
89903873ceSHans Petter Selasky #define MIX_ADDRECSRC		0x01
90903873ceSHans Petter Selasky #define MIX_REMOVERECSRC	0x02
91903873ceSHans Petter Selasky #define MIX_SETRECSRC		0x04
92903873ceSHans Petter Selasky #define MIX_TOGGLERECSRC	0x08
93903873ceSHans Petter Selasky 	int recsrc;				/* recording sources */
94903873ceSHans Petter Selasky #define MIX_MODE_MIXER		0x01
95903873ceSHans Petter Selasky #define MIX_MODE_PLAY		0x02
96903873ceSHans Petter Selasky #define MIX_MODE_REC		0x04
97903873ceSHans Petter Selasky 	int mode;				/* dev.pcm.X.mode sysctl */
98903873ceSHans Petter Selasky 	int f_default;				/* default mixer flag */
99903873ceSHans Petter Selasky };
100903873ceSHans Petter Selasky 
101903873ceSHans Petter Selasky __BEGIN_DECLS
102903873ceSHans Petter Selasky 
103903873ceSHans Petter Selasky struct mixer *mixer_open(const char *);
104903873ceSHans Petter Selasky int mixer_close(struct mixer *);
105903873ceSHans Petter Selasky struct mix_dev *mixer_get_dev(struct mixer *, int);
106903873ceSHans Petter Selasky struct mix_dev *mixer_get_dev_byname(struct mixer *, const char *);
107903873ceSHans Petter Selasky int mixer_add_ctl(struct mix_dev *, int, const char *,
108903873ceSHans Petter Selasky     int (*)(struct mix_dev *, void *), int (*)(struct mix_dev *, void *));
109903873ceSHans Petter Selasky int mixer_add_ctl_s(mix_ctl_t *);
110903873ceSHans Petter Selasky int mixer_remove_ctl(mix_ctl_t *);
111903873ceSHans Petter Selasky mix_ctl_t *mixer_get_ctl(struct mix_dev *, int);
112903873ceSHans Petter Selasky mix_ctl_t *mixer_get_ctl_byname(struct mix_dev *, const char *);
113903873ceSHans Petter Selasky int mixer_set_vol(struct mixer *, mix_volume_t);
114903873ceSHans Petter Selasky int mixer_set_mute(struct mixer *, int);
115903873ceSHans Petter Selasky int mixer_mod_recsrc(struct mixer *, int);
116903873ceSHans Petter Selasky int mixer_get_dunit(void);
117903873ceSHans Petter Selasky int mixer_set_dunit(struct mixer *, int);
118903873ceSHans Petter Selasky int mixer_get_mode(int);
119903873ceSHans Petter Selasky int mixer_get_nmixers(void);
120903873ceSHans Petter Selasky 
121903873ceSHans Petter Selasky __END_DECLS
122903873ceSHans Petter Selasky 
123903873ceSHans Petter Selasky #endif /* _MIXER_H_ */
124