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.

215 lines
7.7 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (c) 1995 - 1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dsutil.cpp
  6. * Content: Routines for dealing with sounds from resources
  7. *
  8. *
  9. ***************************************************************************/
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. ///////////////////////////////////////////////////////////////////////////////
  14. //
  15. // DSLoadSoundBuffer Loads an IDirectSoundBuffer from a Win32 resource in
  16. // the current application.
  17. //
  18. // Params:
  19. // pDS -- Pointer to an IDirectSound that will be used to create
  20. // the buffer.
  21. //
  22. // lpName -- Name of WAV resource to load the data from. Can be a
  23. // resource id specified using the MAKEINTRESOURCE macro.
  24. //
  25. // Returns an IDirectSoundBuffer containing the wave data or NULL on error.
  26. //
  27. // example:
  28. // in the application's resource script (.RC file)
  29. // Turtle WAV turtle.wav
  30. //
  31. // some code in the application:
  32. // IDirectSoundBuffer *pDSB = DSLoadSoundBuffer(pDS, "Turtle");
  33. //
  34. // if (pDSB)
  35. // {
  36. // IDirectSoundBuffer_Play(pDSB, 0, 0, DSBPLAY_TOEND);
  37. // /* ... */
  38. //
  39. ///////////////////////////////////////////////////////////////////////////////
  40. IDirectSoundBuffer *DSLoadSoundBuffer(IDirectSound *pDS, LPCTSTR lpName);
  41. ///////////////////////////////////////////////////////////////////////////////
  42. //
  43. // DSReloadSoundBuffer Reloads an IDirectSoundBuffer from a Win32 resource in
  44. // the current application. normally used to handle
  45. // a DSERR_BUFFERLOST error.
  46. // Params:
  47. // pDSB -- Pointer to an IDirectSoundBuffer to be reloaded.
  48. //
  49. // lpName -- Name of WAV resource to load the data from. Can be a
  50. // resource id specified using the MAKEINTRESOURCE macro.
  51. //
  52. // Returns a BOOL indicating whether the buffer was successfully reloaded.
  53. //
  54. // example:
  55. // in the application's resource script (.RC file)
  56. // Turtle WAV turtle.wav
  57. //
  58. // some code in the application:
  59. // TryAgain:
  60. // HRESULT hres = IDirectSoundBuffer_Play(pDSB, 0, 0, DSBPLAY_TOEND);
  61. //
  62. // if (FAILED(hres))
  63. // {
  64. // if ((hres == DSERR_BUFFERLOST) &&
  65. // DSReloadSoundBuffer(pDSB, "Turtle"))
  66. // {
  67. // goto TryAgain;
  68. // }
  69. // /* deal with other errors... */
  70. // }
  71. //
  72. ///////////////////////////////////////////////////////////////////////////////
  73. BOOL DSReloadSoundBuffer(IDirectSoundBuffer *pDSB, LPCTSTR lpName);
  74. ///////////////////////////////////////////////////////////////////////////////
  75. //
  76. // DSGetWaveResource Finds a WAV resource in a Win32 module.
  77. //
  78. // Params:
  79. // hModule -- Win32 module handle of module containing WAV resource.
  80. // Pass NULL to indicate current application.
  81. //
  82. // lpName -- Name of WAV resource to load the data from. Can be a
  83. // resource id specified using the MAKEINTRESOURCE macro.
  84. //
  85. // ppWaveHeader-- Optional pointer to WAVEFORMATEX * to receive a pointer to
  86. // the WAVEFORMATEX header in the specified WAV resource.
  87. // Pass NULL if not required.
  88. //
  89. // ppbWaveData -- Optional pointer to BYTE * to receive a pointer to the
  90. // waveform data in the specified WAV resource. Pass NULL if
  91. // not required.
  92. //
  93. // pdwWaveSize -- Optional pointer to DWORD to receive the size of the
  94. // waveform data in the specified WAV resource. Pass NULL if
  95. // not required.
  96. //
  97. // Returns a BOOL indicating whether a valid WAV resource was found.
  98. //
  99. ///////////////////////////////////////////////////////////////////////////////
  100. BOOL DSGetWaveResource(HMODULE hModule, LPCTSTR lpName,
  101. WAVEFORMATEX **ppWaveHeader, BYTE **ppbWaveData, DWORD *pdwWaveSize);
  102. ///////////////////////////////////////////////////////////////////////////////
  103. //
  104. // HSNDOBJ Handle to a SNDOBJ object.
  105. //
  106. // SNDOBJs are implemented in dsutil as an example layer built on top
  107. // of DirectSound.
  108. //
  109. // A SNDOBJ is generally used to manage individual
  110. // sounds which need to be played multiple times concurrently. A
  111. // SNDOBJ represents a queue of IDirectSoundBuffer objects which
  112. // all refer to the same buffer memory.
  113. //
  114. // A SNDOBJ also automatically reloads the sound resource when
  115. // DirectSound returns a DSERR_BUFFERLOST
  116. //
  117. ///////////////////////////////////////////////////////////////////////////////
  118. #ifndef _HSNDOBJ_DEFINED
  119. DECLARE_HANDLE32(HSNDOBJ);
  120. #endif
  121. ///////////////////////////////////////////////////////////////////////////////
  122. //
  123. // SndObjCreate Loads a SNDOBJ from a Win32 resource in
  124. // the current application.
  125. //
  126. // Params:
  127. // pDS -- Pointer to an IDirectSound that will be used to create
  128. // the SNDOBJ.
  129. //
  130. // lpName -- Name of WAV resource to load the data from. Can be a
  131. // resource id specified using the MAKEINTRESOURCE macro.
  132. //
  133. // iConcurrent -- Integer representing the number of concurrent playbacks of
  134. // to plan for. Attempts to play more than this number will
  135. // succeed but will restart the least recently played buffer
  136. // even if it is not finished playing yet.
  137. //
  138. // Returns an HSNDOBJ or NULL on error.
  139. //
  140. // NOTES:
  141. // SNDOBJs automatically restore and reload themselves as required.
  142. //
  143. ///////////////////////////////////////////////////////////////////////////////
  144. HSNDOBJ SndObjCreate(IDirectSound *pDS, LPCTSTR lpName, int iConcurrent);
  145. ///////////////////////////////////////////////////////////////////////////////
  146. //
  147. // SndObjDestroy Frees a SNDOBJ and releases all of its buffers.
  148. //
  149. // Params:
  150. // hSO -- Handle to a SNDOBJ to free.
  151. //
  152. ///////////////////////////////////////////////////////////////////////////////
  153. void SndObjDestroy(HSNDOBJ hSO);
  154. ///////////////////////////////////////////////////////////////////////////////
  155. //
  156. // SndObjPlay Plays a buffer in a SNDOBJ.
  157. //
  158. // Params:
  159. // hSO -- Handle to a SNDOBJ to play a buffer from.
  160. //
  161. // dwPlayFlags -- Flags to pass to IDirectSoundBuffer::Play. It is not
  162. // legal to play an SndObj which has more than one buffer
  163. // with the DSBPLAY_LOOPING flag. Pass 0 to stop playback.
  164. //
  165. ///////////////////////////////////////////////////////////////////////////////
  166. BOOL SndObjPlay(HSNDOBJ hSO, DWORD dwPlayFlags);
  167. ///////////////////////////////////////////////////////////////////////////////
  168. //
  169. // SndObjStop Stops one or more buffers in a SNDOBJ.
  170. //
  171. // Params:
  172. // hSO -- Handle to a SNDOBJ to play a buffer from.
  173. //
  174. ///////////////////////////////////////////////////////////////////////////////
  175. BOOL SndObjStop(HSNDOBJ hSO);
  176. ///////////////////////////////////////////////////////////////////////////////
  177. //
  178. // SndObjGetFreeBuffer returns one of the cloned buffers that is
  179. // not currently playing
  180. //
  181. // Params:
  182. // hSO -- Handle to a SNDOBJ
  183. //
  184. // NOTES:
  185. // This function is provided so that callers can set things like pan etc
  186. // before playing the buffer.
  187. //
  188. // EXAMPLE:
  189. // ...
  190. //
  191. ///////////////////////////////////////////////////////////////////////////////
  192. IDirectSoundBuffer *SndObjGetFreeBuffer(HSNDOBJ hSO);
  193. ///////////////////////////////////////////////////////////////////////////////
  194. //
  195. // helper routines
  196. //
  197. ///////////////////////////////////////////////////////////////////////////////
  198. BOOL DSFillSoundBuffer(IDirectSoundBuffer *pDSB, BYTE *pbWaveData, DWORD dwWaveSize);
  199. BOOL DSParseWaveResource(void *pvRes, WAVEFORMATEX **ppWaveHeader, BYTE **ppbWaveData, DWORD *pdwWaveSize);
  200. #ifdef __cplusplus
  201. }
  202. #endif