Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Demos / DX11ClothDemo / DXUT / Optional / SDKsound.h
1 //-----------------------------------------------------------------------------\r
2 // File: DXUTsound.h\r
3 //\r
4 // Copyright (c) Microsoft Corp. All rights reserved.\r
5 //-----------------------------------------------------------------------------\r
6 #ifndef DXUTSOUND_H\r
7 #define DXUTSOUND_H\r
8 \r
9 //-----------------------------------------------------------------------------\r
10 // Header Includes\r
11 //-----------------------------------------------------------------------------\r
12 #include <dsound.h>\r
13 #include <ks.h>\r
14 \r
15 //-----------------------------------------------------------------------------\r
16 // Classes used by this header\r
17 //-----------------------------------------------------------------------------\r
18 class CSoundManager;\r
19 class CSound;\r
20 class CStreamingSound;\r
21 class CWaveFile;\r
22 \r
23 \r
24 //-----------------------------------------------------------------------------\r
25 // Typing macros \r
26 //-----------------------------------------------------------------------------\r
27 #define DXUT_StopSound(s)         { if(s) s->Stop(); }\r
28 #define DXUT_PlaySound(s)         { if(s) s->Play( 0, 0 ); }\r
29 #define DXUT_PlaySoundLooping(s)  { if(s) s->Play( 0, DSBPLAY_LOOPING ); }\r
30 \r
31 \r
32 //-----------------------------------------------------------------------------\r
33 // Name: class CSoundManager\r
34 // Desc: \r
35 //-----------------------------------------------------------------------------\r
36 class CSoundManager\r
37 {\r
38 protected:\r
39     IDirectSound8* m_pDS;\r
40 \r
41 public:\r
42                             CSoundManager();\r
43                             ~CSoundManager();\r
44 \r
45     HRESULT                 Initialize( HWND hWnd, DWORD dwCoopLevel );\r
46     inline  LPDIRECTSOUND8  GetDirectSound()\r
47     {\r
48         return m_pDS;\r
49     }\r
50     HRESULT                 SetPrimaryBufferFormat( DWORD dwPrimaryChannels, DWORD dwPrimaryFreq,\r
51                                                     DWORD dwPrimaryBitRate );\r
52     HRESULT                 Get3DListenerInterface( LPDIRECTSOUND3DLISTENER* ppDSListener );\r
53 \r
54     HRESULT                 Create( CSound** ppSound, LPWSTR strWaveFileName, DWORD dwCreationFlags = 0,\r
55                                     GUID guid3DAlgorithm = GUID_NULL, DWORD dwNumBuffers = 1 );\r
56     HRESULT                 CreateFromMemory( CSound** ppSound, BYTE* pbData, ULONG ulDataSize, LPWAVEFORMATEX pwfx,\r
57                                               DWORD dwCreationFlags = 0, GUID guid3DAlgorithm = GUID_NULL,\r
58                                               DWORD dwNumBuffers = 1 );\r
59     HRESULT                 CreateStreaming( CStreamingSound** ppStreamingSound, LPWSTR strWaveFileName,\r
60                                              DWORD dwCreationFlags, GUID guid3DAlgorithm, DWORD dwNotifyCount,\r
61                                              DWORD dwNotifySize, HANDLE hNotifyEvent );\r
62 };\r
63 \r
64 \r
65 //-----------------------------------------------------------------------------\r
66 // Name: class CSound\r
67 // Desc: Encapsulates functionality of a DirectSound buffer.\r
68 //-----------------------------------------------------------------------------\r
69 class CSound\r
70 {\r
71 protected:\r
72     LPDIRECTSOUNDBUFFER* m_apDSBuffer;\r
73     DWORD m_dwDSBufferSize;\r
74     CWaveFile* m_pWaveFile;\r
75     DWORD m_dwNumBuffers;\r
76     DWORD m_dwCreationFlags;\r
77 \r
78     HRESULT             RestoreBuffer( LPDIRECTSOUNDBUFFER pDSB, BOOL* pbWasRestored );\r
79 \r
80 public:\r
81                         CSound( LPDIRECTSOUNDBUFFER* apDSBuffer, DWORD dwDSBufferSize, DWORD dwNumBuffers,\r
82                                 CWaveFile* pWaveFile, DWORD dwCreationFlags );\r
83     virtual             ~CSound();\r
84 \r
85     HRESULT             Get3DBufferInterface( DWORD dwIndex, LPDIRECTSOUND3DBUFFER* ppDS3DBuffer );\r
86     HRESULT             FillBufferWithSound( LPDIRECTSOUNDBUFFER pDSB, BOOL bRepeatWavIfBufferLarger );\r
87     LPDIRECTSOUNDBUFFER GetFreeBuffer();\r
88     LPDIRECTSOUNDBUFFER GetBuffer( DWORD dwIndex );\r
89 \r
90     HRESULT             Play( DWORD dwPriority = 0, DWORD dwFlags = 0, LONG lVolume = 0, LONG lFrequency = -1,\r
91                               LONG lPan = 0 );\r
92     HRESULT             Play3D( LPDS3DBUFFER p3DBuffer, DWORD dwPriority = 0, DWORD dwFlags = 0, LONG lFrequency = 0 );\r
93     HRESULT             Stop();\r
94     HRESULT             Reset();\r
95     BOOL                IsSoundPlaying();\r
96 };\r
97 \r
98 \r
99 //-----------------------------------------------------------------------------\r
100 // Name: class CStreamingSound\r
101 // Desc: Encapsulates functionality to play a wave file with DirectSound.  \r
102 //       The Create() method loads a chunk of wave file into the buffer, \r
103 //       and as sound plays more is written to the buffer by calling \r
104 //       HandleWaveStreamNotification() whenever hNotifyEvent is signaled.\r
105 //-----------------------------------------------------------------------------\r
106 class CStreamingSound : public CSound\r
107 {\r
108 protected:\r
109     DWORD m_dwLastPlayPos;\r
110     DWORD m_dwPlayProgress;\r
111     DWORD m_dwNotifySize;\r
112     DWORD m_dwNextWriteOffset;\r
113     BOOL m_bFillNextNotificationWithSilence;\r
114 \r
115 public:\r
116             CStreamingSound( LPDIRECTSOUNDBUFFER pDSBuffer, DWORD dwDSBufferSize, CWaveFile* pWaveFile,\r
117                              DWORD dwNotifySize );\r
118             ~CStreamingSound();\r
119 \r
120     HRESULT HandleWaveStreamNotification( BOOL bLoopedPlay );\r
121     HRESULT Reset();\r
122 };\r
123 \r
124 #endif // DXUTSOUND_H\r