[1561] | 1 | //volume.c: |
---|
[1559] | 2 | |
---|
| 3 | /* |
---|
[6052] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2015 |
---|
[1559] | 5 | * The code (may) include prototypes and comments (and maybe |
---|
[4038] | 6 | * other code fragements) from OpenBSD's sndio. |
---|
[4050] | 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 --- |
---|
[1559] | 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 |
---|
[3517] | 41 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 42 | * Boston, MA 02110-1301, USA. |
---|
[1559] | 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 | |
---|
[1571] | 50 | #define ROAR_USE_OWN_SNDIO_HDL |
---|
[1559] | 51 | #include "libroarsndio.h" |
---|
| 52 | |
---|
[1561] | 53 | int sio_setvol (struct sio_hdl * hdl, unsigned vol) { |
---|
[1575] | 54 | struct roar_mixer_settings mixer; |
---|
[3640] | 55 | unsigned int i; |
---|
[1575] | 56 | |
---|
| 57 | if ( hdl == NULL ) |
---|
| 58 | return 0; |
---|
| 59 | |
---|
| 60 | if ( vol > SIO_MAXVOL ) |
---|
| 61 | return 0; |
---|
| 62 | |
---|
[3537] | 63 | mixer.scale = SIO_MAXVOL; |
---|
[1575] | 64 | mixer.rpg_mul = 1; |
---|
| 65 | mixer.rpg_div = 1; |
---|
[5235] | 66 | mixer.mixer[0] = vol; |
---|
| 67 | |
---|
[5236] | 68 | if ( roar_set_vol(&(hdl->con), roar_stream_get_id(&(hdl->stream)), &mixer, 0, ROAR_SET_VOL_UNMAPPED) == -1 ) |
---|
[5235] | 69 | return 0; |
---|
[1575] | 70 | |
---|
| 71 | for (i = 0; i < hdl->info.channels; i++) |
---|
[3537] | 72 | mixer.mixer[i] = vol; |
---|
[1575] | 73 | |
---|
[5236] | 74 | if ( roar_set_vol(&(hdl->con), roar_stream_get_id(&(hdl->stream)), &mixer, hdl->info.channels, ROAR_SET_VOL_ALL) == -1 ) |
---|
[1575] | 75 | return 0; |
---|
| 76 | |
---|
| 77 | if ( hdl->on_vol != NULL ) |
---|
| 78 | hdl->on_vol(hdl->on_vol_arg, vol); |
---|
| 79 | |
---|
| 80 | return 1; |
---|
[1561] | 81 | } |
---|
| 82 | |
---|
[1711] | 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 | |
---|
[1559] | 91 | //ll |
---|