source: branches/gcc-kmk/src/dsound/os2notify.cpp@ 21692

Last change on this file since 21692 was 21692, checked in by dmik, 14 years ago

Normalize file case.

Change all uppercase filenames and extensions to lowercase (except well known cases like LICENSE.TXT and so on).

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