source: mainline/uspace/app/mixerctl/mixerctl.c@ b67968c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b67968c was b67968c, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

uspace/app: Add simple mixerctl utility.

Prints channel volume settings.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup mixerctl
30 * @{
31 */
32/** @file Mixer control for audio devices
33 */
34
35#include <errno.h>
36#include <str_error.h>
37#include <devman.h>
38#include <audio_mixer_iface.h>
39#include <stdio.h>
40
41#define DEFAULT_DEVICE "/hw/pci0/00:01.0/sb16/mixer"
42
43int main(int argc, char *argv[])
44{
45 devman_handle_t mixer_handle;
46 int ret = devman_fun_get_handle(DEFAULT_DEVICE, &mixer_handle, 0);
47 if (ret != EOK) {
48 printf("Failed to get device(%s) handle: %s.\n",
49 DEFAULT_DEVICE, str_error(ret));
50 return 1;
51 }
52
53 async_sess_t *session = devman_device_connect(
54 EXCHANGE_ATOMIC, mixer_handle, IPC_FLAG_BLOCKING);
55 if (!session) {
56 printf("Failed to connect to device.\n");
57 return 1;
58 }
59
60 async_exch_t *exch = async_exchange_begin(session);
61 if (!exch) {
62 printf("Failed to start session exchange.\n");
63 async_hangup(session);
64 return 1;
65 }
66
67 const char* name = NULL;
68 unsigned count = 0;
69 ret = audio_mixer_get_info(exch, &name, &count);
70 if (ret != EOK) {
71 printf("Failed to get mixer info: %s.\n", str_error(ret));
72 return 1;
73 }
74 printf("MIXER: %s.\n", name);
75
76 for (unsigned i = 0; i < count; ++i) {
77 const char *name = NULL;
78 unsigned channels = 0;
79 const int ret =
80 audio_mixer_get_item_info(exch, i, &name, &channels);
81 if (ret != EOK) {
82 printf("Failed to get item %u info: %s.\n",
83 i, str_error(ret));
84 continue;
85 }
86 for (unsigned j = 0; j < channels; ++j) {
87 const char *chan = NULL;
88 int ret = audio_mixer_get_channel_info(
89 exch, i, j, &chan, NULL);
90 if (ret != EOK) {
91 printf(
92 "Failed to get channel %u-%u info: %s.\n",
93 i, j, str_error(ret));
94 }
95 unsigned level = 0, max = 0;
96 ret = audio_mixer_channel_volume_get(
97 exch, i, j, &level, &max);
98 if (ret != EOK) {
99 printf("Failed to get channel %u-%u volume:"
100 " %s.\n", i, j, str_error(ret));
101 }
102 bool mute = false;
103 ret = audio_mixer_channel_mute_get(
104 exch, i, j, &mute);
105 if (ret != EOK) {
106 printf("Failed to get channel %u-%u mute"
107 " status: %s.\n", i, j, str_error(ret));
108 }
109
110 printf("Channel(%u/%u) %s %s volume: %u/%u%s.\n",
111 i, j, name, chan, level, max, mute ? " (M)":"");
112 }
113
114 }
115
116
117 async_exchange_end(exch);
118 async_hangup(session);
119 return 0;
120}
121
122/** @}
123 */
Note: See TracBrowser for help on using the repository browser.