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 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * @brief Mixer support
26 #include "configuration.h"
31 /** @brief Whether lack of volume support has been reported yet */
32 static int none_reported;
34 /** @brief Get/set volume stub if volume control is not supported */
35 static int none_get_set(int attribute((unused)) *left,
36 int attribute((unused)) *right) {
38 error(0, "don't know how to get/set volume with this api");
44 /** @brief Stub mixer control */
45 static const struct mixer mixer_none = {
53 /** @brief Table of mixer definitions */
54 static const struct mixer *mixers[] = {
55 #if HAVE_SYS_SOUNDCARD_H
58 #if HAVE_ALSA_ASOUNDLIB_H
61 &mixer_none /* make sure array is never empty */
64 /** @brief Number of mixer definitions */
65 #define NMIXERS (sizeof mixers / sizeof *mixers)
67 /** @brief Find the mixer definition */
68 static const struct mixer *find_mixer(int api) {
73 for(n = 0; n < NMIXERS; ++n)
74 if(mixers[n]->api == api)
79 /** @brief Return true if we know how to drive the mixer
80 * @param api Sound api or -1 for default
81 * @return true if suppored, false otherwise
83 int mixer_supported(int api) {
84 const struct mixer *const m = find_mixer(api);
85 return m != &mixer_none;
88 /** @brief Get/set volume
89 * @param api Sound api or -1 for default
90 * @param left Left channel level, 0-100
91 * @param right Right channel level, 0-100
92 * @param set Set volume if non-0
93 * @return 0 on success, non-0 on error
95 * If getting the volume then @p left and @p right are filled in.
97 * If setting the volume then the target levels are read from @p left and
98 * @p right, and the actual level set is stored in them.
100 int mixer_control(int api, int *left, int *right, int set) {
101 const struct mixer *const m = find_mixer(api);
103 /* We impose defaults bizarrely late, but this has the advantage of
104 * not making everything depend on sound libraries */
106 config->mixer = xstrdup(m->device);
108 config->channel = xstrdup(m->channel);
110 return m->set(left, right);
112 return m->get(left, right);