X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=lib%2Faudio.c;h=1b834d7b3e1850c11e2287dcab40b8ab49db81e4;hb=bf73ab036aee315f7b28f5e85f361407ae9fb0dc;hp=3183ad94329f22a8ea069bcf9bc8a655622cb159;hpb=7dba440e2ba695278337fe0a250264234043fb91;p=vlc diff --git a/lib/audio.c b/lib/audio.c index 3183ad9432..1b834d7b3e 100644 --- a/lib/audio.c +++ b/lib/audio.c @@ -35,7 +35,6 @@ #include #include -#include #include #include @@ -136,7 +135,7 @@ 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; @@ -218,33 +217,16 @@ void libvlc_audio_output_device_set( libvlc_media_player_t *mp, free( psz_config_name ); } -/***************************************************************************** - * libvlc_audio_output_get_device_type : Get the current audio device type - *****************************************************************************/ int libvlc_audio_output_get_device_type( libvlc_media_player_t *mp ) { - audio_output_t *p_aout = GetAOut( mp ); - if( p_aout ) - { - int i_device_type = var_GetInteger( p_aout, "audio-device" ); - vlc_object_release( p_aout ); - return i_device_type; - } + (void) mp; return libvlc_AudioOutputDevice_Error; } -/***************************************************************************** - * libvlc_audio_output_set_device_type : Set the audio device type - *****************************************************************************/ void libvlc_audio_output_set_device_type( libvlc_media_player_t *mp, int device_type ) { - audio_output_t *p_aout = GetAOut( mp ); - if( !p_aout ) - return; - if( var_SetInteger( p_aout, "audio-device", device_type ) < 0 ) - libvlc_printerr( "Error setting audio device" ); - vlc_object_release( p_aout ); + (void) mp; (void) device_type; } void libvlc_audio_toggle_mute( libvlc_media_player_t *mp ) @@ -256,18 +238,39 @@ void libvlc_audio_toggle_mute( libvlc_media_player_t *mp ) int libvlc_audio_get_mute( libvlc_media_player_t *mp ) { - return aout_MuteGet( mp ); + int mute = -1; + + audio_output_t *aout = GetAOut( mp ); + if( aout != NULL ) + { + mute = aout_MuteGet( aout ); + vlc_object_release( aout ); + } + return mute; } void libvlc_audio_set_mute( libvlc_media_player_t *mp, int mute ) { - aout_MuteSet( VLC_OBJECT(mp), mute != 0 ); + audio_output_t *aout = GetAOut( mp ); + if( aout != NULL ) + { + mute = aout_MuteSet( aout, mute ); + vlc_object_release( aout ); + } } int libvlc_audio_get_volume( libvlc_media_player_t *mp ) { - float vol = aout_VolumeGet( mp ); - return ( vol >= 0.f ) ? lroundf( vol * 100.f ) : -1; + int volume = -1; + + audio_output_t *aout = GetAOut( mp ); + if( aout != NULL ) + { + float vol = aout_VolumeGet( aout ); + vlc_object_release( aout ); + volume = lroundf( vol * 100.f ); + } + return volume; } int libvlc_audio_set_volume( libvlc_media_player_t *mp, int volume ) @@ -278,8 +281,15 @@ int libvlc_audio_set_volume( libvlc_media_player_t *mp, int volume ) libvlc_printerr( "Volume out of range" ); return -1; } - aout_VolumeSet (mp, vol); - return 0; + + int ret = -1; + audio_output_t *aout = GetAOut( mp ); + if( aout != NULL ) + { + ret = aout_VolumeSet( aout, vol ); + vlc_object_release( aout ); + } + return ret; } /***************************************************************************** @@ -314,33 +324,12 @@ libvlc_track_description_t * int libvlc_audio_get_track( libvlc_media_player_t *p_mi ) { input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi ); - vlc_value_t val_list; - vlc_value_t val; - int i_track = -1; - int i; - if( !p_input_thread ) return -1; - if( var_Get( p_input_thread, "audio-es", &val ) < 0 ) - { - vlc_object_release( p_input_thread ); - libvlc_printerr( "Audio track information not found" ); - return -1; - } - - var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL ); - for( i = 0; i < val_list.p_list->i_count; i++ ) - { - if( val_list.p_list->p_values[i].i_int == val.i_int ) - { - i_track = i; - break; - } - } - var_FreeList( &val_list, NULL ); + int id = var_GetInteger( p_input_thread, "audio-es" ); vlc_object_release( p_input_thread ); - return i_track; + return id; } /***************************************************************************** @@ -350,30 +339,23 @@ int libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track ) { input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi ); vlc_value_t val_list; - vlc_value_t newval; - int i_ret; + int i_ret = -1; if( !p_input_thread ) return -1; var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL ); - if( (i_track < 0) || (i_track > val_list.p_list->i_count) ) + for( int i = 0; i < val_list.p_list->i_count; i++ ) { - libvlc_printerr( "Audio track out of range" ); - i_ret = -1; - goto end; - } - - newval = val_list.p_list->p_values[i_track]; - i_ret = var_Set( p_input_thread, "audio-es", newval ); - if( i_ret < 0 ) - { - libvlc_printerr( "Audio track out of range" ); /* Race... */ - i_ret = -1; - goto end; + if( i_track == val_list.p_list->p_values[i].i_int ) + { + if( var_SetInteger( p_input_thread, "audio-es", i_track ) < 0 ) + break; + i_ret = 0; + goto end; + } } - i_ret = 0; - + libvlc_printerr( "Track identifier not found" ); end: var_FreeList( &val_list, NULL ); vlc_object_release( p_input_thread ); @@ -447,3 +429,138 @@ 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 ( f_preamp < -20.0f ) + f_preamp = -20.0f; + else if ( f_preamp > 20.0f ) + f_preamp = 20.0f; + + 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 ) + return -1; + + if ( f_amp < -20.0f ) + f_amp = -20.0f; + else if ( f_amp > 20.0f ) + f_amp = 20.0f; + + 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 0.f; + + return p_equalizer->f_amp[ u_band ]; +}