]> git.sesse.net Git - vlc/blobdiff - lib/audio.c
decoder: cosmetic changes
[vlc] / lib / audio.c
index 8efb7c4e11a8126394d37f56ddd33464c7dcc498..0165d16214de009e7fbc154ce7e2470203cb3553 100644 (file)
@@ -127,15 +127,62 @@ int libvlc_audio_output_set( libvlc_media_player_t *mp, const char *psz_name )
         return -1;
     var_SetString( mp, "aout", value );
     free( value );
+
+    /* Forget the existing audio output */
+    input_resource_ResetAout(mp->input.p_resource);
+
+    /* Create a new audio output */
+    audio_output_t *aout = input_resource_GetAout(mp->input.p_resource);
+    if( aout != NULL )
+        input_resource_PutAout(mp->input.p_resource, aout);
+
     return 0;
 }
 
+libvlc_audio_output_device_t *
+libvlc_audio_output_device_enum( libvlc_media_player_t *mp )
+{
+    audio_output_t *aout = GetAOut( mp );
+    if( aout == NULL )
+        return NULL;
+
+    libvlc_audio_output_device_t *list, **pp = &list;
+    char **values, **texts;
+
+    int n = aout_DevicesList( aout, &values, &texts );
+    vlc_object_release( aout );
+    if( n < 0 )
+        goto err;
+
+    for (int i = 0; i < n; i++)
+    {
+        libvlc_audio_output_device_t *item = malloc( sizeof(*item) );
+        if( unlikely(item == NULL) )
+        {
+            free( texts[i] );
+            free( values[i] );
+            continue;
+        }
+
+        *pp = item;
+        pp = &item->p_next;
+        item->psz_device = values[i];
+        item->psz_description = texts[i];
+    }
+
+    free( texts );
+    free( values );
+err:
+    *pp = NULL;
+    return list;
+}
+
 libvlc_audio_output_device_t *
 libvlc_audio_output_device_list_get( libvlc_instance_t *p_instance,
                                      const char *aout )
 {
     char varname[32];
-    if( (size_t)snprintf( varname, sizeof(varname), "%s-output-device", aout )
+    if( (size_t)snprintf( varname, sizeof(varname), "%s-audio-device", aout )
                                                            >= sizeof(varname) )
         return NULL;
 
@@ -202,19 +249,45 @@ char *libvlc_audio_output_device_id( libvlc_instance_t *p_instance,
  * Set device for using
  *****************************/
 void libvlc_audio_output_device_set( libvlc_media_player_t *mp,
-                                     const char *psz_audio_output,
-                                     const char *psz_device_id )
+                                     const char *module, const char *devid )
 {
-    char *psz_config_name;
-    if( !psz_audio_output || !psz_device_id )
+    if( devid == NULL )
         return;
-    if( asprintf( &psz_config_name, "%s-audio-device", psz_audio_output ) == -1 )
+
+    if( module != NULL )
+    {
+        char *cfg_name;
+
+        if( asprintf( &cfg_name, "%s-audio-device", module ) == -1 )
+            return;
+
+        if( !var_Type( mp, cfg_name ) )
+            /* Don't recreate the same variable over and over and over... */
+            var_Create( mp, cfg_name, VLC_VAR_STRING );
+        var_SetString( mp, cfg_name, devid );
+        free( cfg_name );
+        return;
+    }
+
+    audio_output_t *aout = GetAOut( mp );
+    if( aout == NULL )
         return;
-    if( !var_Type( mp, psz_config_name ) )
-        /* Don't recreate the same variable over and over and over... */
-        var_Create( mp, psz_config_name, VLC_VAR_STRING );
-    var_SetString( mp, psz_config_name, psz_device_id );
-    free( psz_config_name );
+
+    aout_DeviceSet( aout, devid );
+    vlc_object_release( aout );
+}
+
+char *libvlc_audio_output_device_get( libvlc_media_player_t *mp )
+{
+    audio_output_t *aout = GetAOut( mp );
+    if( aout == NULL )
+        return NULL;
+
+    char *devid = aout_DeviceGet( aout );
+
+    vlc_object_release( aout );
+
+    return devid;
 }
 
 int libvlc_audio_output_get_device_type( libvlc_media_player_t *mp )
@@ -276,7 +349,7 @@ int libvlc_audio_get_volume( libvlc_media_player_t *mp )
 int libvlc_audio_set_volume( libvlc_media_player_t *mp, int volume )
 {
     float vol = volume / 100.f;
-    if (vol < 0.f)
+    if (!isgreaterequal(vol, 0.f))
     {
         libvlc_printerr( "Volume out of range" );
         return -1;
@@ -429,3 +502,141 @@ int libvlc_audio_set_delay( libvlc_media_player_t *p_mi, int64_t i_delay )
     }
     return ret;
 }
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_get_preset_count : Get the number of equalizer presets
+ *****************************************************************************/
+unsigned libvlc_audio_equalizer_get_preset_count( void )
+{
+    return NB_PRESETS;
+}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_get_preset_name : Get the name for a preset
+ *****************************************************************************/
+const char *libvlc_audio_equalizer_get_preset_name( unsigned u_index )
+{
+    if ( u_index >= NB_PRESETS )
+        return NULL;
+
+    return preset_list_text[ u_index ];
+}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_get_band_count : Get the number of equalizer frequency bands
+ *****************************************************************************/
+unsigned libvlc_audio_equalizer_get_band_count( void )
+{
+    return EQZ_BANDS_MAX;
+}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_get_band_frequency : Get the frequency for a band
+ *****************************************************************************/
+float libvlc_audio_equalizer_get_band_frequency( unsigned u_index )
+{
+    if ( u_index >= EQZ_BANDS_MAX )
+        return -1.f;
+
+    return f_iso_frequency_table_10b[ u_index ];
+}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_new : Create a new audio equalizer with zeroed values
+ *****************************************************************************/
+libvlc_equalizer_t *libvlc_audio_equalizer_new( void )
+{
+    libvlc_equalizer_t *p_equalizer;
+    p_equalizer = malloc( sizeof( *p_equalizer ) );
+    if ( unlikely( p_equalizer == NULL ) )
+        return NULL;
+
+    p_equalizer->f_preamp = 0.f;
+    for ( unsigned i = 0; i < EQZ_BANDS_MAX; i++ )
+        p_equalizer->f_amp[ i ] = 0.f;
+
+    return p_equalizer;
+}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_new_from_preset : Create a new audio equalizer based on a preset
+ *****************************************************************************/
+libvlc_equalizer_t *libvlc_audio_equalizer_new_from_preset( unsigned u_index )
+{
+    libvlc_equalizer_t *p_equalizer;
+
+    if ( u_index >= NB_PRESETS )
+        return NULL;
+
+    p_equalizer = malloc( sizeof( *p_equalizer ) );
+    if ( unlikely( p_equalizer == NULL ) )
+        return NULL;
+
+    p_equalizer->f_preamp = eqz_preset_10b[ u_index ].f_preamp;
+
+    for ( unsigned i = 0; i < EQZ_BANDS_MAX; i++ )
+        p_equalizer->f_amp[ i ] = eqz_preset_10b[ u_index ].f_amp[ i ];
+
+    return p_equalizer;
+}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_release : Release a previously created equalizer
+ *****************************************************************************/
+void libvlc_audio_equalizer_release( libvlc_equalizer_t *p_equalizer )
+{
+    free( p_equalizer );
+}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_set_preamp : Set the preamp value for an equalizer
+ *****************************************************************************/
+int libvlc_audio_equalizer_set_preamp( libvlc_equalizer_t *p_equalizer, float f_preamp )
+{
+    if( isnan(f_preamp) )
+        return -1;
+    if( f_preamp < -20.f )
+        f_preamp = -20.f;
+    else if( f_preamp > 20.f )
+        f_preamp = 20.f;
+
+    p_equalizer->f_preamp = f_preamp;
+    return 0;
+}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_get_preamp : Get the preamp value for an equalizer
+ *****************************************************************************/
+float libvlc_audio_equalizer_get_preamp( libvlc_equalizer_t *p_equalizer )
+{
+    return p_equalizer->f_preamp;
+}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_set_amp_at_index : Set the amplification value for an equalizer band
+ *****************************************************************************/
+int libvlc_audio_equalizer_set_amp_at_index( libvlc_equalizer_t *p_equalizer, float f_amp, unsigned u_band )
+{
+    if( u_band >= EQZ_BANDS_MAX || isnan(f_amp) )
+        return -1;
+
+
+    if( f_amp < -20.f )
+        f_amp = -20.f;
+    else if( f_amp > 20.f )
+        f_amp = 20.f;
+
+    p_equalizer->f_amp[ u_band ] = f_amp;
+    return 0;
+}
+
+/*****************************************************************************
+ * libvlc_audio_equalizer_get_amp_at_index : Get the amplification value for an equalizer band
+ *****************************************************************************/
+float libvlc_audio_equalizer_get_amp_at_index( libvlc_equalizer_t *p_equalizer, unsigned u_band )
+{
+    if ( u_band >= EQZ_BANDS_MAX )
+        return nanf("");
+
+    return p_equalizer->f_amp[ u_band ];
+}