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
This commit is contained in:
gigaherz 2010-01-17 16:46:28 +00:00
parent ea254bac5e
commit c1cd29a534
2 changed files with 155 additions and 5 deletions

View File

@ -2170,6 +2170,38 @@
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath="..\..\include\pa_asio.h"
>
</File>
<File
RelativePath="..\..\include\pa_jack.h"
>
</File>
<File
RelativePath="..\..\include\pa_linux_alsa.h"
>
</File>
<File
RelativePath="..\..\include\pa_mac_core.h"
>
</File>
<File
RelativePath="..\..\include\pa_win_ds.h"
>
</File>
<File
RelativePath="..\..\include\pa_win_waveformat.h"
>
</File>
<File
RelativePath="..\..\include\pa_win_wmme.h"
>
</File>
<File
RelativePath="..\..\include\portaudio.h"
>
</File>
</Filter>
</Files>
<Globals>

View File

@ -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;i<Pa_GetDeviceCount();i++)
{
const PaDeviceInfo * info = Pa_GetDeviceInfo(i);
const PaHostApiInfo * apiinfo = Pa_GetHostApiInfo(info->hostApi);
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;i<Pa_GetHostApiCount();i++)
{
const PaHostApiInfo * apiinfo = Pa_GetHostApiInfo(i);
if(apiinfo->type == 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;