]> git.sesse.net Git - vlc/blob - src/control/audio.c
1713ba686b52bb0531a7529820441e9e02365579
[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 <audio_output.h> /* for audio_volume_t, AOUT_VOLUME_MAX */
28 #include <vlc/intf.h>
29
30 /*****************************************************************************
31  * libvlc_audio_get_mute : Get the volume state, true if muted
32  *****************************************************************************/
33 void libvlc_audio_toggle_mute( libvlc_instance_t *p_instance,
34                                libvlc_exception_t *p_exception )
35 {
36     aout_VolumeMute( p_instance->p_vlc, NULL );
37 }
38
39 vlc_bool_t libvlc_audio_get_mute( libvlc_instance_t *p_instance,
40                                   libvlc_exception_t *p_exception )
41 {
42     /*
43      * If the volume level is 0, then the channel is muted
44      */
45     audio_volume_t i_volume;
46
47     i_volume = libvlc_audio_get_volume(p_instance, p_exception);
48     if ( i_volume == 0 )
49         return VLC_TRUE;
50
51     return VLC_FALSE;
52 }
53
54 void libvlc_audio_set_mute( libvlc_instance_t *p_instance, vlc_bool_t status,
55                             libvlc_exception_t *p_exception )
56 {
57     if ( status )
58     {
59         /*
60          * Check if the volume is already muted
61          */
62         if (! libvlc_audio_get_volume( p_instance, p_exception ) )
63         {
64             return;
65         }
66         
67         aout_VolumeMute( p_instance->p_vlc, NULL );
68         return;
69         
70     }
71     else
72     {
73         /*
74          * the aout_VolumeMute is a toggle function, so this is enough.
75          */
76         aout_VolumeMute( p_instance->p_vlc, NULL );
77         return;
78     }
79 }
80
81
82 /*****************************************************************************
83  * libvlc_audio_get_volume : Get the current volume (range 0-200 %)
84  *****************************************************************************/
85 int libvlc_audio_get_volume( libvlc_instance_t *p_instance,
86                              libvlc_exception_t *p_exception )
87 {
88     audio_volume_t i_volume;
89
90     aout_VolumeGet( p_instance->p_vlc, &i_volume );
91
92     return i_volume*200/AOUT_VOLUME_MAX;
93 }
94
95
96 /*****************************************************************************
97  * libvlc_audio_set_volume : Set the current volume
98  *****************************************************************************/
99 void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume,
100                               libvlc_exception_t *p_exception )
101 {
102     if( i_volume >= 0 && i_volume <= 200 )
103     {
104         i_volume = i_volume * AOUT_VOLUME_MAX / 200;
105         aout_VolumeSet( p_instance->p_vlc, i_volume );
106     }
107     else
108     {
109         libvlc_exception_raise( p_exception, "Volume out of range" );
110     }
111 }
112