1 /*****************************************************************************
2 * libvlc_audio.c: New libvlc audio control API
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Filippo Carone <filippo@carone.org>
8 * Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "libvlc_internal.h"
26 #include <vlc/libvlc.h>
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_e )
36 aout_VolumeMute( p_instance->p_libvlc_int, NULL );
39 vlc_bool_t libvlc_audio_get_mute( libvlc_instance_t *p_instance,
40 libvlc_exception_t *p_e )
43 * If the volume level is 0, then the channel is muted
45 audio_volume_t i_volume;
47 i_volume = libvlc_audio_get_volume(p_instance, p_e);
53 void libvlc_audio_set_mute( libvlc_instance_t *p_instance, vlc_bool_t mute,
54 libvlc_exception_t *p_e )
56 if ( mute ^ libvlc_audio_get_mute( p_instance, p_e ) )
58 aout_VolumeMute( p_instance->p_libvlc_int, NULL );
62 /*****************************************************************************
63 * libvlc_audio_get_volume : Get the current volume (range 0-200 %)
64 *****************************************************************************/
65 int libvlc_audio_get_volume( libvlc_instance_t *p_instance,
66 libvlc_exception_t *p_e )
68 audio_volume_t i_volume;
70 aout_VolumeGet( p_instance->p_libvlc_int, &i_volume );
72 return (i_volume*200+AOUT_VOLUME_MAX/2)/AOUT_VOLUME_MAX;
76 /*****************************************************************************
77 * libvlc_audio_set_volume : Set the current volume
78 *****************************************************************************/
79 void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume,
80 libvlc_exception_t *p_e )
82 if( i_volume >= 0 && i_volume <= 200 )
84 i_volume = (i_volume * AOUT_VOLUME_MAX + 100) / 200;
86 aout_VolumeSet( p_instance->p_libvlc_int, i_volume );
90 libvlc_exception_raise( p_e, "Volume out of range" );
94 /*****************************************************************************
95 * libvlc_audio_get_track : Get the current audio track
96 *****************************************************************************/
97 int libvlc_audio_get_track( libvlc_instance_t *p_instance,
98 libvlc_exception_t *p_e )
102 i_track = var_GetInteger( p_instance->p_libvlc_int, "audio-track" );
107 /*****************************************************************************
108 * libvlc_audio_set_track : Set the current audio track
109 *****************************************************************************/
110 void libvlc_audio_set_track( libvlc_instance_t *p_instance, int i_track,
111 libvlc_exception_t *p_e )
115 i_ret = var_SetInteger( p_instance->p_libvlc_int, "audio-track", i_track );
119 libvlc_exception_raise( p_e, "Setting audio track failed" );
123 /*****************************************************************************
124 * libvlc_audio_get_channel : Get the current audio channel
125 *****************************************************************************/
126 char *libvlc_audio_get_channel( libvlc_instance_t *p_instance,
127 libvlc_exception_t *p_e )
129 char *psz_channel = NULL;
132 i_channel = var_GetInteger( p_instance->p_libvlc_int, "audio-channel" );
135 case AOUT_VAR_CHAN_RSTEREO:
136 psz_channel = strdup("reverse");
138 case AOUT_VAR_CHAN_STEREO:
139 psz_channel = strdup("stereo");
141 case AOUT_VAR_CHAN_LEFT:
142 psz_channel = strdup("left");
144 case AOUT_VAR_CHAN_RIGHT:
145 psz_channel = strdup("right");
147 case AOUT_VAR_CHAN_DOLBYS:
148 psz_channel = strdup("dolby");
151 psz_channel = strdup("disabled");
157 /*****************************************************************************
158 * libvlc_audio_set_channel : Set the current audio channel
159 *****************************************************************************/
160 void libvlc_audio_set_channel( libvlc_instance_t *p_instance, char *psz_channel,
161 libvlc_exception_t *p_e )
168 libvlc_exception_raise( p_e, "Audio track out of range" );
172 if( strncmp( psz_channel, "reverse", 7 ) == 0 )
173 i_channel = AOUT_VAR_CHAN_RSTEREO;
174 else if( strncmp( psz_channel, "stereo", 6 ) == 0 )
175 i_channel = AOUT_VAR_CHAN_STEREO;
176 else if( strncmp( psz_channel, "left", 4 ) == 0 )
177 i_channel = AOUT_VAR_CHAN_LEFT;
178 else if( strncmp( psz_channel, "right", 5 ) == 0 )
179 i_channel = AOUT_VAR_CHAN_RIGHT;
180 else if( strncmp( psz_channel, "dolby", 5 ) == 0 )
181 i_channel = AOUT_VAR_CHAN_DOLBYS;
183 i_ret = var_SetInteger( p_instance->p_libvlc_int, "audio-channel", i_channel );
186 libvlc_exception_raise( p_e, "Audio track out of range" );