1*903873ceSHans Petter Selasky /*- 2*903873ceSHans Petter Selasky * Copyright (c) 2021 Christos Margiolis <christos@FreeBSD.org> 3*903873ceSHans Petter Selasky * 4*903873ceSHans Petter Selasky * Permission is hereby granted, free of charge, to any person obtaining a copy 5*903873ceSHans Petter Selasky * of this software and associated documentation files (the "Software"), to deal 6*903873ceSHans Petter Selasky * in the Software without restriction, including without limitation the rights 7*903873ceSHans Petter Selasky * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8*903873ceSHans Petter Selasky * copies of the Software, and to permit persons to whom the Software is 9*903873ceSHans Petter Selasky * furnished to do so, subject to the following conditions: 10*903873ceSHans Petter Selasky * 11*903873ceSHans Petter Selasky * The above copyright notice and this permission notice shall be included in 12*903873ceSHans Petter Selasky * all copies or substantial portions of the Software. 13*903873ceSHans Petter Selasky * 14*903873ceSHans Petter Selasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15*903873ceSHans Petter Selasky * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16*903873ceSHans Petter Selasky * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17*903873ceSHans Petter Selasky * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18*903873ceSHans Petter Selasky * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19*903873ceSHans Petter Selasky * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20*903873ceSHans Petter Selasky * THE SOFTWARE. 21*903873ceSHans Petter Selasky * 22*903873ceSHans Petter Selasky * $FreeBSD$ 23*903873ceSHans Petter Selasky */ 24*903873ceSHans Petter Selasky 25*903873ceSHans Petter Selasky #ifndef _MIXER_H_ 26*903873ceSHans Petter Selasky #define _MIXER_H_ 27*903873ceSHans Petter Selasky 28*903873ceSHans Petter Selasky #include <sys/cdefs.h> 29*903873ceSHans Petter Selasky #include <sys/queue.h> 30*903873ceSHans Petter Selasky #include <sys/soundcard.h> 31*903873ceSHans Petter Selasky 32*903873ceSHans Petter Selasky #include <limits.h> 33*903873ceSHans Petter Selasky 34*903873ceSHans Petter Selasky #define MIX_ISSET(n,f) (((1U << (n)) & (f)) ? 1 : 0) 35*903873ceSHans Petter Selasky #define MIX_ISDEV(m,n) MIX_ISSET(n, (m)->devmask) 36*903873ceSHans Petter Selasky #define MIX_ISMUTE(m,n) MIX_ISSET(n, (m)->mutemask) 37*903873ceSHans Petter Selasky #define MIX_ISREC(m,n) MIX_ISSET(n, (m)->recmask) 38*903873ceSHans Petter Selasky #define MIX_ISRECSRC(m,n) MIX_ISSET(n, (m)->recsrc) 39*903873ceSHans Petter Selasky 40*903873ceSHans Petter Selasky /* Forward declarations */ 41*903873ceSHans Petter Selasky struct mixer; 42*903873ceSHans Petter Selasky struct mix_dev; 43*903873ceSHans Petter Selasky 44*903873ceSHans Petter Selasky typedef struct mix_ctl mix_ctl_t; 45*903873ceSHans Petter Selasky typedef struct mix_volume mix_volume_t; 46*903873ceSHans Petter Selasky 47*903873ceSHans Petter Selasky /* User-defined controls */ 48*903873ceSHans Petter Selasky struct mix_ctl { 49*903873ceSHans Petter Selasky struct mix_dev *parent_dev; /* parent device */ 50*903873ceSHans Petter Selasky int id; /* control id */ 51*903873ceSHans Petter Selasky char name[NAME_MAX]; /* control name */ 52*903873ceSHans Petter Selasky int (*mod)(struct mix_dev *, void *); /* modify control values */ 53*903873ceSHans Petter Selasky int (*print)(struct mix_dev *, void *); /* print control */ 54*903873ceSHans Petter Selasky TAILQ_ENTRY(mix_ctl) ctls; 55*903873ceSHans Petter Selasky }; 56*903873ceSHans Petter Selasky 57*903873ceSHans Petter Selasky struct mix_dev { 58*903873ceSHans Petter Selasky struct mixer *parent_mixer; /* parent mixer */ 59*903873ceSHans Petter Selasky char name[NAME_MAX]; /* device name (e.g "vol") */ 60*903873ceSHans Petter Selasky int devno; /* device number */ 61*903873ceSHans Petter Selasky struct mix_volume { 62*903873ceSHans Petter Selasky #define MIX_VOLMIN 0.0f 63*903873ceSHans Petter Selasky #define MIX_VOLMAX 1.0f 64*903873ceSHans Petter Selasky #define MIX_VOLNORM(v) ((v) / 100.0f) 65*903873ceSHans Petter Selasky #define MIX_VOLDENORM(v) ((int)((v) * 100.0f + 0.5f)) 66*903873ceSHans Petter Selasky float left; /* left volume */ 67*903873ceSHans Petter Selasky float right; /* right volume */ 68*903873ceSHans Petter Selasky } vol; 69*903873ceSHans Petter Selasky int nctl; /* number of controls */ 70*903873ceSHans Petter Selasky TAILQ_HEAD(, mix_ctl) ctls; /* control list */ 71*903873ceSHans Petter Selasky TAILQ_ENTRY(mix_dev) devs; 72*903873ceSHans Petter Selasky }; 73*903873ceSHans Petter Selasky 74*903873ceSHans Petter Selasky struct mixer { 75*903873ceSHans Petter Selasky TAILQ_HEAD(, mix_dev) devs; /* device list */ 76*903873ceSHans Petter Selasky struct mix_dev *dev; /* selected device */ 77*903873ceSHans Petter Selasky oss_mixerinfo mi; /* mixer info */ 78*903873ceSHans Petter Selasky oss_card_info ci; /* audio card info */ 79*903873ceSHans Petter Selasky char name[NAME_MAX]; /* mixer name (e.g /dev/mixer0) */ 80*903873ceSHans Petter Selasky int fd; /* file descriptor */ 81*903873ceSHans Petter Selasky int unit; /* audio card unit */ 82*903873ceSHans Petter Selasky int ndev; /* number of devices */ 83*903873ceSHans Petter Selasky int devmask; /* supported devices */ 84*903873ceSHans Petter Selasky #define MIX_MUTE 0x01 85*903873ceSHans Petter Selasky #define MIX_UNMUTE 0x02 86*903873ceSHans Petter Selasky #define MIX_TOGGLEMUTE 0x04 87*903873ceSHans Petter Selasky int mutemask; /* muted devices */ 88*903873ceSHans Petter Selasky int recmask; /* recording devices */ 89*903873ceSHans Petter Selasky #define MIX_ADDRECSRC 0x01 90*903873ceSHans Petter Selasky #define MIX_REMOVERECSRC 0x02 91*903873ceSHans Petter Selasky #define MIX_SETRECSRC 0x04 92*903873ceSHans Petter Selasky #define MIX_TOGGLERECSRC 0x08 93*903873ceSHans Petter Selasky int recsrc; /* recording sources */ 94*903873ceSHans Petter Selasky #define MIX_MODE_MIXER 0x01 95*903873ceSHans Petter Selasky #define MIX_MODE_PLAY 0x02 96*903873ceSHans Petter Selasky #define MIX_MODE_REC 0x04 97*903873ceSHans Petter Selasky int mode; /* dev.pcm.X.mode sysctl */ 98*903873ceSHans Petter Selasky int f_default; /* default mixer flag */ 99*903873ceSHans Petter Selasky }; 100*903873ceSHans Petter Selasky 101*903873ceSHans Petter Selasky __BEGIN_DECLS 102*903873ceSHans Petter Selasky 103*903873ceSHans Petter Selasky struct mixer *mixer_open(const char *); 104*903873ceSHans Petter Selasky int mixer_close(struct mixer *); 105*903873ceSHans Petter Selasky struct mix_dev *mixer_get_dev(struct mixer *, int); 106*903873ceSHans Petter Selasky struct mix_dev *mixer_get_dev_byname(struct mixer *, const char *); 107*903873ceSHans Petter Selasky int mixer_add_ctl(struct mix_dev *, int, const char *, 108*903873ceSHans Petter Selasky int (*)(struct mix_dev *, void *), int (*)(struct mix_dev *, void *)); 109*903873ceSHans Petter Selasky int mixer_add_ctl_s(mix_ctl_t *); 110*903873ceSHans Petter Selasky int mixer_remove_ctl(mix_ctl_t *); 111*903873ceSHans Petter Selasky mix_ctl_t *mixer_get_ctl(struct mix_dev *, int); 112*903873ceSHans Petter Selasky mix_ctl_t *mixer_get_ctl_byname(struct mix_dev *, const char *); 113*903873ceSHans Petter Selasky int mixer_set_vol(struct mixer *, mix_volume_t); 114*903873ceSHans Petter Selasky int mixer_set_mute(struct mixer *, int); 115*903873ceSHans Petter Selasky int mixer_mod_recsrc(struct mixer *, int); 116*903873ceSHans Petter Selasky int mixer_get_dunit(void); 117*903873ceSHans Petter Selasky int mixer_set_dunit(struct mixer *, int); 118*903873ceSHans Petter Selasky int mixer_get_mode(int); 119*903873ceSHans Petter Selasky int mixer_get_nmixers(void); 120*903873ceSHans Petter Selasky 121*903873ceSHans Petter Selasky __END_DECLS 122*903873ceSHans Petter Selasky 123*903873ceSHans Petter Selasky #endif /* _MIXER_H_ */ 124