2 * This file is part of DisOrder
3 * Copyright (C) 2007 Richard Kettlewell
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @brief Mixer support
24 #include "configuration.h"
29 /** @brief Whether lack of volume support has been reported yet */
30 static int none_reported
;
32 /** @brief Get/set volume stub if volume control is not supported */
33 static int none_get_set(int attribute((unused
)) *left
,
34 int attribute((unused
)) *right
) {
36 error(0, "don't know how to get/set volume with this api");
42 /** @brief Stub mixer control */
43 static const struct mixer mixer_none
= {
51 /** @brief Table of mixer definitions */
52 static const struct mixer
*mixers
[] = {
53 #if HAVE_SYS_SOUNDCARD_H
56 #if HAVE_ALSA_ASOUNDLIB_H
59 &mixer_none
/* make sure array is never empty */
62 /** @brief Number of mixer definitions */
63 #define NMIXERS (sizeof mixers / sizeof *mixers)
65 /** @brief Find the mixer definition */
66 static const struct mixer
*find_mixer(int api
) {
71 for(n
= 0; n
< NMIXERS
; ++n
)
72 if(mixers
[n
]->api
== api
)
77 /** @brief Return true if we know how to drive the mixer
78 * @param api Sound api or -1 for default
79 * @return true if suppored, false otherwise
81 int mixer_supported(int api
) {
82 const struct mixer
*const m
= find_mixer(api
);
83 return m
!= &mixer_none
;
86 /** @brief Get/set volume
87 * @param api Sound api or -1 for default
88 * @param left Left channel level, 0-100
89 * @param right Right channel level, 0-100
90 * @param set Set volume if non-0
91 * @return 0 on success, non-0 on error
93 * If getting the volume then @p left and @p right are filled in.
95 * If setting the volume then the target levels are read from @p left and
96 * @p right, and the actual level set is stored in them.
98 int mixer_control(int api
, int *left
, int *right
, int set
) {
99 const struct mixer
*const m
= find_mixer(api
);
101 /* We impose defaults bizarrely late, but this has the advantage of
102 * not making everything depend on sound libraries */
104 config
->mixer
= xstrdup(m
->device
);
106 config
->channel
= xstrdup(m
->channel
);
108 return m
->set(left
, right
);
110 return m
->get(left
, right
);