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.

861 lines
22 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. ////
  23. // awav.c - wav array functions
  24. ////
  25. #include "winlocal.h"
  26. #include <stdlib.h>
  27. #include "awav.h"
  28. #include "wav.h"
  29. #include "mem.h"
  30. #include "trace.h"
  31. ////
  32. // private definitions
  33. ////
  34. // awav control struct
  35. //
  36. typedef struct AWAV
  37. {
  38. DWORD dwVersion;
  39. HINSTANCE hInst;
  40. HTASK hTask;
  41. HWAV FAR *lpahWav;
  42. int chWav;
  43. int ihWav;
  44. int idDev;
  45. PLAYSTOPPEDPROC lpfnPlayStopped;
  46. HANDLE hUserPlayStopped;
  47. DWORD dwReserved;
  48. DWORD dwFlags;
  49. BOOL fStopping;
  50. } AWAV, FAR *LPAWAV;
  51. // helper functions
  52. //
  53. static LPAWAV AWavGetPtr(HAWAV hAWav);
  54. static HAWAV AWavGetHandle(LPAWAV lpAWav);
  55. BOOL CALLBACK PlayStoppedProc(HWAV hWav, HANDLE hUser, DWORD dwReserved);
  56. ////
  57. // public functions
  58. ////
  59. // AWavOpen - initialize array of open wav files
  60. // <dwVersion> (i) must be AWAV_VERSION
  61. // <hInst> (i) instance handle of calling module
  62. // <lpahWav> (i) pointer to array of HWAVs
  63. // <chWav> (i) count of HWAVs pointed to by lpahWav
  64. // <dwFlags> (i) control flags
  65. // 0 reserved; must be zero
  66. // return handle (NULL if error)
  67. //
  68. HAWAV DLLEXPORT WINAPI AWavOpen(DWORD dwVersion, HINSTANCE hInst, HWAV FAR *lpahWav, int chWav, DWORD dwFlags)
  69. {
  70. BOOL fSuccess = TRUE;
  71. LPAWAV lpAWav = NULL;
  72. if (dwVersion != AWAV_VERSION)
  73. fSuccess = TraceFALSE(NULL);
  74. else if (hInst == NULL)
  75. fSuccess = TraceFALSE(NULL);
  76. else if (lpahWav == NULL)
  77. fSuccess = TraceFALSE(NULL);
  78. else if (chWav < 1)
  79. fSuccess = TraceFALSE(NULL);
  80. else if ((lpAWav = (LPAWAV) MemAlloc(NULL, sizeof(AWAV), 0)) == NULL)
  81. fSuccess = TraceFALSE(NULL);
  82. else
  83. {
  84. lpAWav->dwVersion = dwVersion;
  85. lpAWav->hInst = hInst;
  86. lpAWav->hTask = GetCurrentTask();
  87. lpAWav->lpahWav = lpahWav;
  88. lpAWav->chWav = chWav;
  89. lpAWav->ihWav = 0;
  90. lpAWav->idDev = 0;
  91. lpAWav->lpfnPlayStopped = NULL;
  92. lpAWav->hUserPlayStopped = 0;
  93. lpAWav->dwReserved = 0;
  94. lpAWav->dwFlags = 0;
  95. lpAWav->fStopping = FALSE;
  96. }
  97. if (!fSuccess)
  98. {
  99. AWavClose(AWavGetHandle(lpAWav));
  100. lpAWav = NULL;
  101. }
  102. return fSuccess ? AWavGetHandle(lpAWav) : NULL;
  103. }
  104. // AWavClose - shut down array of open wav files
  105. // <hAWav> (i) handle returned from AWavOpen
  106. // return 0 if success
  107. //
  108. int DLLEXPORT WINAPI AWavClose(HAWAV hAWav)
  109. {
  110. BOOL fSuccess = TRUE;
  111. LPAWAV lpAWav;
  112. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  113. fSuccess = TraceFALSE(NULL);
  114. else
  115. {
  116. // make sure playback is complete
  117. //
  118. if (AWavStop(hAWav) != 0)
  119. fSuccess = TraceFALSE(NULL);
  120. else if ((lpAWav = MemFree(NULL, lpAWav)) != NULL)
  121. fSuccess = TraceFALSE(NULL);
  122. }
  123. return fSuccess ? 0 : -1;
  124. }
  125. // AWavPlayEx - play array of wav files
  126. // <hAWav> (i) handle returned from AWavOpen
  127. // see WavPlayEx() for further description
  128. // return 0 if success
  129. //
  130. int DLLEXPORT WINAPI AWavPlayEx(HAWAV hAWav, int idDev,
  131. PLAYSTOPPEDPROC lpfnPlayStopped, HANDLE hUserPlayStopped,
  132. DWORD dwReserved, DWORD dwFlags)
  133. {
  134. BOOL fSuccess = TRUE;
  135. LPAWAV lpAWav;
  136. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  137. fSuccess = TraceFALSE(NULL);
  138. // make sure we are not playing
  139. //
  140. else if (AWavStop(hAWav) != 0)
  141. fSuccess = TraceFALSE(NULL);
  142. // save params so we can use them for each element in array
  143. //
  144. else if (lpAWav->idDev = idDev, FALSE)
  145. ;
  146. else if (lpAWav->lpfnPlayStopped = lpfnPlayStopped, FALSE)
  147. ;
  148. else if (lpAWav->hUserPlayStopped = hUserPlayStopped, FALSE)
  149. ;
  150. else if (lpAWav->dwReserved = dwReserved, FALSE)
  151. ;
  152. else if (lpAWav->dwFlags = dwFlags, FALSE)
  153. ;
  154. // start playback of current element in wav array
  155. //
  156. else if (WavPlayEx(*(lpAWav->lpahWav + lpAWav->ihWav),
  157. lpAWav->idDev, PlayStoppedProc, hAWav,
  158. lpAWav->dwReserved, lpAWav->dwFlags) != 0)
  159. {
  160. fSuccess = TraceFALSE(NULL);
  161. }
  162. return fSuccess ? 0 : -1;
  163. }
  164. // AWavStop - stop playing wav array
  165. // <hAWav> (i) handle returned from AWavOpen
  166. // see WavStop() for further description
  167. // return 0 if success
  168. //
  169. int DLLEXPORT WINAPI AWavStop(HAWAV hAWav)
  170. {
  171. BOOL fSuccess = TRUE;
  172. LPAWAV lpAWav;
  173. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  174. fSuccess = TraceFALSE(NULL);
  175. // set flag for use in PlayStoppedProc
  176. //
  177. else if (lpAWav->fStopping = TRUE, FALSE)
  178. ;
  179. // stop playback of current element in wav array
  180. //
  181. else if (WavStop(*(lpAWav->lpahWav + lpAWav->ihWav)) != 0)
  182. fSuccess = TraceFALSE(NULL);
  183. // clear flag used in PlayStoppedProc
  184. //
  185. if (lpAWav != NULL)
  186. lpAWav->fStopping = FALSE;
  187. return fSuccess ? 0 : -1;
  188. }
  189. // AWavGetState - return current wav state
  190. // <hAWav> (i) handle returned from AWavOpen
  191. // see WavGetState() for further description
  192. // return WAV_STOPPED, WAV_PLAYING, WAV_RECORDING, or 0 if error
  193. //
  194. WORD DLLEXPORT WINAPI AWavGetState(HAWAV hAWav)
  195. {
  196. BOOL fSuccess = TRUE;
  197. LPAWAV lpAWav;
  198. WORD wState = WAV_STOPPED;
  199. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  200. fSuccess = TraceFALSE(NULL);
  201. else
  202. {
  203. // get state of current element in wav array
  204. //
  205. wState = WavGetState(*(lpAWav->lpahWav + lpAWav->ihWav));
  206. }
  207. return fSuccess ? wState : 0;
  208. }
  209. // AWavGetLength - get current wav data length in milleseconds
  210. // <hAWav> (i) handle returned from AWavOpen
  211. // see WavGetState() for further description
  212. // return milleseconds if success, otherwise -1
  213. //
  214. long DLLEXPORT WINAPI AWavGetLength(HAWAV hAWav)
  215. {
  216. BOOL fSuccess = TRUE;
  217. LPAWAV lpAWav;
  218. long msLength = 0;
  219. int ihWav;
  220. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  221. fSuccess = TraceFALSE(NULL);
  222. // simulated length is calculated as
  223. // total length of each element in wav array
  224. //
  225. else for (ihWav = 0; fSuccess && ihWav < lpAWav->chWav; ++ihWav)
  226. {
  227. long msTemp;
  228. if ((msTemp = WavGetLength(*(lpAWav->lpahWav + ihWav))) < 0)
  229. fSuccess = TraceFALSE(NULL);
  230. else
  231. msLength += msTemp;
  232. }
  233. return fSuccess ? msLength : -1;
  234. }
  235. // AWavGetPosition - get current wav data position in milleseconds
  236. // <hAWav> (i) handle returned from AWavOpen
  237. // see WavGetPosition() for further description
  238. // return milleseconds if success, otherwise -1
  239. //
  240. long DLLEXPORT WINAPI AWavGetPosition(HAWAV hAWav)
  241. {
  242. BOOL fSuccess = TRUE;
  243. LPAWAV lpAWav;
  244. long msPos = 0;
  245. int ihWav;
  246. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  247. fSuccess = TraceFALSE(NULL);
  248. // simulated position is calculated as
  249. // total length of previous elements plus position of current element
  250. //
  251. else for (ihWav = 0; fSuccess && ihWav <= lpAWav->ihWav; ++ihWav)
  252. {
  253. long msTemp = 0;
  254. if (ihWav < lpAWav->ihWav &&
  255. (msTemp = WavGetLength(*(lpAWav->lpahWav + ihWav))) < 0)
  256. fSuccess = TraceFALSE(NULL);
  257. else if (ihWav == lpAWav->ihWav &&
  258. (msTemp = WavGetPosition(*(lpAWav->lpahWav + ihWav))) < 0)
  259. fSuccess = TraceFALSE(NULL);
  260. msPos += msTemp;
  261. }
  262. return fSuccess ? msPos : -1;
  263. }
  264. // AWavSetPosition - set current wav data position in milleseconds
  265. // <hAWav> (i) handle returned from AWavOpen
  266. // see WavSetPosition() for further description
  267. // return new position in milleseconds if success, otherwise -1
  268. //
  269. long DLLEXPORT WINAPI AWavSetPosition(HAWAV hAWav, long msPosition)
  270. {
  271. BOOL fSuccess = TRUE;
  272. LPAWAV lpAWav;
  273. int ihWav;
  274. long msPos = 0;
  275. BOOL fPosSet = FALSE;
  276. BOOL fRestart = FALSE;
  277. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  278. fSuccess = TraceFALSE(NULL);
  279. // make sure requested position is reasonable
  280. //
  281. else if (msPosition < 0 || msPosition > AWavGetLength(hAWav))
  282. fSuccess = TraceFALSE(NULL);
  283. // search for the element which contains requested position
  284. //
  285. else for (ihWav = 0; fSuccess && ihWav < lpAWav->chWav; ++ihWav)
  286. {
  287. long msTemp;
  288. if (WavGetState(*(lpAWav->lpahWav + ihWav)) == WAV_PLAYING)
  289. {
  290. // set flag for use in PlayStoppedProc
  291. //
  292. if (lpAWav->fStopping = TRUE, FALSE)
  293. ;
  294. // stop playback of current element in wav array
  295. //
  296. else if (WavStop(*(lpAWav->lpahWav + ihWav)) != 0)
  297. fSuccess = TraceFALSE(NULL);
  298. // clear flag used in PlayStoppedProc
  299. //
  300. if (lpAWav != NULL)
  301. lpAWav->fStopping = FALSE;
  302. // remember to restart playback later
  303. //
  304. fRestart = TRUE;
  305. }
  306. if ((msTemp = WavGetLength(*(lpAWav->lpahWav + ihWav))) < 0)
  307. fSuccess = TraceFALSE(NULL);
  308. if (fPosSet)
  309. {
  310. // all elements after the current one should have zero position
  311. //
  312. if ((msTemp = WavSetPosition(*(lpAWav->lpahWav + ihWav), 0)) < 0)
  313. fSuccess = TraceFALSE(NULL);
  314. }
  315. else if (msPosition < msPos + msTemp)
  316. {
  317. // set relative position within current element
  318. //
  319. if ((msTemp = WavSetPosition(*(lpAWav->lpahWav + ihWav),
  320. msPosition - msPos)) < 0)
  321. fSuccess = TraceFALSE(NULL);
  322. else
  323. {
  324. // keep track of simulated position
  325. //
  326. msPos += msTemp;
  327. // this element becomes the current one
  328. //
  329. lpAWav->ihWav = ihWav;
  330. fPosSet = TRUE;
  331. }
  332. }
  333. else
  334. {
  335. msPos += msTemp;
  336. // all elements before the current one should have zero position
  337. //
  338. if ((msTemp = WavSetPosition(*(lpAWav->lpahWav + ihWav), 0)) < 0)
  339. fSuccess = TraceFALSE(NULL);
  340. }
  341. }
  342. // if necessary, restart playback of current element in wav array
  343. //
  344. if (fSuccess && fRestart &&
  345. WavPlayEx(*(lpAWav->lpahWav + lpAWav->ihWav),
  346. lpAWav->idDev, PlayStoppedProc, hAWav,
  347. lpAWav->dwReserved, lpAWav->dwFlags) != 0)
  348. fSuccess = TraceFALSE(NULL);
  349. return fSuccess ? msPos : -1;
  350. }
  351. // AWavGetFormat - get wav format of current element in wav array
  352. // <hAWav> (i) handle returned from AWavOpen
  353. // see WavGetFormat() for further description
  354. // return pointer to specified format, NULL if error
  355. //
  356. LPWAVEFORMATEX DLLEXPORT WINAPI AWavGetFormat(HAWAV hAWav, DWORD dwFlags)
  357. {
  358. BOOL fSuccess = TRUE;
  359. LPAWAV lpAWav;
  360. LPWAVEFORMATEX lpwfx;
  361. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  362. fSuccess = TraceFALSE(NULL);
  363. // get format of current element
  364. //
  365. else if ((lpwfx = WavGetFormat(*(lpAWav->lpahWav + lpAWav->ihWav), dwFlags)) == NULL)
  366. fSuccess = TraceFALSE(NULL);
  367. return fSuccess ? lpwfx : NULL;
  368. }
  369. // AWavSetFormat - set wav format for all elements in wav array
  370. // <hAWav> (i) handle returned from AWavOpen
  371. // see WavSetFormat() for further description
  372. // return 0 if success
  373. //
  374. int DLLEXPORT WINAPI AWavSetFormat(HAWAV hAWav,
  375. LPWAVEFORMATEX lpwfx, DWORD dwFlags)
  376. {
  377. BOOL fSuccess = TRUE;
  378. LPAWAV lpAWav;
  379. int ihWav;
  380. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  381. fSuccess = TraceFALSE(NULL);
  382. // set format for all elements
  383. //
  384. else for (ihWav = 0; fSuccess && ihWav < lpAWav->chWav; ++ihWav)
  385. {
  386. if (WavSetFormat(*(lpAWav->lpahWav + ihWav), lpwfx, dwFlags) != 0)
  387. fSuccess = TraceFALSE(NULL);
  388. }
  389. return fSuccess ? 0 : -1;
  390. }
  391. // AWavChooseFormat - choose and set audio format from dialog box
  392. // <hAWav> (i) handle returned from AWavOpen
  393. // see WavChooseFormat() for further description
  394. // return 0 if success
  395. //
  396. int DLLEXPORT WINAPI AWavChooseFormat(HAWAV hAWav, HWND hwndOwner, LPCTSTR lpszTitle, DWORD dwFlags)
  397. {
  398. BOOL fSuccess = TRUE;
  399. LPAWAV lpAWav;
  400. int ihWav;
  401. LPWAVEFORMATEX lpwfx = NULL;
  402. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  403. fSuccess = TraceFALSE(NULL);
  404. // choose and set format for current element
  405. //
  406. else if (WavChooseFormat(*(lpAWav->lpahWav + lpAWav->ihWav), hwndOwner, lpszTitle, dwFlags) != 0)
  407. fSuccess = TraceFALSE(NULL);
  408. // get chosen format
  409. //
  410. else if ((lpwfx = WavGetFormat(*(lpAWav->lpahWav + lpAWav->ihWav), dwFlags)) == NULL)
  411. fSuccess = TraceFALSE(NULL);
  412. // set chosen format for all other elements
  413. //
  414. else for (ihWav = 0; fSuccess && ihWav < lpAWav->chWav; ++ihWav)
  415. {
  416. if (ihWav != lpAWav->ihWav)
  417. {
  418. if (WavSetFormat(*(lpAWav->lpahWav + ihWav), lpwfx, dwFlags) != 0)
  419. fSuccess = TraceFALSE(NULL);
  420. }
  421. }
  422. if (lpwfx != NULL && WavFormatFree(lpwfx) != 0)
  423. fSuccess = TraceFALSE(NULL);
  424. return fSuccess ? 0 : -1;
  425. }
  426. // AWavGetVolume - get current volume level
  427. // <hAWav> (i) handle returned from AWavOpen
  428. // see WavGetVolume() for further description
  429. // return volume level (0 minimum through 100 maximum, -1 if error)
  430. //
  431. int DLLEXPORT WINAPI AWavGetVolume(HAWAV hAWav, int idDev, DWORD dwFlags)
  432. {
  433. BOOL fSuccess = TRUE;
  434. LPAWAV lpAWav;
  435. int nLevel;
  436. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  437. fSuccess = TraceFALSE(NULL);
  438. // get volume of current element
  439. //
  440. else if ((nLevel = WavGetVolume(*(lpAWav->lpahWav + lpAWav->ihWav), idDev, dwFlags)) < 0)
  441. fSuccess = TraceFALSE(NULL);
  442. return fSuccess ? nLevel : -1;
  443. }
  444. // AWavSetVolume - set current volume level
  445. // <hAWav> (i) handle returned from AWavOpen
  446. // see WavGetVolume() for further description
  447. // return 0 if success
  448. //
  449. int DLLEXPORT WINAPI AWavSetVolume(HAWAV hAWav, int idDev, int nLevel, DWORD dwFlags)
  450. {
  451. BOOL fSuccess = TRUE;
  452. LPAWAV lpAWav;
  453. int ihWav;
  454. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  455. fSuccess = TraceFALSE(NULL);
  456. // set volume for all elements
  457. //
  458. else for (ihWav = 0; fSuccess && ihWav < lpAWav->chWav; ++ihWav)
  459. {
  460. if (WavSetVolume(*(lpAWav->lpahWav + ihWav), idDev, nLevel, dwFlags) != 0)
  461. fSuccess = TraceFALSE(NULL);
  462. }
  463. return fSuccess ? 0 : -1;
  464. }
  465. // AWavSupportsVolume - check if audio can be played at specified volume
  466. // <hAWav> (i) handle returned from AWavOpen
  467. // see WavSupportsVolume() for further description
  468. // return TRUE if supported
  469. //
  470. BOOL DLLEXPORT WINAPI AWavSupportsVolume(HAWAV hAWav, int idDev, int nLevel, DWORD dwFlags)
  471. {
  472. BOOL fSuccess = TRUE;
  473. LPAWAV lpAWav;
  474. int ihWav;
  475. BOOL fSupported = TRUE;
  476. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  477. fSuccess = TraceFALSE(NULL);
  478. // see if all elements support the specified volume
  479. //
  480. else for (ihWav = 0; fSuccess && ihWav < lpAWav->chWav; ++ihWav)
  481. {
  482. if (!WavSupportsVolume(*(lpAWav->lpahWav + ihWav), idDev, nLevel, dwFlags))
  483. {
  484. fSupported = FALSE;
  485. break;
  486. }
  487. }
  488. return fSuccess ? fSupported : FALSE;
  489. }
  490. // AWavGetSpeed - get current speed level
  491. // <hAWav> (i) handle returned from AWavOpen
  492. // see WavGetSpeed() for further description
  493. // return speed level (100 is normal, 50 is half, 200 is double, -1 if error)
  494. //
  495. int DLLEXPORT WINAPI AWavGetSpeed(HAWAV hAWav, int idDev, DWORD dwFlags)
  496. {
  497. BOOL fSuccess = TRUE;
  498. LPAWAV lpAWav;
  499. int nLevel;
  500. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  501. fSuccess = TraceFALSE(NULL);
  502. // get speed of current element
  503. //
  504. else if ((nLevel = WavGetSpeed(*(lpAWav->lpahWav + lpAWav->ihWav), idDev, dwFlags)) < 0)
  505. fSuccess = TraceFALSE(NULL);
  506. return fSuccess ? nLevel : -1;
  507. }
  508. // AWavSetSpeed - set current speed level
  509. // <hAWav> (i) handle returned from AWavOpen
  510. // see WavSetSpeed() for further description
  511. // return 0 if success
  512. //
  513. int DLLEXPORT WINAPI AWavSetSpeed(HAWAV hAWav, int idDev, int nLevel, DWORD dwFlags)
  514. {
  515. BOOL fSuccess = TRUE;
  516. LPAWAV lpAWav;
  517. int ihWav;
  518. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  519. fSuccess = TraceFALSE(NULL);
  520. // set speed for all elements
  521. //
  522. else for (ihWav = 0; fSuccess && ihWav < lpAWav->chWav; ++ihWav)
  523. {
  524. if (WavSetSpeed(*(lpAWav->lpahWav + ihWav), idDev, nLevel, dwFlags) != 0)
  525. fSuccess = TraceFALSE(NULL);
  526. }
  527. return fSuccess ? 0 : -1;
  528. }
  529. // AWavSupportsSpeed - check if audio can be played at specified speed
  530. // <hAWav> (i) handle returned from AWavOpen
  531. // see WavSupportsSpeed() for further description
  532. // return TRUE if supported
  533. //
  534. BOOL DLLEXPORT WINAPI AWavSupportsSpeed(HAWAV hAWav, int idDev, int nLevel, DWORD dwFlags)
  535. {
  536. BOOL fSuccess = TRUE;
  537. LPAWAV lpAWav;
  538. int ihWav;
  539. BOOL fSupported = TRUE;
  540. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  541. fSuccess = TraceFALSE(NULL);
  542. // see if all elements support the specified speed
  543. //
  544. else for (ihWav = 0; fSuccess && ihWav < lpAWav->chWav; ++ihWav)
  545. {
  546. if (!WavSupportsSpeed(*(lpAWav->lpahWav + ihWav), idDev, nLevel, dwFlags))
  547. {
  548. fSupported = FALSE;
  549. break;
  550. }
  551. }
  552. return fSuccess ? fSupported : FALSE;
  553. }
  554. // AWavGetChunks - get chunk count and size of current element in wav array
  555. // <hAWav> (i) handle returned from AWavOpen
  556. // see WavGetChunks() for further description
  557. // return 0 if success
  558. //
  559. int DLLEXPORT WINAPI AWavGetChunks(HAWAV hAWav,
  560. int FAR *lpcChunks, long FAR *lpmsChunkSize, BOOL fWavOut)
  561. {
  562. BOOL fSuccess = TRUE;
  563. LPAWAV lpAWav;
  564. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  565. fSuccess = TraceFALSE(NULL);
  566. // get chunk count and size of current element
  567. //
  568. else if (WavGetChunks(*(lpAWav->lpahWav + lpAWav->ihWav),
  569. lpcChunks, lpmsChunkSize, fWavOut) != 0)
  570. fSuccess = TraceFALSE(NULL);
  571. return fSuccess ? 0 : -1;
  572. }
  573. // AWavSetChunks - set chunk count and size of all elements in wav array
  574. // <hAWav> (i) handle returned from WavOpen
  575. // see WavSetChunks() for further description
  576. // return 0 if success
  577. //
  578. int DLLEXPORT WINAPI AWavSetChunks(HAWAV hAWav, int cChunks, long msChunkSize, BOOL fWavOut)
  579. {
  580. BOOL fSuccess = TRUE;
  581. LPAWAV lpAWav;
  582. int ihWav;
  583. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  584. fSuccess = TraceFALSE(NULL);
  585. // set chunk count and size for all elements
  586. //
  587. else for (ihWav = 0; fSuccess && ihWav < lpAWav->chWav; ++ihWav)
  588. {
  589. if (WavSetChunks(*(lpAWav->lpahWav + ihWav), cChunks, msChunkSize, fWavOut) != 0)
  590. fSuccess = TraceFALSE(NULL);
  591. }
  592. return fSuccess ? 0 : -1;
  593. }
  594. // AWavCopy - copy data from wav array to wav file
  595. // <hAWavSrc> (i) source handle returned from AWavOpen
  596. // see WavCopy() for further description
  597. // return 0 if success (-1 if error, +1 if user abort)
  598. //
  599. int DLLEXPORT WINAPI AWavCopy(HAWAV hAWavSrc, HWAV hWavDst,
  600. void _huge *hpBuf, long sizBuf, USERABORTPROC lpfnUserAbort, DWORD dwUser, DWORD dwFlags)
  601. {
  602. BOOL fSuccess = TRUE;
  603. LPAWAV lpAWav;
  604. int ihWav;
  605. int iRet = 0;
  606. if ((lpAWav = AWavGetPtr(hAWavSrc)) == NULL)
  607. fSuccess = TraceFALSE(NULL);
  608. // copy each source element to destination
  609. //
  610. else for (ihWav = 0; fSuccess && ihWav < lpAWav->chWav; ++ihWav)
  611. {
  612. if ((iRet = WavCopy(*(lpAWav->lpahWav + ihWav), hWavDst,
  613. hpBuf, sizBuf, lpfnUserAbort, dwUser, dwFlags)) == -1)
  614. fSuccess = TraceFALSE(NULL);
  615. else if (iRet == +1)
  616. break; // user abort
  617. }
  618. return fSuccess ? iRet : -1;
  619. }
  620. // AWavGetOutputDevice - get handle to open wav output device
  621. // <hAWav> (i) handle returned from AWavOpen
  622. // see WavGetOutputDevice() for further description
  623. // return handle to wav output device (NULL if device not open or error)
  624. //
  625. HWAVOUT DLLEXPORT WINAPI AWavGetOutputDevice(HAWAV hAWav)
  626. {
  627. BOOL fSuccess = TRUE;
  628. LPAWAV lpAWav;
  629. HWAVOUT hWavOut;
  630. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  631. fSuccess = TraceFALSE(NULL);
  632. // get device handle of current element
  633. //
  634. else if ((hWavOut = WavGetOutputDevice(*(lpAWav->lpahWav + lpAWav->ihWav))) == NULL)
  635. fSuccess = TraceFALSE(NULL);
  636. return fSuccess ? hWavOut : NULL;
  637. }
  638. // AWavGetInputDevice - get handle to open wav input device
  639. // <hAWav> (i) handle returned from AWavOpen
  640. // return handle to wav input device (NULL if device not open or error)
  641. //
  642. HWAVIN DLLEXPORT WINAPI AWavGetInputDevice(HAWAV hAWav)
  643. {
  644. BOOL fSuccess = TRUE;
  645. LPAWAV lpAWav;
  646. HWAVIN hWavIn;
  647. if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  648. fSuccess = TraceFALSE(NULL);
  649. // get device handle of current element
  650. //
  651. else if ((hWavIn = WavGetInputDevice(*(lpAWav->lpahWav + lpAWav->ihWav))) == NULL)
  652. fSuccess = TraceFALSE(NULL);
  653. return fSuccess ? hWavIn : NULL;
  654. }
  655. ////
  656. // helper functions
  657. ////
  658. // AWavGetPtr - verify that awav handle is valid,
  659. // <hAWav> (i) handle returned from AWavOpen
  660. // see WavGetInputDevice() for further description
  661. // return corresponding awav pointer (NULL if error)
  662. //
  663. static LPAWAV AWavGetPtr(HAWAV hAWav)
  664. {
  665. BOOL fSuccess = TRUE;
  666. LPAWAV lpAWav;
  667. if ((lpAWav = (LPAWAV) hAWav) == NULL)
  668. fSuccess = TraceFALSE(NULL);
  669. else if (IsBadWritePtr(lpAWav, sizeof(AWAV)))
  670. fSuccess = TraceFALSE(NULL);
  671. #ifdef CHECKTASK
  672. // make sure current task owns the awav handle
  673. //
  674. else if (lpAWav->hTask != GetCurrentTask())
  675. fSuccess = TraceFALSE(NULL);
  676. #endif
  677. return fSuccess ? lpAWav : NULL;
  678. }
  679. // AWavGetHandle - verify that awav pointer is valid,
  680. // <lpAWav> (i) pointer to AWAV struct
  681. // return corresponding awav handle (NULL if error)
  682. //
  683. static HAWAV AWavGetHandle(LPAWAV lpAWav)
  684. {
  685. BOOL fSuccess = TRUE;
  686. HAWAV hAWav;
  687. if ((hAWav = (HAWAV) lpAWav) == NULL)
  688. fSuccess = TraceFALSE(NULL);
  689. return fSuccess ? hAWav : NULL;
  690. }
  691. BOOL CALLBACK PlayStoppedProc(HWAV hWav, HANDLE hUser, DWORD dwReserved)
  692. {
  693. BOOL fSuccess = TRUE;
  694. BOOL bRet = TRUE;
  695. HAWAV hAWav;
  696. LPAWAV lpAWav;
  697. if ((hAWav = hUser) == NULL)
  698. fSuccess = TraceFALSE(NULL);
  699. else if ((lpAWav = AWavGetPtr(hAWav)) == NULL)
  700. fSuccess = TraceFALSE(NULL);
  701. else if (!lpAWav->fStopping && lpAWav->ihWav + 1 < lpAWav->chWav)
  702. {
  703. // start playback of next wav array element
  704. //
  705. if (WavPlayEx(*(lpAWav->lpahWav + (++lpAWav->ihWav)),
  706. lpAWav->idDev, PlayStoppedProc, hAWav,
  707. lpAWav->dwReserved, lpAWav->dwFlags) != 0)
  708. {
  709. fSuccess = TraceFALSE(NULL);
  710. }
  711. }
  712. else
  713. {
  714. // playback of entire array is complete; send notification
  715. //
  716. if (lpAWav->lpfnPlayStopped != NULL)
  717. (*lpAWav->lpfnPlayStopped)((HWAV) hAWav, lpAWav->hUserPlayStopped, 0);
  718. }
  719. return fSuccess ? bRet : FALSE;
  720. }