Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
7.2 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dvengine.cpp
  6. * Content: Implementation of CDirectVoiceEngine's static functions
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 07/19/99 rodtoll Created
  12. * 07/29/99 rodtoll Added static members to load default settings
  13. * 08/10/99 rodtoll Removed the TODOs
  14. * 08/25/99 rodtoll General Cleanup/Modifications to support new
  15. * compression sub-system.
  16. * Added default parameter reads from the registry
  17. * 08/30/99 rodtoll Distinguish between primary buffer format and
  18. * playback format.
  19. * Changed playback format to be 8Khz, 16Bit mono
  20. * 10/05/99 rodtoll Additional comments/DPFs
  21. * 10/07/99 rodtoll Updated to work in Unicode
  22. * 02/08/2000 rodtoll Bug #131496 - Selecting DVTHRESHOLD_DEFAULT results in voice
  23. * never being detected
  24. * 03/03/2000 rodtoll Updated to handle alternative gamevoice build.
  25. * 04/21/2000 rodtoll Bug #32889 - Does not run on Win2k on non-admin account
  26. * 04/24/2000 rodtoll Bug #33203 - Aureal Vortex plays back at the wrong rate
  27. * 07/12/2000 rodtoll Bug #31468 - Add diagnostic spew to logfile to show what is failing the HW Wizard
  28. * 08/31/2000 rodtoll Bug #43804 - DVOICE: dwSensitivity structure member is confusing - should be dwThreshold
  29. * 10/10/2000 rodtoll Bug #46907 - 3D Sound position not working correctly with Win9X & VxD
  30. * 04/06/2001 kareemc Added Voice Defense
  31. *
  32. ***************************************************************************/
  33. #include "dxvoicepch.h"
  34. #undef DPF_SUBCOMP
  35. #define DPF_SUBCOMP DN_SUBCOMP_VOICE
  36. // Registry settings and their defaults
  37. #define DPVOICE_REGISTRY_DEFAULTAGGRESSIVENESS L"DefaultAggressiveness"
  38. #define DPVOICE_DEFAULT_DEFAULTAGGRESSIVENESS 15
  39. #define DPVOICE_REGISTRY_DEFAULTQUALITY L"DefaultQuality"
  40. #define DPVOICE_DEFAULT_DEFAULTQUALITY 15
  41. #define DPVOICE_REGISTRY_DEFAULTSENSITIVITY L"DefaultSensitivity"
  42. #define DPVOICE_DEFAULT_DEFAULTSENSITIVITY 20
  43. #define DPVOICE_REGISTRY_ASO L"AltStart"
  44. #define DPVOICE_DEFAULT_ASO FALSE
  45. #define DPVOICE_REGISTRY_DUMPDIAGNOSTICS L"InitDiagnostics"
  46. #define DPVOICE_DEFAULT_DUMPDIAGNOSTICS FALSE
  47. // Fix for bug #33203 -- Some cards having trouble with playback at 8Khz.
  48. #define DPVOICE_REGISTRY_PLAYBACKFORMAT L"PlaybackFormat"
  49. #define DPVOICE_DEFAULT_PLAYBACKFORMAT CreateWaveFormat( WAVE_FORMAT_PCM, FALSE, 22050, 16 )
  50. #define DPVOICE_REGISTRY_PRIMARYFORMAT L"PrimaryFormat"
  51. #define DPVOICE_DEFAULT_PRIMARYFORMAT CreateWaveFormat( WAVE_FORMAT_PCM, TRUE, 22050, 16 )
  52. #define DPVOICE_REGISTRY_MIXERFORMAT L"MixerFormat"
  53. #define DPVOICE_DEFAULT_MIXERFORMAT CreateWaveFormat( WAVE_FORMAT_PCM, FALSE, 8000, 16 );
  54. // Initialize static member variables
  55. DWORD CDirectVoiceEngine::s_dwDefaultBufferAggressiveness = DPVOICE_DEFAULT_DEFAULTAGGRESSIVENESS;
  56. DWORD CDirectVoiceEngine::s_dwDefaultBufferQuality = DPVOICE_DEFAULT_DEFAULTQUALITY;
  57. DWORD CDirectVoiceEngine::s_dwDefaultSensitivity = DPVOICE_DEFAULT_DEFAULTSENSITIVITY;
  58. LPWAVEFORMATEX CDirectVoiceEngine::s_lpwfxPrimaryFormat = NULL;
  59. LPWAVEFORMATEX CDirectVoiceEngine::s_lpwfxPlaybackFormat = NULL;
  60. LPWAVEFORMATEX CDirectVoiceEngine::s_lpwfxMixerFormat = NULL;
  61. BOOL CDirectVoiceEngine::s_fASO = DPVOICE_DEFAULT_ASO;
  62. WCHAR CDirectVoiceEngine::s_szRegistryPath[_MAX_PATH];
  63. BOOL CDirectVoiceEngine::s_fDumpDiagnostics = DPVOICE_DEFAULT_DUMPDIAGNOSTICS;
  64. DNCRITICAL_SECTION CDirectVoiceEngine::s_csSTLLock;
  65. #undef DPF_MODNAME
  66. #define DPF_MODNAME "CDirectVoiceEngine::Startup"
  67. //
  68. // Startup
  69. //
  70. // Called to load global settings and compression info from the registry.
  71. //
  72. HRESULT CDirectVoiceEngine::Startup(const WCHAR *szPath)
  73. {
  74. HRESULT hr;
  75. DPFX(DPFPREP, DVF_WARNINGLEVEL, "Starting up global DLL state" );
  76. wcscpy( s_szRegistryPath, szPath );
  77. if (!DNInitializeCriticalSection( &s_csSTLLock ) )
  78. {
  79. return DVERR_OUTOFMEMORY;
  80. }
  81. hr = DVCDB_LoadCompressionInfo( s_szRegistryPath );
  82. if( FAILED( hr ) )
  83. {
  84. DPFX(DPFPREP, DVF_ERRORLEVEL, "Unable to load compression info: hr=0x%x", hr );
  85. return hr;
  86. }
  87. InitRecordFormats();
  88. CRegistry cregSettings;
  89. if( !cregSettings.Open( HKEY_CURRENT_USER, s_szRegistryPath, FALSE, TRUE ) )
  90. {
  91. s_dwDefaultBufferQuality = DPVOICE_DEFAULT_DEFAULTAGGRESSIVENESS;
  92. s_dwDefaultBufferAggressiveness = DPVOICE_DEFAULT_DEFAULTQUALITY;
  93. s_dwDefaultSensitivity = DPVOICE_DEFAULT_DEFAULTSENSITIVITY;
  94. CDirectVoiceEngine::s_lpwfxPlaybackFormat = DPVOICE_DEFAULT_PLAYBACKFORMAT;
  95. CDirectVoiceEngine::s_lpwfxPrimaryFormat = DPVOICE_DEFAULT_PRIMARYFORMAT;
  96. CDirectVoiceEngine::s_lpwfxMixerFormat = DPVOICE_DEFAULT_MIXERFORMAT;
  97. CDirectVoiceEngine::s_fDumpDiagnostics = DPVOICE_DEFAULT_DUMPDIAGNOSTICS;
  98. return DV_OK;
  99. }
  100. cregSettings.ReadDWORD( DPVOICE_REGISTRY_DEFAULTQUALITY, s_dwDefaultBufferQuality );
  101. cregSettings.ReadDWORD( DPVOICE_REGISTRY_DEFAULTAGGRESSIVENESS, s_dwDefaultBufferAggressiveness );
  102. cregSettings.ReadDWORD( DPVOICE_REGISTRY_DEFAULTSENSITIVITY, s_dwDefaultSensitivity );
  103. cregSettings.ReadBOOL( DPVOICE_REGISTRY_ASO, s_fASO );
  104. cregSettings.ReadBOOL( DPVOICE_REGISTRY_DUMPDIAGNOSTICS, s_fDumpDiagnostics );
  105. if( FAILED( CREG_ReadAndAllocWaveFormatEx( cregSettings, DPVOICE_REGISTRY_PLAYBACKFORMAT, &CDirectVoiceEngine::s_lpwfxPlaybackFormat ) ) )
  106. {
  107. CDirectVoiceEngine::s_lpwfxPlaybackFormat = DPVOICE_DEFAULT_PLAYBACKFORMAT;
  108. }
  109. if( FAILED( CREG_ReadAndAllocWaveFormatEx( cregSettings, DPVOICE_REGISTRY_PRIMARYFORMAT, &CDirectVoiceEngine::s_lpwfxPrimaryFormat ) ) )
  110. {
  111. CDirectVoiceEngine::s_lpwfxPrimaryFormat = DPVOICE_DEFAULT_PRIMARYFORMAT;
  112. }
  113. if( FAILED( CREG_ReadAndAllocWaveFormatEx( cregSettings, DPVOICE_REGISTRY_MIXERFORMAT, &CDirectVoiceEngine::s_lpwfxMixerFormat ) ) )
  114. {
  115. CDirectVoiceEngine::s_lpwfxMixerFormat = DPVOICE_DEFAULT_MIXERFORMAT;
  116. }
  117. return DV_OK;
  118. }
  119. #undef DPF_MODNAME
  120. #define DPF_MODNAME "CDirectVoiceEngine::Shutdown"
  121. //
  122. // Shutdown
  123. //
  124. // Called to free the global settings and compression list
  125. //
  126. HRESULT CDirectVoiceEngine::Shutdown()
  127. {
  128. HRESULT hr;
  129. DPFX(DPFPREP, DVF_WARNINGLEVEL, "Shutting down global DLL state" );
  130. DeInitRecordFormats();
  131. if( CDirectVoiceEngine::s_lpwfxPlaybackFormat != NULL )
  132. delete CDirectVoiceEngine::s_lpwfxPlaybackFormat;
  133. if( CDirectVoiceEngine::s_lpwfxMixerFormat != NULL )
  134. delete CDirectVoiceEngine::s_lpwfxMixerFormat;
  135. if( CDirectVoiceEngine::s_lpwfxPrimaryFormat != NULL )
  136. delete CDirectVoiceEngine::s_lpwfxPrimaryFormat;
  137. hr = DVCDB_FreeCompressionInfo();
  138. if( FAILED( hr ) )
  139. {
  140. DPFX(DPFPREP, DVF_ERRORLEVEL, "Unable to un-load compression info: hr=0x%x", hr );
  141. return hr;
  142. }
  143. DNDeleteCriticalSection( &s_csSTLLock );
  144. return DV_OK;
  145. }
  146. #undef DPF_MODNAME
  147. #define DPF_MODNAME "CDirectVoiceEngine::ValidateSpeechPacketSize"
  148. //
  149. // ValidateSpeechPacketSize
  150. //
  151. // Called to make sure the speech packet size is valid
  152. //
  153. BOOL CDirectVoiceEngine::ValidateSpeechPacketSize(LPDVFULLCOMPRESSIONINFO lpdvfCompressionInfo, DWORD dwSize)
  154. {
  155. BOOL bValid;
  156. // return true in this case because it isn't a hack attempt
  157. if( lpdvfCompressionInfo == NULL)
  158. return TRUE;
  159. // Check for VR12
  160. if( lpdvfCompressionInfo->guidType == DPVCTGUID_VR12 )
  161. bValid = ( dwSize <= lpdvfCompressionInfo->dwFrameLength );
  162. else
  163. bValid = ( dwSize == lpdvfCompressionInfo->dwFrameLength );
  164. return bValid;
  165. }