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.

180 lines
4.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dsoundobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // dSoundObj.cpp : Implementation of CDirectApp and DLL registration.
  11. // DHF_DS entire file
  12. #define DIRECTSOUND_VERSION 0x600
  13. #include "stdafx.h"
  14. #include "Direct.h"
  15. #include "dSound.h"
  16. #include "dms.h"
  17. #include "dSoundObj.h"
  18. #include "dSoundBufferObj.h"
  19. extern HRESULT InternalCreateSoundBufferFromFile(LPDIRECTSOUND lpDirectSound,LPDSBUFFERDESC pDesc,WCHAR *file,LPDIRECTSOUNDBUFFER *lplpDirectSoundBuffer) ;
  20. extern HRESULT InternalCreateSoundBufferFromResource(LPDIRECTSOUND lpDirectSound,LPDSBUFFERDESC pDesc,HANDLE resHandle,WCHAR *resName,LPDIRECTSOUNDBUFFER *lplpDirectSoundBuffer);
  21. CONSTRUCTOR(_dxj_DirectSound, {m__dxj_DirectSound=NULL;m_pDriverGuid=NULL;});
  22. DESTRUCTOR(_dxj_DirectSound, {if (m_pDriverGuid) delete m_pDriverGuid;});
  23. GETSET_OBJECT(_dxj_DirectSound);
  24. //
  25. /*** IDirectSound methods ***/
  26. //
  27. PASS_THROUGH_CAST_1_R(_dxj_DirectSound, getSpeakerConfig, GetSpeakerConfig, long*,(DWORD*));
  28. PASS_THROUGH_CAST_1_R(_dxj_DirectSound, setSpeakerConfig, SetSpeakerConfig, long,(DWORD));
  29. STDMETHODIMP C_dxj_DirectSoundObject::getCaps(DSCaps* caps)
  30. {
  31. caps->lSize = sizeof(DSCAPS);
  32. return m__dxj_DirectSound->GetCaps((LPDSCAPS)caps);
  33. }
  34. /////////////////////////////////////////////////////////////////////////////
  35. /////////////////////////////////////////////////////////////////////////////
  36. STDMETHODIMP C_dxj_DirectSoundObject::setCooperativeLevel(HWnd h, long d)
  37. {
  38. if( m__dxj_DirectSound == NULL )
  39. return E_FAIL;
  40. return m__dxj_DirectSound->SetCooperativeLevel((HWND)h, (DWORD)d);
  41. }
  42. /////////////////////////////////////////////////////////////////////////////
  43. STDMETHODIMP C_dxj_DirectSoundObject::duplicateSoundBuffer(I_dxj_DirectSoundBuffer *src,
  44. I_dxj_DirectSoundBuffer **val)
  45. {
  46. if(! (src && val) )
  47. return E_POINTER;
  48. DO_GETOBJECT_NOTNULL(LPDIRECTSOUNDBUFFER, lpdsb, src);
  49. //Need to create a second one
  50. LPDIRECTSOUNDBUFFER dsb=0;
  51. HRESULT hr=DD_OK;
  52. hr=m__dxj_DirectSound->DuplicateSoundBuffer((LPDIRECTSOUNDBUFFER)lpdsb, &dsb);
  53. if(hr == DD_OK)
  54. {
  55. INTERNAL_CREATE(_dxj_DirectSoundBuffer, dsb, val);
  56. }
  57. return hr;
  58. }
  59. #pragma message ("Consider putting waveformat back in DSBufferDesc")
  60. /////////////////////////////////////////////////////////////////////////////
  61. STDMETHODIMP C_dxj_DirectSoundObject::createSoundBuffer(DSBufferDesc *desc,
  62. WaveFormatex *wave, I_dxj_DirectSoundBuffer **val)
  63. {
  64. LPDIRECTSOUNDBUFFER dsb; // Need to get the buffer first
  65. BOOL bDirty=FALSE;
  66. // make Java desc look like DirectX desc
  67. desc->lSize = sizeof(DSBUFFERDESC);
  68. for (int i=0;i<sizeof(WAVEFORMATEX);i++) {
  69. if (((byte*)wave)[i]!=0) bDirty=TRUE;
  70. }
  71. if (bDirty==TRUE){
  72. desc->lpwfxFormat = PtrToLong(wave); //bugbug SUNDOWN
  73. }
  74. else {
  75. desc->lpwfxFormat = 0;
  76. }
  77. LPDSBUFFERDESC lpds ;
  78. lpds = (LPDSBUFFERDESC)desc;
  79. HRESULT hr=S_OK;
  80. hr = m__dxj_DirectSound->CreateSoundBuffer(lpds, &dsb, NULL);
  81. if(hr == DD_OK)
  82. {
  83. INTERNAL_CREATE(_dxj_DirectSoundBuffer, dsb, val);
  84. }
  85. return hr;
  86. }
  87. STDMETHODIMP C_dxj_DirectSoundObject::createSoundBufferFromFile(BSTR fileName, DSBufferDesc *desc,
  88. WaveFormatex *wave, I_dxj_DirectSoundBuffer **val)
  89. {
  90. LPDIRECTSOUNDBUFFER dsb; // Need to get the buffer first
  91. LPDSBUFFERDESC lpds ;
  92. HRESULT hr=S_OK;
  93. *val=NULL;
  94. desc->lSize = sizeof(DSBUFFERDESC);
  95. desc->lpwfxFormat = (long)PtrToLong(wave); //bugbug SUNDOWN
  96. lpds = (LPDSBUFFERDESC)desc;
  97. hr=InternalCreateSoundBufferFromFile(m__dxj_DirectSound,(LPDSBUFFERDESC)desc,
  98. (WCHAR*)fileName,&dsb);
  99. if(hr == DD_OK)
  100. {
  101. INTERNAL_CREATE(_dxj_DirectSoundBuffer, dsb, val);
  102. }
  103. return hr;
  104. }
  105. STDMETHODIMP C_dxj_DirectSoundObject::createSoundBufferFromResource(BSTR resFile, BSTR resName, DSBufferDesc *desc,
  106. WaveFormatex *wave, I_dxj_DirectSoundBuffer **val)
  107. {
  108. LPDIRECTSOUNDBUFFER dsb; // Need to get the buffer first
  109. LPDSBUFFERDESC lpds ;
  110. HRESULT hr=S_OK;
  111. HMODULE hMod=NULL;
  112. USES_CONVERSION;
  113. if ((resFile) &&(resFile[0]!=0)){
  114. // NOTE
  115. // seems that GetModuleHandleW is
  116. // always returning 0 on w98??
  117. // use ansi verion
  118. LPCTSTR pszName = W2T(resFile);
  119. hMod= GetModuleHandle(pszName);
  120. }
  121. *val=NULL;
  122. desc->lSize = sizeof(DSBUFFERDESC);
  123. desc->lpwfxFormat = (long)PtrToLong(wave); //NOTE SUNDOWN issue
  124. lpds = (LPDSBUFFERDESC)desc;
  125. hr=InternalCreateSoundBufferFromResource(m__dxj_DirectSound,(LPDSBUFFERDESC)desc,
  126. (HANDLE)hMod,(WCHAR*)resName,&dsb);
  127. if(hr == DD_OK)
  128. {
  129. INTERNAL_CREATE(_dxj_DirectSoundBuffer, dsb, val);
  130. }
  131. return hr;
  132. }