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.

147 lines
6.3 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dvsndt.h
  6. * Content: definition of CSoundTarget class
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 09/02/99 rodtoll Created
  12. * 09/08/99 rodtoll Updated to provide lockup detection
  13. * 09/14/99 rodtoll Added WriteAheadSilence()
  14. * 09/20/99 rodtoll Added handlers for buffer loss
  15. * 11/12/99 rodtoll Updated to use new abstractions for playback (allows use
  16. * of waveOut with this class).
  17. * 01/24/2000 rodtoll Fix: Bug #129427 - Destroying transport before calling Delete3DSound
  18. * 01/27/2000 rodtoll Bug #129934 - Update SoundTargets to take DSBUFFERDESC
  19. * 02/17/2000 rodtoll Bug #133691 - Choppy audio - queue was not adapting
  20. * Added instrumentation
  21. * 04/17/2000 rodtoll Fix: Bug #32215 - Session Lost after resuming from hibernation
  22. * 06/21/2000 rodtoll Fix: Bug #35767 - Must implement ability for dsound effects on voice buffers
  23. * Added new constructor/init that takes pre-built buffers
  24. * 07/09/2000 rodtoll Added signature bytes
  25. *
  26. ***************************************************************************/
  27. #ifndef __DVSNDT_H
  28. #define __DVSNDT_H
  29. // CSoundTarget
  30. //
  31. // This class represents a single mixer target within the DirectPlayClient system. Normally there
  32. // is only a single mixer target ("main") for all incoming audio. However, using the CreateUserBuffer and
  33. // DeleteUserBuffer APIs the developer can specify that they wish to seperate a group or a player
  34. // from the main mixer target. In this manner they can control the 3d spatialization of the group/player's
  35. // incoming audio stream.
  36. //
  37. // This class handles all the details related to a mixer target. It encapsulates the mixing of single
  38. // or multiple source audio frames and then commiting them to the corresponding directsound buffer. It also
  39. // handles timing errors in the directsoundbuffer.
  40. //
  41. // For example, if the directsoundbuffer stops running, it will attempt to reset the buffer.
  42. //
  43. // If the directsoundbuffer slows down (because of high CPU), it moves the read pointer forward. In short
  44. // it ensures that there is always 1 or 2 frames of mixed audio present in the buffer in advance of the
  45. // read pointer.
  46. //
  47. // In addition the class provides reference counting to prevent premature deletion of the class. If you
  48. // wish to take a reference to the class, call AddRef and you MUST then call Release when you are done.
  49. //
  50. // Do not destroy the object directly. When the last reference to the object is released the object will
  51. // destroy itself.
  52. //
  53. // This class is not multithread safe (except for AddRef and Release). Only one thread should be
  54. // accessing it.
  55. //
  56. #define VSIG_SOUNDTARGET 'TNSV'
  57. #define VSIG_SOUNDTARGET_FREE 'TNS_'
  58. volatile struct CSoundTarget
  59. {
  60. public:
  61. CSoundTarget( DVID dvidTarget, CAudioPlaybackDevice *lpads, LPDSBUFFERDESC lpdsBufferDesc, DWORD dwPriority, DWORD dwFlags, DWORD dwFrameSize );
  62. CSoundTarget( DVID dvidTarget, CAudioPlaybackDevice *lpads, CAudioPlaybackBuffer *lpdsBuffer, LPDSBUFFERDESC lpdsBufferDesc, DWORD dwPriority, DWORD dwFlags, DWORD dwFrameSize );
  63. CSoundTarget( DVID dvidTarget, CAudioPlaybackDevice *lpads, LPDIRECTSOUNDBUFFER lpdsBuffer, BOOL fEightBit, DWORD dwPriority, DWORD dwFlags, DWORD dwFrameSize );
  64. ~CSoundTarget();
  65. HRESULT StartMix();
  66. HRESULT MixInSingle( LPBYTE lpbBuffer );
  67. HRESULT MixIn( const BYTE* lpbBuffer );
  68. HRESULT Commit();
  69. inline HRESULT GetInitResult() const { return m_hrInitResult; };
  70. LPDIRECTSOUND3DBUFFER Get3DBuffer();
  71. inline CAudioPlaybackBuffer *GetBuffer() { return m_lpAudioPlaybackBuffer; };
  72. CSoundTarget *m_lpstNext; // Next entry in the list
  73. inline DVID GetTarget() const { return m_dvidTarget; };
  74. inline LONG GetRefCount() const { return m_lRefCount; };
  75. LONG AddRef();
  76. LONG Release();
  77. void GetStats( PlaybackStats *statPlayback );
  78. HRESULT GetCurrentLead( PDWORD pdwLead );
  79. protected:
  80. HRESULT Initialize( DVID dvidTarget, CAudioPlaybackBuffer *lpdsBuffer, BOOL fEightBit, DWORD dwPriority, DWORD dwFlags, DWORD dwFrameSize );
  81. HRESULT RestoreLostBuffer();
  82. HRESULT AdjustWritePtr();
  83. HRESULT WriteAheadSilence();
  84. void Stats_Init();
  85. void Stats_Begin();
  86. void Stats_End();
  87. public:
  88. DWORD m_dwSignature;
  89. protected:
  90. CAudioPlaybackBuffer *m_lpAudioPlaybackBuffer;
  91. LPDIRECTSOUND3DBUFFER m_lpds3dBuffer; // 3d buffer interface for this sound target
  92. DWORD m_dwNextWritePos; // Next byte position in the directsound buffer we'll
  93. // be writing to.
  94. DWORD m_dwBufferSize; // Size of directsound buffer in bytes
  95. BOOL m_bGroup; // Does this buffer represent a group?
  96. LPLONG m_lpMixBuffer; // High resolution mixing buffer
  97. BOOL m_bCommited; // Has the data in the latest mix been commited to the buffer
  98. BOOL m_fEightBit; // Is the buffer 8-bit?
  99. HRESULT m_hrInitResult; // Contains result of the initializatio of this object
  100. DWORD m_dwMixSize; // # of samples per frame
  101. DWORD m_dwFrameSize; // Size of a frame in bytes
  102. BOOL m_fMixed; // Set to TRUE as soon as a single source has been mixed
  103. // Set to FALSE whenever the mix is commited.
  104. LONG m_lRefCount; // Reference count on the object
  105. DWORD m_dwLastWritePos; // Byte position that the last write occured at.
  106. DWORD m_dwNumResets; // # of times buffer has been reset
  107. BOOL m_fLastFramePushed; // Did the last frame push the read pointer forward?
  108. DWORD m_dwNumSinceMove; // How many frames since no movement was detected?
  109. DWORD m_dwLastWriteTime; // GetTickCount() at last call to AdjustWritePtr
  110. BOOL m_fIgnoreFrame; // This frame will cross the boundary of where the write pointer is.
  111. // Do NOT write to the buffer
  112. DWORD m_dwWritePos;
  113. DNCRITICAL_SECTION m_csGuard; // Guard for reference counts
  114. DWORD m_dwPlayFlags;
  115. DWORD m_dwPriority;
  116. DVID m_dvidTarget; // DVID this buffer is for.
  117. // DVID_REMAINING for the global one
  118. PlaybackStats m_statPlay; // Playback Statistics
  119. LPVOID m_lpDummy;
  120. };
  121. #endif