From c1cd29a534efef06208c40a3202b0165f028d766 Mon Sep 17 00:00:00 2001 From: gigaherz Date: Sun, 17 Jan 2010 16:46:28 +0000 Subject: [PATCH] Started implementing configuration support for PortAudio. Since PortAudio doesn't have any kind of "Unique ID" for the listed devices, I have to rely on the "host api" name and the descriptive name of the device, but it doesn't seem to be 100% reliable. In case the device name can't be found, it will try to use the default device for the specified API. If no api is specified, then it will fall back to using whatever default device PortAudio provides. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2445 96395faa-99c1-11dd-bbfe-3dabce05a288 --- .../portaudio/build/msvc/portaudio.vcproj | 32 +++++ plugins/spu2-x/src/SndOut_Portaudio.cpp | 128 +++++++++++++++++- 2 files changed, 155 insertions(+), 5 deletions(-) diff --git a/3rdparty/portaudio/build/msvc/portaudio.vcproj b/3rdparty/portaudio/build/msvc/portaudio.vcproj index 0922f51743..14bfa98153 100644 --- a/3rdparty/portaudio/build/msvc/portaudio.vcproj +++ b/3rdparty/portaudio/build/msvc/portaudio.vcproj @@ -2170,6 +2170,38 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl" > + + + + + + + + + + + + + + + + diff --git a/plugins/spu2-x/src/SndOut_Portaudio.cpp b/plugins/spu2-x/src/SndOut_Portaudio.cpp index 43c7fd4b14..1768a79d38 100644 --- a/plugins/spu2-x/src/SndOut_Portaudio.cpp +++ b/plugins/spu2-x/src/SndOut_Portaudio.cpp @@ -32,7 +32,7 @@ private: ////////////////////////////////////////////////////////////////////////////////////////// // Configuration Vars (unused still) - wstring m_Api; + int m_ApiId; wstring m_Device; bool m_UseHardware; @@ -76,11 +76,18 @@ private: } public: + Portaudio() + { + m_ApiId=-1; + } + s32 Init() { started=false; stream=NULL; + ReadSettings(); + PaError err = Pa_Initialize(); if( err != paNoError ) { @@ -89,10 +96,78 @@ public: } started=true; - err = Pa_OpenDefaultStream( &stream, - 0, 2, paInt32, 48000, - SndOutPacketSize, - PaCallback, NULL ); + int deviceIndex = -1; + + fprintf(stderr," * SPU2: Enumerating PortAudio devices:"); + for(int i=0;ihostApi); + + fprintf(stderr," *** Device %d: '%s' (%s)", i, info->name, apiinfo->name); + + if(apiinfo->type == m_ApiId) + { +#ifdef __WIN32__ + static wchar_t buffer [1000]; + MultiByteToWideChar(CP_UTF8,0,info->name,strlen(info->name),buffer,999); + buffer[999]=0; +#else +# error TODO +#endif + + if(m_Device == buffer) + { + deviceIndex = i; + fprintf(stderr," (selected)"); + } + + } + fprintf(stderr,"\n"); + } + + if(deviceIndex<0 && m_ApiId>=0) + { + for(int i=0;itype == m_ApiId) + { + deviceIndex = apiinfo->defaultOutputDevice; + } + } + } + + if(deviceIndex>=0) + { + PaStreamParameters outParams = { + + // PaDeviceIndex device; + // int channelCount; + // PaSampleFormat sampleFormat; + // PaTime suggestedLatency; + // void *hostApiSpecificStreamInfo; + deviceIndex, + 2, + paInt32, + 0, //? + NULL + + }; + + err = Pa_OpenStream(&stream, + NULL, &outParams, SampleRate, + SndOutPacketSize, + paNoFlag, PaCallback, NULL); + } + else + { + err = Pa_OpenDefaultStream( &stream, + 0, 2, paInt32, 48000, + SndOutPacketSize, + PaCallback, NULL ); + } if( err != paNoError ) { fprintf(stderr," * SPU2: PortAudio error: %s\n", Pa_GetErrorText( err ) ); @@ -176,10 +251,53 @@ public: void ReadSettings() { + wstring api=L"EMPTYEMPTYEMPTY"; + m_Device = L"EMPTYEMPTYEMPTY"; + CfgReadStr( L"PORTAUDIO", L"HostApi", api, 254, L"Unknown" ); + CfgReadStr( L"PORTAUDIO", L"Device", m_Device, 254, L"default" ); + + m_ApiId = -1; + if(api == L"InDevelopment") m_ApiId = paInDevelopment; /* use while developing support for a new host API */ + if(api == L"DirectSound") m_ApiId = paDirectSound; + if(api == L"MME") m_ApiId = paMME; + if(api == L"ASIO") m_ApiId = paASIO; + if(api == L"SoundManager") m_ApiId = paSoundManager; + if(api == L"CoreAudio") m_ApiId = paCoreAudio; + if(api == L"OSS") m_ApiId = paOSS; + if(api == L"ALSA") m_ApiId = paALSA; + if(api == L"AL") m_ApiId = paAL; + if(api == L"BeOS") m_ApiId = paBeOS; + if(api == L"WDMKS") m_ApiId = paWDMKS; + if(api == L"JACK") m_ApiId = paJACK; + if(api == L"WASAPI") m_ApiId = paWASAPI; + if(api == L"AudioScienceHPI") m_ApiId = paAudioScienceHPI; + } void WriteSettings() const { + wstring api; + switch(m_ApiId) + { + case paInDevelopment: api = L"InDevelopment"; break; /* use while developing support for a new host API */ + case paDirectSound: api = L"DirectSound"; break; + case paMME: api = L"MME"; break; + case paASIO: api = L"ASIO"; break; + case paSoundManager: api = L"SoundManager"; break; + case paCoreAudio: api = L"CoreAudio"; break; + case paOSS: api = L"OSS"; break; + case paALSA: api = L"ALSA"; break; + case paAL: api = L"AL"; break; + case paBeOS: api = L"BeOS"; break; + case paWDMKS: api = L"WDMKS"; break; + case paJACK: api = L"JACK"; break; + case paWASAPI: api = L"WASAPI"; break; + case paAudioScienceHPI: api = L"AudioScienceHPI"; break; + default: api = L"Unknown"; + } + + CfgWriteStr( L"PORTAUDIO", L"HostApi", api); + CfgWriteStr( L"PORTAUDIO", L"Device", m_Device); } } static PA;