1 | /*
|
---|
2 | * DirectSound DirectSoundNotify class
|
---|
3 | *
|
---|
4 | * Copyright 2000 Michal Necasek
|
---|
5 | *
|
---|
6 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
7 | *
|
---|
8 | */
|
---|
9 |
|
---|
10 |
|
---|
11 | /*@Header***********************************************************************
|
---|
12 | * Header Files *
|
---|
13 | *******************************************************************************/
|
---|
14 | #define INCL_DOSMISC
|
---|
15 | #include <os2win.h>
|
---|
16 |
|
---|
17 | #include <stdlib.h>
|
---|
18 | #include <string.h>
|
---|
19 |
|
---|
20 | #define INITGUID
|
---|
21 | #include <dsound.h>
|
---|
22 |
|
---|
23 | #include "os2dsound.h"
|
---|
24 | #include "os2sndbuffer.h"
|
---|
25 | #include "os2notify.h"
|
---|
26 | #include <misc.h>
|
---|
27 |
|
---|
28 | //******************************************************************************
|
---|
29 | //******************************************************************************
|
---|
30 | OS2IDirectSoundNotify::OS2IDirectSoundNotify(OS2IDirectSoundBuffer *parentBuffer)
|
---|
31 | {
|
---|
32 | lpVtbl = &Vtbl;
|
---|
33 | Vtbl.AddRef = SoundNotifyAddRef;
|
---|
34 | Vtbl.Release = SoundNotifyRelease;
|
---|
35 | Vtbl.QueryInterface = SoundNotifyQueryInterface;
|
---|
36 | Vtbl.SetNotificationPositions = SoundNotifySetNotificationPositions;
|
---|
37 |
|
---|
38 | dprintf(("DSOUND-OS2IDirectSoundNotify::OS2IDirectSoundNotify (this=%X)", this));
|
---|
39 |
|
---|
40 | lpSoundBuffer = parentBuffer;
|
---|
41 | lpPositions = NULL;
|
---|
42 | cPositions = 0;
|
---|
43 | Referenced = 0;
|
---|
44 |
|
---|
45 | // add a reference to the parent SoundBuffer to make sure it won't suddenly disappear
|
---|
46 | lpSoundBuffer->Vtbl.AddRef(lpSoundBuffer);
|
---|
47 | // set pointer to ourselves in parent SoundBuffer
|
---|
48 | lpSoundBuffer->SetNotify(this);
|
---|
49 | }
|
---|
50 |
|
---|
51 | //******************************************************************************
|
---|
52 | //******************************************************************************
|
---|
53 | OS2IDirectSoundNotify::~OS2IDirectSoundNotify()
|
---|
54 | {
|
---|
55 | dprintf(("DSOUND-OS2IDirectSoundNotify::~OS2IDirectSoundNotify (this=%X)", this));
|
---|
56 | lpSoundBuffer->SetNotify(NULL);
|
---|
57 | lpSoundBuffer->Vtbl.Release(lpSoundBuffer);
|
---|
58 | if (lpPositions != NULL)
|
---|
59 | free(lpPositions);
|
---|
60 | }
|
---|
61 |
|
---|
62 | //******************************************************************************
|
---|
63 | //******************************************************************************
|
---|
64 | HRESULT __stdcall SoundNotifyQueryInterface(THIS, REFIID riid, LPVOID * ppvObj)
|
---|
65 | {
|
---|
66 | dprintf(("DSOUND-OS2IDirectSoundNotify::QueryInterface"));
|
---|
67 | if (This == NULL) {
|
---|
68 | return DSERR_INVALIDPARAM;
|
---|
69 | }
|
---|
70 | *ppvObj = NULL;
|
---|
71 |
|
---|
72 | if (!IsEqualGUID(riid, IID_IDirectSoundNotify))
|
---|
73 | return E_NOINTERFACE;
|
---|
74 |
|
---|
75 | *ppvObj = This;
|
---|
76 |
|
---|
77 | SoundNotifyAddRef(This);
|
---|
78 | return DS_OK;
|
---|
79 | }
|
---|
80 |
|
---|
81 | //******************************************************************************
|
---|
82 | //******************************************************************************
|
---|
83 | ULONG __stdcall SoundNotifyAddRef(THIS)
|
---|
84 | {
|
---|
85 | OS2IDirectSoundNotify *me = (OS2IDirectSoundNotify *)This;
|
---|
86 |
|
---|
87 | dprintf(("DSOUND-OS2IDirectSoundNotify::AddRef (this=%X) %d", me, me->Referenced+1));
|
---|
88 | if (me == NULL) {
|
---|
89 | return 0;
|
---|
90 | }
|
---|
91 | return ++me->Referenced;
|
---|
92 | }
|
---|
93 |
|
---|
94 | //******************************************************************************
|
---|
95 | //******************************************************************************
|
---|
96 | ULONG __stdcall SoundNotifyRelease(THIS)
|
---|
97 | {
|
---|
98 | OS2IDirectSoundNotify *me = (OS2IDirectSoundNotify *)This;
|
---|
99 |
|
---|
100 | dprintf(("DSOUND-OS2IDirectSoundNotify::Release (this=%X) %d", me, me->Referenced-1));
|
---|
101 | if (me == NULL) {
|
---|
102 | return 0;
|
---|
103 | }
|
---|
104 | if (me->Referenced) {
|
---|
105 | me->Referenced--;
|
---|
106 | if (me->Referenced == 0) {
|
---|
107 | delete me;
|
---|
108 | return DS_OK;
|
---|
109 | }
|
---|
110 | else
|
---|
111 | return me->Referenced;
|
---|
112 | }
|
---|
113 | else
|
---|
114 | return DS_OK;
|
---|
115 | }
|
---|
116 |
|
---|
117 | //******************************************************************************
|
---|
118 | //******************************************************************************
|
---|
119 | HRESULT __stdcall SoundNotifySetNotificationPositions(THIS, DWORD cPositionNotifies,
|
---|
120 | LPCDSBPOSITIONNOTIFY lpcPositionNotifies)
|
---|
121 | {
|
---|
122 | OS2IDirectSoundNotify *me = (OS2IDirectSoundNotify *)This;
|
---|
123 |
|
---|
124 | dprintf(("DSOUND-OS2IDirectSoundNotify::SoundNotifySetPositions (%d, this=%X)", cPositionNotifies, me));
|
---|
125 | if (me == NULL || lpcPositionNotifies == NULL) {
|
---|
126 | return DSERR_INVALIDPARAM;
|
---|
127 | }
|
---|
128 |
|
---|
129 | // we have to copy the notifications array to our own memory here; if any notifications
|
---|
130 | // were registered previously, discard them
|
---|
131 | me->cPositions = cPositionNotifies;
|
---|
132 | if (me->lpPositions != NULL)
|
---|
133 | free(me->lpPositions);
|
---|
134 | me->lpPositions = (LPDSBPOSITIONNOTIFY)malloc(cPositionNotifies * sizeof(DSBPOSITIONNOTIFY));
|
---|
135 | for (int i = 0; i < cPositionNotifies; i++) {
|
---|
136 | me->lpPositions[i].dwOffset = lpcPositionNotifies[i].dwOffset;
|
---|
137 | me->lpPositions[i].hEventNotify = lpcPositionNotifies[i].hEventNotify;
|
---|
138 | }
|
---|
139 |
|
---|
140 | return DS_OK;
|
---|
141 | }
|
---|
142 |
|
---|
143 | //******************************************************************************
|
---|
144 | //******************************************************************************
|
---|
145 | void OS2IDirectSoundNotify::CheckPos(DWORD dwOldpos, DWORD dwNewpos)
|
---|
146 | {
|
---|
147 | //dprintf(("DSOUND-OS2IDirectSoundNotify::CheckPos (%d, %d) (this=%X)", dwOldpos, dwNewpos, this));
|
---|
148 | // loop thru all registered notifications and check if any offset was reached
|
---|
149 | DWORD i;
|
---|
150 |
|
---|
151 | for (i = 0; i < cPositions; i++) {
|
---|
152 | // we do NOT handle the stop notification here
|
---|
153 | if (lpPositions[i].dwOffset == DSBPN_OFFSETSTOP)
|
---|
154 | continue;
|
---|
155 |
|
---|
156 | if (dwOldpos < dwNewpos) { // did we just wrap?
|
---|
157 | if ((lpPositions[i].dwOffset >= dwOldpos) && (lpPositions[i].dwOffset < dwNewpos))
|
---|
158 | SetEvent(lpPositions[i].hEventNotify);
|
---|
159 | } else { // yes we wrapped
|
---|
160 | if ((lpPositions[i].dwOffset >= dwOldpos) || (lpPositions[i].dwOffset < dwNewpos))
|
---|
161 | SetEvent(lpPositions[i].hEventNotify);
|
---|
162 | }
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | //******************************************************************************
|
---|
167 | //******************************************************************************
|
---|
168 | void OS2IDirectSoundNotify::CheckStop()
|
---|
169 | {
|
---|
170 | //dprintf(("DSOUND-OS2IDirectSoundNotify::CheckStop (this=%X)", this));
|
---|
171 | // just loop thru all notifications and check if DSBPN_OFFSETSTOP is there
|
---|
172 | DWORD i;
|
---|
173 |
|
---|
174 | for (i = 0; i < cPositions; i++) {
|
---|
175 | if (lpPositions[i].dwOffset == DSBPN_OFFSETSTOP)
|
---|
176 | SetEvent(lpPositions[i].hEventNotify);
|
---|
177 | }
|
---|
178 | }
|
---|