]> git.sesse.net Git - vlc/blob - src/control/audio.c
A bit of headers cleanup
[vlc] / src / control / audio.c
1 /*****************************************************************************
2  * libvlc_audio.c: New libvlc audio control API
3  *****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Filippo Carone <filippo@carone.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include "libvlc_internal.h"
25 #include <vlc/libvlc.h>
26
27 #include <vlc_aout.h>
28
29 /*****************************************************************************
30  * libvlc_audio_get_mute : Get the volume state, true if muted
31  *****************************************************************************/
32 void libvlc_audio_toggle_mute( libvlc_instance_t *p_instance,
33                                libvlc_exception_t *p_e )
34 {
35     aout_VolumeMute( p_instance->p_libvlc_int, NULL );
36 }
37
38 vlc_bool_t libvlc_audio_get_mute( libvlc_instance_t *p_instance,
39                                   libvlc_exception_t *p_e )
40 {
41     /*
42      * If the volume level is 0, then the channel is muted
43      */
44     audio_volume_t i_volume;
45
46     i_volume = libvlc_audio_get_volume(p_instance, p_e);
47     if ( i_volume == 0 )
48         return VLC_TRUE;
49     return VLC_FALSE;
50 }
51
52 void libvlc_audio_set_mute( libvlc_instance_t *p_instance, vlc_bool_t mute,
53                             libvlc_exception_t *p_e )
54 {
55     if ( mute ^ libvlc_audio_get_mute( p_instance, p_e ) )
56     {
57         aout_VolumeMute( p_instance->p_libvlc_int, NULL );
58     }
59 }
60
61 /*****************************************************************************
62  * libvlc_audio_get_volume : Get the current volume (range 0-200 %)
63  *****************************************************************************/
64 int libvlc_audio_get_volume( libvlc_instance_t *p_instance,
65                              libvlc_exception_t *p_e )
66 {
67     audio_volume_t i_volume;
68
69     aout_VolumeGet( p_instance->p_libvlc_int, &i_volume );
70
71     return (i_volume*200+AOUT_VOLUME_MAX/2)/AOUT_VOLUME_MAX;
72 }
73
74
75 /*****************************************************************************
76  * libvlc_audio_set_volume : Set the current volume
77  *****************************************************************************/
78 void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume,
79                               libvlc_exception_t *p_e )
80 {
81     if( i_volume >= 0 && i_volume <= 200 )
82     {
83         i_volume = (i_volume * AOUT_VOLUME_MAX + 100) / 200;
84
85         aout_VolumeSet( p_instance->p_libvlc_int, i_volume );
86     }
87     else
88     {
89         libvlc_exception_raise( p_e, "Volume out of range" );
90     }
91 }
92