Commit 797746e9 authored by Gildas Bazin's avatar Gildas Bazin

* modules/audio_output/directx.c: audio device selection based on a patch from...

* modules/audio_output/directx.c: audio device selection based on a patch from Matthew Armsby (uberground at gmail dot com) + config option to disable float32 output.
parent ec19e63d
......@@ -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,8 +658,8 @@ static int InitDirectSound( aout_instance_t *p_aout )
goto error;
}
OurDirectSoundCreate = (void *)GetProcAddress(
p_aout->output.p_sys->hdsound_dll,
OurDirectSoundCreate = (void *)
GetProcAddress( p_aout->output.p_sys->hdsound_dll,
"DirectSoundCreate" );
if( OurDirectSoundCreate == NULL )
{
......@@ -616,8 +667,23 @@ static int InitDirectSound( aout_instance_t *p_aout )
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 )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment