?? pa_win_ds.c
字號:
deviceInfo->defaultLowInputLatency = 0.; /** @todo IMPLEMENT ME */ deviceInfo->defaultLowOutputLatency = 0.; /** @todo IMPLEMENT ME */ deviceInfo->defaultHighInputLatency = 0.; /** @todo IMPLEMENT ME */ deviceInfo->defaultHighOutputLatency = 0.; /** @todo IMPLEMENT ME *//* constants from a WINE patch by Francois Gouget, see: http://www.winehq.com/hypermail/wine-patches/2003/01/0290.html --- Date: Fri, 14 May 2004 10:38:12 +0200 (CEST) From: Francois Gouget <fgouget@ ... .fr> To: Ross Bencina <rbencina@ ... .au> Subject: Re: Permission to use wine 48/96 wave patch in BSD licensed library [snip] I give you permission to use the patch below under the BSD license. http://www.winehq.com/hypermail/wine-patches/2003/01/0290.html [snip]*/#ifndef WAVE_FORMAT_48M08#define WAVE_FORMAT_48M08 0x00001000 /* 48 kHz, Mono, 8-bit */#define WAVE_FORMAT_48S08 0x00002000 /* 48 kHz, Stereo, 8-bit */#define WAVE_FORMAT_48M16 0x00004000 /* 48 kHz, Mono, 16-bit */#define WAVE_FORMAT_48S16 0x00008000 /* 48 kHz, Stereo, 16-bit */#define WAVE_FORMAT_96M08 0x00010000 /* 96 kHz, Mono, 8-bit */#define WAVE_FORMAT_96S08 0x00020000 /* 96 kHz, Stereo, 8-bit */#define WAVE_FORMAT_96M16 0x00040000 /* 96 kHz, Mono, 16-bit */#define WAVE_FORMAT_96S16 0x00080000 /* 96 kHz, Stereo, 16-bit */#endif /* defaultSampleRate */ if( caps.dwChannels == 2 ) { if( caps.dwFormats & WAVE_FORMAT_4S16 ) deviceInfo->defaultSampleRate = 44100.0; else if( caps.dwFormats & WAVE_FORMAT_48S16 ) deviceInfo->defaultSampleRate = 48000.0; else if( caps.dwFormats & WAVE_FORMAT_2S16 ) deviceInfo->defaultSampleRate = 22050.0; else if( caps.dwFormats & WAVE_FORMAT_1S16 ) deviceInfo->defaultSampleRate = 11025.0; else if( caps.dwFormats & WAVE_FORMAT_96S16 ) deviceInfo->defaultSampleRate = 96000.0; else deviceInfo->defaultSampleRate = 0.; } else if( caps.dwChannels == 1 ) { if( caps.dwFormats & WAVE_FORMAT_4M16 ) deviceInfo->defaultSampleRate = 44100.0; else if( caps.dwFormats & WAVE_FORMAT_48M16 ) deviceInfo->defaultSampleRate = 48000.0; else if( caps.dwFormats & WAVE_FORMAT_2M16 ) deviceInfo->defaultSampleRate = 22050.0; else if( caps.dwFormats & WAVE_FORMAT_1M16 ) deviceInfo->defaultSampleRate = 11025.0; else if( caps.dwFormats & WAVE_FORMAT_96M16 ) deviceInfo->defaultSampleRate = 96000.0; else deviceInfo->defaultSampleRate = 0.; } else deviceInfo->defaultSampleRate = 0.; } } IDirectSoundCapture_Release( lpDirectSoundCapture ); } if( deviceOK ) { deviceInfo->name = name; if( lpGUID == NULL ) hostApi->info.defaultInputDevice = hostApi->info.deviceCount; hostApi->info.deviceCount++; } return result;}/***********************************************************************************/PaError PaWinDs_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex ){ PaError result = paNoError; int i, deviceCount; PaWinDsHostApiRepresentation *winDsHostApi; DSDeviceNameAndGUIDVector inputNamesAndGUIDs, outputNamesAndGUIDs; PaDeviceInfo *deviceInfoArray; HRESULT hr = CoInitialize(NULL); /** @todo: should uninitialize too */ if( FAILED(hr) ){ return paUnanticipatedHostError; } /* initialise guid vectors so they can be safely deleted on error */ inputNamesAndGUIDs.items = NULL; outputNamesAndGUIDs.items = NULL; PaWinDs_InitializeDSoundEntryPoints(); winDsHostApi = (PaWinDsHostApiRepresentation*)PaUtil_AllocateMemory( sizeof(PaWinDsHostApiRepresentation) ); if( !winDsHostApi ) { result = paInsufficientMemory; goto error; } winDsHostApi->allocations = PaUtil_CreateAllocationGroup(); if( !winDsHostApi->allocations ) { result = paInsufficientMemory; goto error; } *hostApi = &winDsHostApi->inheritedHostApiRep; (*hostApi)->info.structVersion = 1; (*hostApi)->info.type = paDirectSound; (*hostApi)->info.name = "Windows DirectSound"; (*hostApi)->info.deviceCount = 0; (*hostApi)->info.defaultInputDevice = paNoDevice; (*hostApi)->info.defaultOutputDevice = paNoDevice; /* DSound - enumerate devices to count them and to gather their GUIDs */ result = InitializeDSDeviceNameAndGUIDVector( &inputNamesAndGUIDs, winDsHostApi->allocations ); if( result != paNoError ) goto error; result = InitializeDSDeviceNameAndGUIDVector( &outputNamesAndGUIDs, winDsHostApi->allocations ); if( result != paNoError ) goto error; paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerate( (LPDSENUMCALLBACK)CollectGUIDsProc, (void *)&inputNamesAndGUIDs ); paWinDsDSoundEntryPoints.DirectSoundEnumerate( (LPDSENUMCALLBACK)CollectGUIDsProc, (void *)&outputNamesAndGUIDs ); if( inputNamesAndGUIDs.enumerationError != paNoError ) { result = inputNamesAndGUIDs.enumerationError; goto error; } if( outputNamesAndGUIDs.enumerationError != paNoError ) { result = outputNamesAndGUIDs.enumerationError; goto error; } deviceCount = inputNamesAndGUIDs.count + outputNamesAndGUIDs.count; if( deviceCount > 0 ) { /* allocate array for pointers to PaDeviceInfo structs */ (*hostApi)->deviceInfos = (PaDeviceInfo**)PaUtil_GroupAllocateMemory( winDsHostApi->allocations, sizeof(PaDeviceInfo*) * deviceCount ); if( !(*hostApi)->deviceInfos ) { result = paInsufficientMemory; goto error; } /* allocate all PaDeviceInfo structs in a contiguous block */ deviceInfoArray = (PaDeviceInfo*)PaUtil_GroupAllocateMemory( winDsHostApi->allocations, sizeof(PaDeviceInfo) * deviceCount ); if( !deviceInfoArray ) { result = paInsufficientMemory; goto error; } /* allocate all DSound specific info structs in a contiguous block */ winDsHostApi->winDsDeviceInfos = (PaWinDsDeviceInfo*)PaUtil_GroupAllocateMemory( winDsHostApi->allocations, sizeof(PaWinDsDeviceInfo) * deviceCount ); if( !winDsHostApi->winDsDeviceInfos ) { result = paInsufficientMemory; goto error; } for( i=0; i < deviceCount; ++i ) { PaDeviceInfo *deviceInfo = &deviceInfoArray[i]; deviceInfo->structVersion = 2; deviceInfo->hostApi = hostApiIndex; deviceInfo->name = 0; (*hostApi)->deviceInfos[i] = deviceInfo; } for( i=0; i< inputNamesAndGUIDs.count; ++i ) { result = AddInputDeviceInfoFromDirectSoundCapture( winDsHostApi, inputNamesAndGUIDs.items[i].name, inputNamesAndGUIDs.items[i].lpGUID ); if( result != paNoError ) goto error; } for( i=0; i< outputNamesAndGUIDs.count; ++i ) { result = AddOutputDeviceInfoFromDirectSound( winDsHostApi, outputNamesAndGUIDs.items[i].name, outputNamesAndGUIDs.items[i].lpGUID ); if( result != paNoError ) goto error; } } result = TerminateDSDeviceNameAndGUIDVector( &inputNamesAndGUIDs ); if( result != paNoError ) goto error; result = TerminateDSDeviceNameAndGUIDVector( &outputNamesAndGUIDs ); if( result != paNoError ) goto error; (*hostApi)->Terminate = Terminate; (*hostApi)->OpenStream = OpenStream; (*hostApi)->IsFormatSupported = IsFormatSupported; PaUtil_InitializeStreamInterface( &winDsHostApi->callbackStreamInterface, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, GetStreamCpuLoad, PaUtil_DummyRead, PaUtil_DummyWrite, PaUtil_DummyGetReadAvailable, PaUtil_DummyGetWriteAvailable ); PaUtil_InitializeStreamInterface( &winDsHostApi->blockingStreamInterface, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, PaUtil_DummyGetCpuLoad, ReadStream, WriteStream, GetStreamReadAvailable, GetStreamWriteAvailable ); return result;error: if( winDsHostApi ) { if( winDsHostApi->allocations ) { PaUtil_FreeAllAllocations( winDsHostApi->allocations ); PaUtil_DestroyAllocationGroup( winDsHostApi->allocations ); } PaUtil_FreeMemory( winDsHostApi ); } TerminateDSDeviceNameAndGUIDVector( &inputNamesAndGUIDs ); TerminateDSDeviceNameAndGUIDVector( &outputNamesAndGUIDs ); return result;}/***********************************************************************************/static void Terminate( struct PaUtilHostApiRepresentation *hostApi ){ PaWinDsHostApiRepresentation *winDsHostApi = (PaWinDsHostApiRepresentation*)hostApi; /* IMPLEMENT ME: - clean up any resources not handled by the allocation group */ if( winDsHostApi->allocations ) { PaUtil_FreeAllAllocations( winDsHostApi->allocations ); PaUtil_DestroyAllocationGroup( winDsHostApi->allocations ); } PaUtil_FreeMemory( winDsHostApi ); PaWinDs_TerminateDSoundEntryPoints(); CoUninitialize();}/* Set minimal latency based on whether NT or Win95. * NT has higher latency. */static int PaWinDS_GetMinSystemLatency( void ){ int minLatencyMsec; /* Set minimal latency based on whether NT or other OS. * NT has higher latency. */ OSVERSIONINFO osvi; osvi.dwOSVersionInfoSize = sizeof( osvi ); GetVersionEx( &osvi ); DBUG(("PA - PlatformId = 0x%x\n", osvi.dwPlatformId )); DBUG(("PA - MajorVersion = 0x%x\n", osvi.dwMajorVersion )); DBUG(("PA - MinorVersion = 0x%x\n", osvi.dwMinorVersion )); /* Check for NT */ if( (osvi.dwMajorVersion == 4) && (osvi.dwPlatformId == 2) ) { minLatencyMsec = PA_WIN_NT_LATENCY; } else if(osvi.dwMajorVersion >= 5) { minLatencyMsec = PA_WIN_WDM_LATENCY; } else { minLatencyMsec = PA_WIN_9X_LATENCY; } return minLatencyMsec;}/***********************************************************************************/static PaError IsFormatSupported( struct PaUtilHostApiRepresentation *hostApi, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate ){ int inputChannelCount, outputChannelCount; PaSampleFormat inputSampleFormat, outputSampleFormat; if( inputParameters ) { inputChannelCount = inputParameters->channelCount; inputSampleFormat = inputParameters->sampleFormat; /* unless alternate device specification is supported, reject the use of paUseHostApiSpecificDeviceSpecification */ if( inputParameters->device == paUseHostApiSpecificDeviceSpecification ) return paInvalidDevice; /* check that input device can support inputChannelCount */ if( inputChannelCount > hostApi->deviceInfos[ inputParameters->device ]->maxInputChannels ) return paInvalidChannelCount; /* validate inputStreamInfo */ if( inputParameters->hostApiSpecificStreamInfo ) return paIncompatibleHostApiSpecificStreamInfo; /* this implementation doesn't use custom stream info */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -