1 | //volume.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2015 |
---|
5 | * The code (may) include prototypes and comments (and maybe |
---|
6 | * other code fragements) from OpenBSD's sndio. |
---|
7 | * See 'Copyright for sndio' below for more information on |
---|
8 | * code fragments taken from OpenBSD's sndio. |
---|
9 | * |
---|
10 | * --- Copyright for sndio --- |
---|
11 | * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> |
---|
12 | * |
---|
13 | * Permission to use, copy, modify, and distribute this software for any |
---|
14 | * purpose with or without fee is hereby granted, provided that the above |
---|
15 | * copyright notice and this permission notice appear in all copies. |
---|
16 | * |
---|
17 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
---|
18 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
---|
19 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
---|
20 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
---|
21 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
---|
22 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
---|
23 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
---|
24 | * --- End of Copyright for sndio --- |
---|
25 | * |
---|
26 | * This file is part of libroaresd a part of RoarAudio, |
---|
27 | * a cross-platform sound system for both, home and professional use. |
---|
28 | * See README for details. |
---|
29 | * |
---|
30 | * This file is free software; you can redistribute it and/or modify |
---|
31 | * it under the terms of the GNU General Public License version 3 |
---|
32 | * as published by the Free Software Foundation. |
---|
33 | * |
---|
34 | * RoarAudio is distributed in the hope that it will be useful, |
---|
35 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
36 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
37 | * GNU General Public License for more details. |
---|
38 | * |
---|
39 | * You should have received a copy of the GNU General Public License |
---|
40 | * along with this software; see the file COPYING. If not, write to |
---|
41 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
42 | * Boston, MA 02110-1301, USA. |
---|
43 | * |
---|
44 | * NOTE for everyone want's to change something and send patches: |
---|
45 | * read README and HACKING! There a addition information on |
---|
46 | * the license of this document you need to read before you send |
---|
47 | * any patches. |
---|
48 | */ |
---|
49 | |
---|
50 | #define ROAR_USE_OWN_SNDIO_HDL |
---|
51 | #include "libroarsndio.h" |
---|
52 | |
---|
53 | int sio_setvol (struct sio_hdl * hdl, unsigned vol) { |
---|
54 | struct roar_mixer_settings mixer; |
---|
55 | unsigned int i; |
---|
56 | |
---|
57 | if ( hdl == NULL ) |
---|
58 | return 0; |
---|
59 | |
---|
60 | if ( vol > SIO_MAXVOL ) |
---|
61 | return 0; |
---|
62 | |
---|
63 | mixer.scale = SIO_MAXVOL; |
---|
64 | mixer.rpg_mul = 1; |
---|
65 | mixer.rpg_div = 1; |
---|
66 | mixer.mixer[0] = vol; |
---|
67 | |
---|
68 | if ( roar_set_vol(&(hdl->con), roar_stream_get_id(&(hdl->stream)), &mixer, 0, ROAR_SET_VOL_UNMAPPED) == -1 ) |
---|
69 | return 0; |
---|
70 | |
---|
71 | for (i = 0; i < hdl->info.channels; i++) |
---|
72 | mixer.mixer[i] = vol; |
---|
73 | |
---|
74 | if ( roar_set_vol(&(hdl->con), roar_stream_get_id(&(hdl->stream)), &mixer, hdl->info.channels, ROAR_SET_VOL_ALL) == -1 ) |
---|
75 | return 0; |
---|
76 | |
---|
77 | if ( hdl->on_vol != NULL ) |
---|
78 | hdl->on_vol(hdl->on_vol_arg, vol); |
---|
79 | |
---|
80 | return 1; |
---|
81 | } |
---|
82 | |
---|
83 | void sio_onvol (struct sio_hdl * hdl, void (*cb)(void * arg, unsigned vol), void * arg) { |
---|
84 | if ( hdl == NULL ) |
---|
85 | return; |
---|
86 | |
---|
87 | hdl->on_vol = cb; |
---|
88 | hdl->on_vol_arg = arg; |
---|
89 | } |
---|
90 | |
---|
91 | //ll |
---|