From: Gildas Bazin Date: Tue, 7 Jun 2005 15:02:55 +0000 (+0000) Subject: * modules/audio_output/directx.c: backport of 11335. X-Git-Tag: 0.8.2~81 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=4c04bf3eafc35456093119f9f95e9f0c8df5103d;p=vlc * modules/audio_output/directx.c: backport of 11335. --- diff --git a/modules/audio_output/directx.c b/modules/audio_output/directx.c index 17913d23f5..1097decfce 100644 --- a/modules/audio_output/directx.c +++ b/modules/audio_output/directx.c @@ -152,6 +152,10 @@ typedef struct notification_thread_t struct aout_sys_t { HINSTANCE hdsound_dll; /* handle of the opened dsound dll */ + + int i_device_id; /* user defined device */ + LPGUID p_device_guid; + LPDIRECTSOUND p_dsobject; /* main Direct Sound object */ LPDIRECTSOUNDBUFFER p_dsbuffer; /* the sound buffer we use (direct sound * takes care of mixing all the @@ -206,6 +210,15 @@ static int FillBuffer ( aout_instance_t *, int, aout_buffer_t * ); /***************************************************************************** * Module descriptor *****************************************************************************/ +#define DEVICE_TEXT N_("Output device") +#define DEVICE_LONGTEXT N_( \ + "DirectX device number: 0 default device, 1..N device by number" \ + "(Note that the default device appears as 0 AND another number)." ) +#define FLOAT_TEXT N_("Use float32 output") +#define FLOAT_LONGTEXT N_( \ + "The option allows you to enable or disable the high-quality float32 " \ + "audio output mode (which is not well supported by some soundcards)." ) + vlc_module_begin(); set_description( _("DirectX audio output") ); set_shortname( "DirectX" ); @@ -213,6 +226,10 @@ vlc_module_begin(); set_category( CAT_AUDIO ); set_subcategory( SUBCAT_AUDIO_AOUT ); add_shortcut( "directx" ); + add_integer( "directx-audio-device", 0, NULL, DEVICE_TEXT, + DEVICE_LONGTEXT, VLC_TRUE ); + add_bool( "directx-audio-float32", 1, 0, FLOAT_TEXT, + FLOAT_LONGTEXT, VLC_TRUE ); set_callbacks( OpenAudio, CloseAudio ); vlc_module_end(); @@ -247,6 +264,15 @@ static int OpenAudio( vlc_object_t *p_this ) p_aout->output.pf_play = Play; aout_VolumeSoftInit( p_aout ); + /* Retrieve config values */ + var_Create( p_aout, "directx-audio-float32", + VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); + var_Create( p_aout, "directx-audio-device", + VLC_VAR_INTEGER|VLC_VAR_DOINHERIT ); + var_Get( p_aout, "directx-audio-device", &val ); + p_aout->output.p_sys->i_device_id = val.i_int; + p_aout->output.p_sys->p_device_guid = 0; + /* Initialise DirectSound */ if( InitDirectSound( p_aout ) ) { @@ -590,15 +616,40 @@ static void CloseAudio( vlc_object_t *p_this ) /* free DSOUND.DLL */ if( p_sys->hdsound_dll ) FreeLibrary( p_sys->hdsound_dll ); + if( p_aout->output.p_sys->p_device_guid ) + free( p_aout->output.p_sys->p_device_guid ); + free( p_sys ); } +/***************************************************************************** + * CallBackDirectSoundEnum: callback to enumerate available devices + *****************************************************************************/ +static int CALLBACK CallBackDirectSoundEnum( LPGUID p_guid, LPCSTR psz_desc, + LPCSTR psz_mod, LPVOID _p_aout ) +{ + aout_instance_t *p_aout = (aout_instance_t *)_p_aout; + + msg_Dbg( p_aout, "found device: %s", psz_desc ); + + if( p_aout->output.p_sys->i_device_id == 0 && p_guid ) + { + p_aout->output.p_sys->p_device_guid = malloc( sizeof( GUID ) ); + *p_aout->output.p_sys->p_device_guid = *p_guid; + msg_Dbg( p_aout, "using device: %s", psz_desc ); + } + + p_aout->output.p_sys->i_device_id--; + return 1; +} + /***************************************************************************** * InitDirectSound: handle all the gory details of DirectSound initialisation *****************************************************************************/ static int InitDirectSound( aout_instance_t *p_aout ) { HRESULT (WINAPI *OurDirectSoundCreate)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN); + HRESULT (WINAPI *OurDirectSoundEnumerate)(LPDSENUMCALLBACK, LPVOID); p_aout->output.p_sys->hdsound_dll = LoadLibrary("DSOUND.DLL"); if( p_aout->output.p_sys->hdsound_dll == NULL ) @@ -607,17 +658,32 @@ static int InitDirectSound( aout_instance_t *p_aout ) goto error; } - OurDirectSoundCreate = (void *)GetProcAddress( - p_aout->output.p_sys->hdsound_dll, - "DirectSoundCreate" ); + OurDirectSoundCreate = (void *) + GetProcAddress( p_aout->output.p_sys->hdsound_dll, + "DirectSoundCreate" ); if( OurDirectSoundCreate == NULL ) { msg_Warn( p_aout, "GetProcAddress FAILED" ); goto error; } + /* Get DirectSoundEnumerate */ + OurDirectSoundEnumerate = (void *) + GetProcAddress( p_aout->output.p_sys->hdsound_dll, + "DirectSoundEnumerateA" ); + if( OurDirectSoundEnumerate ) + { + /* Attempt enumeration */ + if( FAILED( OurDirectSoundEnumerate( CallBackDirectSoundEnum, + p_aout ) ) ) + { + msg_Dbg( p_aout, "enumeration of DirectSound devices failed" ); + } + } + /* Create the direct sound object */ - if FAILED( OurDirectSoundCreate( NULL, &p_aout->output.p_sys->p_dsobject, + if FAILED( OurDirectSoundCreate( p_aout->output.p_sys->p_device_guid, + &p_aout->output.p_sys->p_dsobject, NULL ) ) { msg_Warn( p_aout, "cannot create a direct sound device" ); @@ -839,9 +905,13 @@ static int CreateDSBufferPCM( aout_instance_t *p_aout, int *i_format, int i_channels, int i_nb_channels, int i_rate, vlc_bool_t b_probe ) { + vlc_value_t val; + + var_Get( p_aout, "directx-audio-float32", &val ); + /* Float32 audio samples are not supported for 5.1 output on the emu101k */ - if( i_nb_channels > 2 || + if( !val.b_bool || i_nb_channels > 2 || CreateDSBuffer( p_aout, VLC_FOURCC('f','l','3','2'), i_channels, i_nb_channels, i_rate, FRAME_SIZE * 4 * i_nb_channels, b_probe )