Skip to content

Commit

Permalink
lib: add libvlc_audio_set_mixmode
Browse files Browse the repository at this point in the history
  • Loading branch information
tguillem authored and jbkempf committed Dec 10, 2022
1 parent 42b645e commit fefe9b6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
46 changes: 46 additions & 0 deletions include/vlc/libvlc_media_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,17 @@ typedef enum libvlc_audio_output_stereomode_t {
libvlc_AudioStereoMode_Mono = 7,
} libvlc_audio_output_stereomode_t;

/**
* Audio mix modes
*/
typedef enum libvlc_audio_output_mixmode_t {
libvlc_AudioMixMode_Unset = 0,
libvlc_AudioMixMode_Stereo = 1,
libvlc_AudioMixMode_Binaural = 2,
libvlc_AudioMixMode_4_0 = 3,
libvlc_AudioMixMode_5_1 = 4,
libvlc_AudioMixMode_7_1 = 5,
} libvlc_audio_output_mixmode_t;

/**
* Gets the list of available audio output modules.
Expand Down Expand Up @@ -2429,6 +2440,41 @@ LIBVLC_API libvlc_audio_output_stereomode_t libvlc_audio_get_stereomode( libvlc_
LIBVLC_API int libvlc_audio_set_stereomode( libvlc_media_player_t *p_mi,
libvlc_audio_output_stereomode_t mode );

/**
* Get current audio mix-mode.
*
* \param p_mi media player
* \return the audio mix-mode, \see libvlc_audio_output_mixmode_t
* \version LibVLC 4.0.0 or later
*/
LIBVLC_API libvlc_audio_output_mixmode_t libvlc_audio_get_mixmode( libvlc_media_player_t *p_mi );

/**
* Set current audio mix-mode.
*
* By default (libvlc_AudioMixMode_Unset), the audio output will keep its
* original channel configuration (play stereo as stereo, or 5.1 as 5.1). Yet,
* the OS and Audio API might refuse a channel configuration and asks VLC to
* adapt (Stereo played as 5.1 or vice-versa).
*
* This function allows to force a channel configuration, it will only work if
* the OS and Audio API accept this configuration (otherwise, it won't have any
* effects). Here are some examples:
* - Play multi-channels (5.1, 7.1...) as stereo (libvlc_AudioMixMode_Stereo)
* - Play Stereo or 5.1 as 7.1 (libvlc_AudioMixMode_7_1)
* - Play multi-channels as stereo with a binaural effect
* (libvlc_AudioMixMode_Binaural). It might be selected automatically if the
* OS and Audio API can detect if a headphone is plugged.
*
* \param p_mi media player
* \param channel the audio mix-mode, \see libvlc_audio_output_mixmode_t
* \return 0 on success, -1 on error
* \version LibVLC 4.0.0 or later
*/
LIBVLC_API int libvlc_audio_set_mixmode( libvlc_media_player_t *p_mi,
libvlc_audio_output_mixmode_t mode );


/**
* Get current audio delay.
*
Expand Down
42 changes: 42 additions & 0 deletions lib/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,48 @@ int libvlc_audio_set_stereomode( libvlc_media_player_t *mp, libvlc_audio_output_
return ret;
}

/*****************************************************************************
* libvlc_audio_get_mixmode : Get the current audio mix-mode
*****************************************************************************/
libvlc_audio_output_mixmode_t libvlc_audio_get_mixmode( libvlc_media_player_t *mp )
{
audio_output_t *p_aout = GetAOut( mp );
if( !p_aout )
return libvlc_AudioMixMode_Unset;

int val = var_GetInteger( p_aout, "mix-mode" );
aout_Release(p_aout);
return val;
}

/*****************************************************************************
* libvlc_audio_set_mixmode : Set the current audio mix-mode
*****************************************************************************/
int libvlc_audio_set_mixmode( libvlc_media_player_t *mp, libvlc_audio_output_mixmode_t mode )
{
static_assert(libvlc_AudioMixMode_Unset == AOUT_VAR_CHAN_UNSET &&
libvlc_AudioMixMode_Stereo == AOUT_MIX_MODE_STEREO &&
libvlc_AudioMixMode_Binaural == AOUT_MIX_MODE_BINAURAL &&
libvlc_AudioMixMode_4_0 == AOUT_MIX_MODE_4_0 &&
libvlc_AudioMixMode_5_1 == AOUT_MIX_MODE_5_1 &&
libvlc_AudioMixMode_7_1 == AOUT_MIX_MODE_7_1,
"Mismatch with mix-mode LibVLC/VLC enums");

audio_output_t *p_aout = GetAOut( mp );
int ret = 0;

if( !p_aout )
return -1;

if( var_SetInteger( p_aout, "mix-mode", mode ) < 0 )
{
libvlc_printerr( "Audio mix-mode out of range" );
ret = -1;
}
aout_Release(p_aout);
return ret;
}

/*****************************************************************************
* libvlc_audio_get_delay : Get the current audio delay
*****************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions lib/libvlc.sym
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ libvlc_audio_output_device_set
libvlc_audio_output_list_get
libvlc_audio_output_list_release
libvlc_audio_output_set
libvlc_audio_get_mixmode
libvlc_audio_get_stereomode
libvlc_audio_get_delay
libvlc_audio_get_mute
libvlc_audio_get_track
libvlc_audio_get_track_count
libvlc_audio_get_track_description
libvlc_audio_get_volume
libvlc_audio_set_mixmode
libvlc_audio_set_stereomode
libvlc_audio_set_delay
libvlc_audio_set_mute
Expand Down

0 comments on commit fefe9b6

Please sign in to comment.