Leaked source code of windows server 2003
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.

254 lines
7.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dsoundbufferobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // dSoundBufferObj.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 "dSoundBufferObj.h"
  18. #include "dSoundObj.h"
  19. #include "dSound3DListener.h"
  20. #include "dSound3DBuffer.h"
  21. extern HRESULT InternalSaveToFile(IDirectSoundBuffer *pBuff,BSTR file);
  22. CONSTRUCTOR(_dxj_DirectSoundBuffer, {});
  23. DESTRUCTOR(_dxj_DirectSoundBuffer, {});
  24. GETSET_OBJECT(_dxj_DirectSoundBuffer);
  25. PASS_THROUGH1_R(_dxj_DirectSoundBuffer, getVolume, GetVolume, long*);
  26. PASS_THROUGH1_R(_dxj_DirectSoundBuffer, getPan, GetPan, long*);
  27. PASS_THROUGH_CAST_1_R(_dxj_DirectSoundBuffer, getFrequency, GetFrequency, long*,(DWORD*));
  28. PASS_THROUGH_CAST_1_R(_dxj_DirectSoundBuffer, getStatus, GetStatus, long*,(DWORD*));
  29. PASS_THROUGH_CAST_1_R(_dxj_DirectSoundBuffer, setCurrentPosition, SetCurrentPosition, long,(DWORD));
  30. PASS_THROUGH_CAST_1_R(_dxj_DirectSoundBuffer, setFormat, SetFormat, WaveFormatex*, (LPWAVEFORMATEX));
  31. // PASS_THROUGH1_R(_dxj_DirectSoundBuffer, setVolume, SetVolume, LONG);
  32. PASS_THROUGH1_R(_dxj_DirectSoundBuffer, setPan, SetPan, LONG);
  33. PASS_THROUGH_CAST_1_R(_dxj_DirectSoundBuffer, setFrequency, SetFrequency, long,(DWORD));
  34. PASS_THROUGH_R(_dxj_DirectSoundBuffer, stop, Stop);
  35. PASS_THROUGH_R(_dxj_DirectSoundBuffer, restore, Restore);
  36. STDMETHODIMP C_dxj_DirectSoundBufferObject::setVolume(LONG vol)
  37. {
  38. #ifdef JAVA
  39. IDxSecurity *ids=0;
  40. HRESULT hr = CoCreateInstance(CLSID_DxSecurity, 0, 1, IID_IDxSecurity, (void **)&ids);
  41. if(hr == S_OK)
  42. hr = ids->isFullDirectX();
  43. if(hr != S_OK )
  44. return E_FAIL;
  45. #endif
  46. return m__dxj_DirectSoundBuffer->SetVolume(vol);
  47. }
  48. STDMETHODIMP C_dxj_DirectSoundBufferObject::getDirectSound3dListener(I_dxj_DirectSound3dListener **retval)
  49. {
  50. IDirectSound3DListener *lp3dl;
  51. HRESULT hr = DD_OK;
  52. if( (hr=m__dxj_DirectSoundBuffer->QueryInterface(IID_IDirectSound3DListener, (void**) &lp3dl)) != DD_OK)
  53. return hr;
  54. INTERNAL_CREATE(_dxj_DirectSound3dListener, lp3dl, retval);
  55. return hr;
  56. }
  57. STDMETHODIMP C_dxj_DirectSoundBufferObject::getDirectSound3dBuffer(I_dxj_DirectSound3dBuffer **retval)
  58. {
  59. IDirectSound3DBuffer *lp3db;
  60. HRESULT hr = DD_OK;
  61. if( (hr=m__dxj_DirectSoundBuffer->QueryInterface(IID_IDirectSound3DBuffer, (void**) &lp3db)) != DD_OK)
  62. return hr;
  63. INTERNAL_CREATE(_dxj_DirectSound3dBuffer, lp3db, retval);
  64. return hr;
  65. }
  66. STDMETHODIMP C_dxj_DirectSoundBufferObject::getCaps(DSBCaps* caps)
  67. {
  68. if(!caps)
  69. return E_POINTER;
  70. caps->lSize = sizeof(DSBCAPS);
  71. return m__dxj_DirectSoundBuffer->GetCaps((LPDSBCAPS)caps);
  72. }
  73. /////////////////////////////////////////////////////////////////////////////
  74. STDMETHODIMP C_dxj_DirectSoundBufferObject::getCurrentPosition(DSCursors *desc)
  75. {
  76. if(!desc)
  77. return E_POINTER;
  78. return (m__dxj_DirectSoundBuffer->GetCurrentPosition((DWORD*)&desc->lPlay, (DWORD*)&desc->lWrite) );
  79. }
  80. /////////////////////////////////////////////////////////////////////////////
  81. //Java has no direct access to system memory, so it allocates it's own buffer
  82. //which is passed into WriteBuffer(). Because the environment is now double
  83. //buffered there is no need to Lock Java memory. WriteBuffer() calls
  84. //both lock and Unlock internally to write the result after the fact.
  85. /////////////////////////////////////////////////////////////////////////////
  86. STDMETHODIMP C_dxj_DirectSoundBufferObject::writeBuffer(long start, long totsz,
  87. void *buf, long flags)
  88. {
  89. #pragma message ("SoundBuffer writeBuffer ")
  90. byte *buffer=(byte*)buf; //(byte*)((SAFEARRAY*)*ppsa)->pvData;
  91. if(!buffer)
  92. return E_POINTER;
  93. LPVOID p1, p2;
  94. DWORD size1=0, size2=0;
  95. HRESULT val = E_FAIL;
  96. __try {
  97. if ((val = m__dxj_DirectSoundBuffer->Lock((DWORD)start, (DWORD)totsz, &p1, &size1, &p2, &size2,
  98. (DWORD)flags)) != DS_OK)
  99. return val;
  100. // Copy to buffer end, then do a wrapped portion if it exists, then unlock
  101. if (size1)
  102. memcpy (p1, &buffer[start], size1);
  103. if (size2)
  104. memcpy(p2, &buffer, size2);
  105. //docdoc: because Lock and Unlock are tied together within WriteBuffer,
  106. // DSBufferDesc no longer needs to save Lock's system pointers.
  107. val=m__dxj_DirectSoundBuffer->Unlock(p1, size1, p2, size2);
  108. }
  109. __except(0,0){
  110. return E_FAIL;
  111. }
  112. return val;
  113. }
  114. /////////////////////////////////////////////////////////////////////////////
  115. //Java has no direct access to system memory, so it allocates it's own buffer
  116. //which is passed into WriteBuffer(). Because the environment is now double
  117. //buffered there is no need to Lock Java memory. WriteBuffer() calls
  118. //both lock and Unlock internally to write the result after the fact.
  119. /////////////////////////////////////////////////////////////////////////////
  120. STDMETHODIMP C_dxj_DirectSoundBufferObject::readBuffer(long start, long totsz,
  121. void *buf, long flags)
  122. {
  123. //byte *buffer=(byte*)((SAFEARRAY*)*ppsa)->pvData;
  124. byte *buffer=(byte*)buf;
  125. if(!buffer)
  126. return E_POINTER;
  127. LPVOID p1, p2;
  128. DWORD size1=0, size2=0;
  129. HRESULT val = E_FAIL;
  130. __try {
  131. if ((val = m__dxj_DirectSoundBuffer->Lock((DWORD)start, (DWORD)totsz, &p1, &size1, &p2, &size2,
  132. (DWORD)flags)) != DS_OK)
  133. return val;
  134. // Copy to buffer end, then do a wrapped portion if it exists, then unlock
  135. if (size1)
  136. memcpy (&buffer[start],p1, size1);
  137. if (size2)
  138. memcpy(&buffer,p2, size2);
  139. //docdoc: because Lock and Unlock are tied together within WriteBuffer,
  140. // DSBufferDesc no longer needs to save Lock's system pointers.
  141. val= m__dxj_DirectSoundBuffer->Unlock(p1, size1, p2, size2);
  142. }
  143. __except(1,1){
  144. return E_FAIL;
  145. }
  146. return val;
  147. }
  148. /////////////////////////////////////////////////////////////////////////////
  149. STDMETHODIMP C_dxj_DirectSoundBufferObject::getFormat(WaveFormatex *format)
  150. {
  151. DWORD *wsize=0; // docdoc: throw away returned written size
  152. HRESULT hr=DS_OK;
  153. hr=m__dxj_DirectSoundBuffer->GetFormat((LPWAVEFORMATEX)format, (DWORD)sizeof(WaveFormatex), wsize);
  154. return hr;
  155. }
  156. /////////////////////////////////////////////////////////////////////////////
  157. STDMETHODIMP C_dxj_DirectSoundBufferObject::initialize(I_dxj_DirectSound *ds, DSBufferDesc *buf,
  158. BYTE *wave)
  159. {
  160. if(! (ds && buf && wave) )
  161. return E_POINTER;
  162. // make Java desc look like DirectX desc
  163. buf->lSize = sizeof(DSBUFFERDESC);
  164. buf->lpwfxFormat = PtrToLong(wave); //bugbug SUNDOWN
  165. DO_GETOBJECT_NOTNULL(LPDIRECTSOUND, lpds, ds)
  166. m__dxj_DirectSoundBuffer->Initialize(lpds, (LPDSBUFFERDESC)buf);
  167. return S_OK;
  168. }
  169. /////////////////////////////////////////////////////////////////////////////
  170. STDMETHODIMP C_dxj_DirectSoundBufferObject::play(long flags)
  171. {
  172. HRESULT hr=DS_OK;
  173. if((hr=m__dxj_DirectSoundBuffer->Play(0, 0, (DWORD)flags)) != DS_OK)
  174. return hr;
  175. return hr;
  176. }
  177. STDMETHODIMP C_dxj_DirectSoundBufferObject::setNotificationPositions (long nElements,SAFEARRAY **ppsa)
  178. {
  179. if (!ISSAFEARRAY1D(ppsa,(DWORD)nElements))
  180. return E_INVALIDARG;
  181. HRESULT hr;
  182. LPDIRECTSOUNDNOTIFY pDSN=NULL;
  183. hr=m__dxj_DirectSoundBuffer->QueryInterface(IID_IDirectSoundNotify,(void**)&pDSN);
  184. if FAILED(hr) return hr;
  185. hr=pDSN->SetNotificationPositions((DWORD)nElements,(LPCDSBPOSITIONNOTIFY)((SAFEARRAY*)*ppsa)->pvData);
  186. pDSN->Release();
  187. return hr;
  188. }
  189. STDMETHODIMP C_dxj_DirectSoundBufferObject::saveToFile(BSTR file)
  190. {
  191. HRESULT hr= InternalSaveToFile(m__dxj_DirectSoundBuffer,file);
  192. return hr;
  193. }