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.

153 lines
2.3 KiB

  1. #include <windows.h>
  2. #include <mmsystem.h>
  3. #include "waveutil.h"
  4. void CopyFormat
  5. (
  6. LPWAVEFORMATEX pwfxDst,
  7. LPWAVEFORMATEX pwfxSrc
  8. )
  9. {
  10. DWORD cbSize;
  11. cbSize = SIZEOFFORMAT(pwfxSrc);
  12. CopyMemory(pwfxDst, pwfxSrc, cbSize);
  13. }
  14. void CopyFormatEx
  15. (
  16. LPWAVEFORMATEX pwfxDst,
  17. LPWAVEFORMATEX pwfxSrc
  18. )
  19. {
  20. DWORD cbSize;
  21. cbSize = SIZEOFFORMATEX(pwfxSrc);
  22. CopyMemory(pwfxDst, pwfxSrc, cbSize);
  23. if (WAVE_FORMAT_PCM == pwfxDst->wFormatTag)
  24. {
  25. pwfxDst->cbSize = 0;
  26. }
  27. }
  28. BOOL FormatCmp
  29. (
  30. LPWAVEFORMATEX pwfx1,
  31. LPWAVEFORMATEX pwfx2
  32. )
  33. {
  34. DWORD cbSize;
  35. cbSize = SIZEOFFORMAT(pwfx1);
  36. if (cbSize != SIZEOFFORMAT(pwfx2))
  37. {
  38. return (FALSE);
  39. }
  40. else
  41. {
  42. LPBYTE pb1 = (LPBYTE)pwfx1, pb2 = (LPBYTE)pwfx2;
  43. for (; cbSize; cbSize--)
  44. {
  45. if (pb1[cbSize - 1] != pb2[cbSize - 1])
  46. {
  47. return (FALSE);
  48. }
  49. }
  50. }
  51. return (TRUE);
  52. }
  53. DWORD DeinterleaveBuffers
  54. (
  55. LPWAVEFORMATEX pwfx,
  56. LPBYTE pSrc,
  57. LPBYTE *ppbDst,
  58. DWORD cBuffers,
  59. DWORD cbSrcLength,
  60. DWORD dwOffset
  61. )
  62. {
  63. DWORD ii;
  64. // Note: Right now, we don't deal with anything but PCM
  65. if (WAVE_FORMAT_PCM != pwfx->wFormatTag)
  66. {
  67. return (dwOffset);
  68. }
  69. if (1 == cBuffers)
  70. {
  71. LPBYTE pDst = ppbDst[0];
  72. pDst += dwOffset;
  73. CopyMemory(pDst, pSrc, cbSrcLength);
  74. dwOffset += cbSrcLength;
  75. return (dwOffset);
  76. }
  77. if (8 == pwfx->wBitsPerSample)
  78. {
  79. if ( !cBuffers || (0 != (cbSrcLength % cBuffers)) )
  80. {
  81. // Hmm... Buffer sizes don't line up!
  82. return (dwOffset);
  83. }
  84. for (; cbSrcLength; cbSrcLength -= cBuffers)
  85. {
  86. for (ii = 0; ii < cBuffers; ii++)
  87. {
  88. ppbDst[ii][dwOffset] = *pSrc++;
  89. }
  90. dwOffset++;
  91. }
  92. return (dwOffset);
  93. }
  94. else
  95. {
  96. PWORD *ppwDst = (PWORD*)ppbDst;
  97. PWORD pwSrc = (PWORD)pSrc;
  98. // Assuming 16-bit...
  99. if ( !cBuffers || (0 != (cbSrcLength % (cBuffers * 2))) || (0 != (dwOffset % sizeof(WORD))))
  100. {
  101. // Hmm... Buffer sizes don't line up!
  102. return (0);
  103. }
  104. // Convert byte index into word index
  105. //
  106. dwOffset /= sizeof(WORD);
  107. for (; cbSrcLength; cbSrcLength -= (2 * cBuffers))
  108. {
  109. for (ii = 0; ii < cBuffers; ii++)
  110. {
  111. ppwDst[ii][dwOffset] = *pwSrc++;
  112. }
  113. dwOffset++;
  114. }
  115. // Return byte index
  116. //
  117. dwOffset *= sizeof(WORD);
  118. return (dwOffset);
  119. }
  120. }