ReactOS 0.4.16-dev-306-g647d351
playsound.c File Reference
#include "winemm.h"
#include <winternl.h>
Include dependency graph for playsound.c:

Go to the source code of this file.

Classes

struct  tagWINE_PLAYSOUND
 
struct  playsound_data
 

Typedefs

typedef struct tagWINE_PLAYSOUND WINE_PLAYSOUND
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (winmm)
 
static HMMIO get_mmioFromFile (LPCWSTR lpszName)
 
static HMMIO get_mmioFromProfile (UINT uFlags, LPCWSTR lpszName)
 
static HMMIO PlaySound_GetMMIO (LPCWSTR pszSound, HMODULE hMod, DWORD fdwSound)
 
static void CALLBACK PlaySound_Callback (HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
 
static void PlaySound_WaitDone (struct playsound_data *s)
 
static BOOL PlaySound_IsString (DWORD fdwSound, const void *psz)
 
static void PlaySound_Free (WINE_PLAYSOUND *wps)
 
static WINE_PLAYSOUNDPlaySound_AllocAndGetMMIO (const void *pszSound, HMODULE hmod, DWORD fdwSound, BOOL bUnicode)
 
static BOOL proc_PlaySound (WINE_PLAYSOUND *wps)
 
static DWORD WINAPI PlaySoundAsyncThreadProc (LPVOID lpParameter)
 
static BOOL proc_PlaySoundAsync (WINE_PLAYSOUND *wps)
 
static BOOL MULTIMEDIA_PlaySound (const void *pszSound, HMODULE hmod, DWORD fdwSound, BOOL bUnicode)
 
BOOL WINAPI PlaySoundA (LPCSTR pszSoundA, HMODULE hmod, DWORD fdwSound)
 
BOOL WINAPI PlaySoundW (LPCWSTR pszSoundW, HMODULE hmod, DWORD fdwSound)
 
BOOL WINAPI sndPlaySoundA (LPCSTR pszSoundA, UINT uFlags)
 
BOOL WINAPI sndPlaySoundW (LPCWSTR pszSound, UINT uFlags)
 
UINT WINAPI mmsystemGetVersion (void)
 

Variables

static WINE_PLAYSOUNDPlaySoundCurrent
 
static BOOL bPlaySoundStop
 

Typedef Documentation

◆ WINE_PLAYSOUND

Function Documentation

◆ get_mmioFromFile()

static HMMIO get_mmioFromFile ( LPCWSTR  lpszName)
static

Definition at line 42 of file playsound.c.

43{
44 HMMIO ret;
45 WCHAR buf[256];
47
48 ret = mmioOpenW((LPWSTR)lpszName, NULL,
50 if (ret != 0) return ret;
51 if (SearchPathW(NULL, lpszName, L".wav", ARRAY_SIZE(buf), buf, &dummy))
52 {
53 return mmioOpenW(buf, NULL,
55 }
56 return 0;
57}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define NULL
Definition: types.h:112
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1298
HMMIO WINAPI mmioOpenW(LPWSTR szFileName, MMIOINFO *lpmmioinfo, DWORD dwOpenFlags)
Definition: mmio.c:670
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define MMIO_ALLOCBUF
Definition: mmsystem.h:532
#define MMIO_DENYWRITE
Definition: mmsystem.h:540
#define MMIO_READ
Definition: mmsystem.h:535
#define L(x)
Definition: ntvdm.h:50
int ret
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by PlaySound_GetMMIO().

◆ get_mmioFromProfile()

static HMMIO get_mmioFromProfile ( UINT  uFlags,
LPCWSTR  lpszName 
)
static

Definition at line 59 of file playsound.c.

60{
61 WCHAR str[128];
62 LPWSTR ptr, pszSnd;
63 HMMIO hmmio;
64 HKEY hUserKey, hRegSnd, hRegApp, hScheme, hSnd;
66 BOOL bIsDefault;
67
68 TRACE("searching in SystemSound list for %s\n", debugstr_w(lpszName));
69
70 bIsDefault = (_wcsicmp(lpszName, L"SystemDefault") == 0);
71
72 GetProfileStringW(L"Sounds",
73 bIsDefault ? L"Default" : lpszName,
74 L"",
75 str,
77 if (!*str)
78 goto Next;
79
80 for (ptr = str; *ptr && *ptr != L','; ptr++);
81
82 if (*ptr)
84
86 if (hmmio)
87 return hmmio;
88
89Next:
90 /* we look up the registry under
91 * HKCU\AppEvents\Schemes\Apps\.Default
92 * HKCU\AppEvents\Schemes\Apps<AppName>
93 */
94 err = RegOpenCurrentUser(KEY_READ, &hUserKey);
95 if (err == ERROR_SUCCESS)
96 {
97 err = RegOpenKeyW(hUserKey, L"AppEvents\\Schemes\\Apps", &hRegSnd);
98 RegCloseKey(hUserKey);
99 }
100
101 if (err != ERROR_SUCCESS)
102 goto None;
103
105 {
106 DWORD len;
107
108 err = ERROR_FILE_NOT_FOUND; /* error */
110 if (len > 0 && len < ARRAY_SIZE(str))
111 {
112 for (ptr = str + lstrlenW(str) - 1; ptr >= str; ptr--)
113 {
114 if (*ptr == L'.')
115 *ptr = UNICODE_NULL;
116
117 if (*ptr == L'\\')
118 {
119 err = RegOpenKeyW(hRegSnd, ptr + 1, &hRegApp);
120 break;
121 }
122 }
123 }
124 }
125 else
126 {
127 err = RegOpenKeyW(hRegSnd, L".Default", &hRegApp);
128 }
129
130 RegCloseKey(hRegSnd);
131
132 if (err != ERROR_SUCCESS)
133 goto None;
134
135 err = RegOpenKeyW(hRegApp,
136 bIsDefault ? L".Default" : lpszName,
137 &hScheme);
138
139 RegCloseKey(hRegApp);
140
141 if (err != ERROR_SUCCESS)
142 goto None;
143
144 err = RegOpenKeyW(hScheme, L".Current", &hSnd);
145
146 RegCloseKey(hScheme);
147
148 if (err != ERROR_SUCCESS)
149 goto None;
150
151 count = sizeof(str);
152 err = RegQueryValueExW(hSnd, NULL, 0, &type, (LPBYTE)str, &count);
153
154 RegCloseKey(hSnd);
155
156 if (err != ERROR_SUCCESS || !*str)
157 goto None;
158
159 if (type == REG_EXPAND_SZ)
160 {
162 if (count == 0)
163 goto None;
164
165 pszSnd = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
166 if (!pszSnd)
167 goto None;
168
169 if (ExpandEnvironmentStringsW(str, pszSnd, count) == 0)
170 {
171 HeapFree(GetProcessHeap(), 0, pszSnd);
172 goto None;
173 }
174 }
175 else if (type == REG_SZ)
176 {
177 /* The type is REG_SZ, no need to expand */
178 pszSnd = str;
179 }
180 else
181 {
182 /* Invalid type */
183 goto None;
184 }
185
187
188 if (type == REG_EXPAND_SZ)
189 HeapFree(GetProcessHeap(), 0, pszSnd);
190
191 if (hmmio)
192 return hmmio;
193
194None:
195 WARN("can't find SystemSound=%s !\n", debugstr_w(lpszName));
196 return NULL;
197}
@ None
Definition: install.h:14
#define WARN(fmt,...)
Definition: precomp.h:61
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenCurrentUser(IN REGSAM samDesired, OUT PHKEY phkResult)
Definition: reg.c:3209
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3268
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
UINT uFlags
Definition: api.c:59
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define lstrlenW
Definition: compat.h:750
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
INT WINAPI GetProfileStringW(LPCWSTR section, LPCWSTR entry, LPCWSTR def_val, LPWSTR buffer, UINT len)
Definition: profile.c:1267
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLsizei len
Definition: glext.h:6722
#define debugstr_w
Definition: kernel32.h:32
#define REG_SZ
Definition: layer.c:22
#define SND_APPLICATION
Definition: mmsystem.h:165
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static PVOID ptr
Definition: dispmode.c:27
#define KEY_READ
Definition: nt_native.h:1023
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define UNICODE_NULL
#define err(...)
const WCHAR * str
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define TRACE(s)
Definition: solgame.cpp:4
unsigned char * LPBYTE
Definition: typedefs.h:53

Referenced by PlaySound_GetMMIO().

◆ mmsystemGetVersion()

UINT WINAPI mmsystemGetVersion ( void  )

Definition at line 679 of file playsound.c.

680{
681 TRACE("3.10 (Win95?)\n");
682 return 0x030a;
683}

◆ MULTIMEDIA_PlaySound()

static BOOL MULTIMEDIA_PlaySound ( const void pszSound,
HMODULE  hmod,
DWORD  fdwSound,
BOOL  bUnicode 
)
static

Definition at line 589 of file playsound.c.

590{
591 WINE_PLAYSOUND* wps = NULL;
592
593 TRACE("pszSound='%p' hmod=%p fdwSound=%08X\n",
594 pszSound, hmod, fdwSound);
595
596 /* SND_NOWAIT is ignored in w95/2k/xp. */
597 if ((fdwSound & SND_NOSTOP) && PlaySoundCurrent != NULL)
598 return FALSE;
599
600 /* alloc internal structure, if we need to play something */
601 if (pszSound && !(fdwSound & SND_PURGE))
602 {
603 if (!(wps = PlaySound_AllocAndGetMMIO(pszSound, hmod, fdwSound, bUnicode)))
604 return FALSE;
605 }
606
608 /* since several threads can enter PlaySound in parallel, we're not
609 * sure, at this point, that another thread didn't start a new playsound
610 */
611 while (PlaySoundCurrent != NULL)
612 {
614 /* FIXME: doc says we have to stop all instances of pszSound if it's non
615 * NULL... as of today, we stop all playing instances */
619
623
625 }
626
627 PlaySoundCurrent = wps;
629
630 if (!wps) return TRUE;
631
632 if (fdwSound & SND_ASYNC)
633 {
634 wps->bLoop = (fdwSound & SND_LOOP) ? TRUE : FALSE;
635
636 return proc_PlaySoundAsync(wps);
637 }
638
639 return proc_PlaySound(wps);
640}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define INFINITE
Definition: serial.h:102
#define SND_PURGE
Definition: mmsystem.h:164
#define SND_LOOP
Definition: mmsystem.h:157
#define SND_ASYNC
Definition: mmsystem.h:154
#define SND_NOSTOP
Definition: mmsystem.h:158
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:143
static WINE_PLAYSOUND * PlaySoundCurrent
Definition: playsound.c:39
static BOOL proc_PlaySound(WINE_PLAYSOUND *wps)
Definition: playsound.c:423
static WINE_PLAYSOUND * PlaySound_AllocAndGetMMIO(const void *pszSound, HMODULE hmod, DWORD fdwSound, BOOL bUnicode)
Definition: playsound.c:382
static BOOL bPlaySoundStop
Definition: playsound.c:40
static BOOL proc_PlaySoundAsync(WINE_PLAYSOUND *wps)
Definition: playsound.c:571
unsigned bLoop
Definition: playsound.c:34
HWAVEOUT hWave
Definition: playsound.c:36
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:714
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
HANDLE psLastEvent
Definition: winmm.c:51
CRITICAL_SECTION WINMM_cs
Definition: winmm.c:53
UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
Definition: winmm.c:2385

Referenced by PlaySoundA(), PlaySoundW(), sndPlaySoundA(), and sndPlaySoundW().

◆ PlaySound_AllocAndGetMMIO()

static WINE_PLAYSOUND * PlaySound_AllocAndGetMMIO ( const void pszSound,
HMODULE  hmod,
DWORD  fdwSound,
BOOL  bUnicode 
)
static

Definition at line 382 of file playsound.c.

384{
385 BOOL bIsString;
386 LPCWSTR pszSoundW;
387 UNICODE_STRING usBuffer;
388 WINE_PLAYSOUND* wps;
389
390 bIsString = PlaySound_IsString(fdwSound, pszSound);
391
392 if (bIsString && !bUnicode)
393 {
394 RtlCreateUnicodeStringFromAsciiz(&usBuffer, pszSound);
395 if (!usBuffer.Buffer)
396 return NULL;
397
398 pszSoundW = usBuffer.Buffer;
399 }
400 else
401 {
402 pszSoundW = pszSound;
403 }
404
405 wps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wps));
406 if (wps)
407 {
408 /* construct an MMIO stream (either in memory, or from a file) */
409 wps->hmmio = PlaySound_GetMMIO(pszSoundW, hmod, fdwSound);
410 if (!wps->hmmio)
411 {
412 PlaySound_Free(wps);
413 wps = NULL;
414 }
415 }
416
417 if (bIsString && !bUnicode)
418 RtlFreeUnicodeString(&usBuffer);
419
420 return wps;
421}
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
static void PlaySound_Free(WINE_PLAYSOUND *wps)
Definition: playsound.c:372
static HMMIO PlaySound_GetMMIO(LPCWSTR pszSound, HMODULE hMod, DWORD fdwSound)
Definition: playsound.c:199
static BOOL PlaySound_IsString(DWORD fdwSound, const void *psz)
Definition: playsound.c:347
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by MULTIMEDIA_PlaySound().

◆ PlaySound_Callback()

static void CALLBACK PlaySound_Callback ( HWAVEOUT  hwo,
UINT  uMsg,
DWORD_PTR  dwInstance,
DWORD_PTR  dwParam1,
DWORD_PTR  dwParam2 
)
static

Definition at line 317 of file playsound.c.

320{
321 struct playsound_data* s = (struct playsound_data*)dwInstance;
322
323 switch (uMsg) {
324 case WOM_OPEN:
325 case WOM_CLOSE:
326 break;
327 case WOM_DONE:
328 InterlockedIncrement(&s->dwEventCount);
329 TRACE("Returning waveHdr=%lx\n", dwParam1);
330 SetEvent(s->hEvent);
331 break;
332 default:
333 ERR("Unknown uMsg=%d\n", uMsg);
334 }
335}
#define InterlockedIncrement
Definition: armddk.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
GLdouble s
Definition: gl.h:2039
#define WOM_DONE
Definition: mmsystem.h:183
#define WOM_OPEN
Definition: mmsystem.h:181
#define WOM_CLOSE
Definition: mmsystem.h:182
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733

Referenced by proc_PlaySound().

◆ PlaySound_Free()

static void PlaySound_Free ( WINE_PLAYSOUND wps)
static

Definition at line 372 of file playsound.c.

373{
378 if (wps->hmmio) mmioClose(wps->hmmio, 0);
379 HeapFree(GetProcessHeap(), 0, wps);
380}
MMRESULT WINAPI mmioClose(HMMIO hmmio, UINT uFlags)
Definition: mmio.c:702

Referenced by PlaySound_AllocAndGetMMIO(), proc_PlaySound(), and proc_PlaySoundAsync().

◆ PlaySound_GetMMIO()

static HMMIO PlaySound_GetMMIO ( LPCWSTR  pszSound,
HMODULE  hMod,
DWORD  fdwSound 
)
static

Definition at line 199 of file playsound.c.

200{
201 BOOL bIsDefault = FALSE;
202 HMMIO hmmio = NULL;
203
204 TRACE("SoundName=%s !\n", debugstr_w(pszSound));
205
206 if (fdwSound & SND_MEMORY)
207 {
208 PVOID data;
209 MMIOINFO mminfo;
210
211 /* NOTE: SND_RESOURCE has the SND_MEMORY bit set */
212 if ((fdwSound & SND_RESOURCE) == SND_RESOURCE)
213 {
214 HRSRC hRes;
215 HGLOBAL hGlob;
216
217 hRes = FindResourceW(hMod, pszSound, L"WAVE");
218 hGlob = LoadResource(hMod, hRes);
219 if (!hRes || !hGlob)
220 goto Quit;
221
222 data = LockResource(hGlob);
223 FreeResource(hGlob);
224 if (!data)
225 goto Quit;
226 }
227 else
228 {
229 data = (PVOID)pszSound;
230 }
231
232 ZeroMemory(&mminfo, sizeof(mminfo));
233 mminfo.fccIOProc = FOURCC_MEM;
234 mminfo.pchBuffer = data;
235 mminfo.cchBuffer = -1; /* FIXME: when a resource, could grab real size */
236
237 TRACE("Memory sound %p\n", data);
238
239 hmmio = mmioOpenW(NULL, &mminfo, MMIO_READ);
240 }
241 else if (fdwSound & SND_ALIAS)
242 {
243 LPCWSTR pszName;
244
245 /* NOTE: SND_ALIAS_ID has the SND_ALIAS bit set */
246 if ((fdwSound & SND_ALIAS_ID) == SND_ALIAS_ID)
247 {
248 if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMASTERISK)
249 pszName = L"SystemAsterisk";
250 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMDEFAULT)
251 pszName = L"SystemDefault";
252 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMEXCLAMATION)
253 pszName = L"SystemExclamation";
254 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMEXIT)
255 pszName = L"SystemExit";
256 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMHAND)
257 pszName = L"SystemHand";
258 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMQUESTION)
259 pszName = L"SystemQuestion";
260 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMSTART)
261 pszName = L"SystemStart";
262 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMWELCOME)
263 pszName = L"SystemWelcome";
264 else
265 goto Quit;
266 }
267 else
268 {
269 pszName = pszSound;
270 }
271
272 bIsDefault = (_wcsicmp(pszName, L"SystemDefault") == 0);
273 hmmio = get_mmioFromProfile(fdwSound, pszName);
274 }
275 else if (fdwSound & SND_FILENAME)
276 {
277 hmmio = get_mmioFromFile(pszSound);
278 }
279 else
280 {
281 hmmio = get_mmioFromProfile(fdwSound, pszSound);
282 if (!hmmio)
283 hmmio = get_mmioFromFile(pszSound);
284 }
285
286Quit:
287 if (!hmmio && !(fdwSound & SND_NODEFAULT))
288 {
289 if (fdwSound & SND_APPLICATION)
290 {
291 if (!bIsDefault)
292 {
293 /* Find application-defined default sound */
294 hmmio = get_mmioFromProfile(fdwSound, L"SystemDefault");
295 if (hmmio)
296 return hmmio;
297 }
298
299 /* Find system default sound */
300 hmmio = get_mmioFromProfile(fdwSound & ~SND_APPLICATION, L"SystemDefault");
301 }
302 else if (!bIsDefault)
303 {
304 hmmio = get_mmioFromProfile(fdwSound, L"SystemDefault");
305 }
306 }
307
308 return hmmio;
309}
BOOL WINAPI FreeResource(HGLOBAL handle)
Definition: res.c:559
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define SND_ALIAS_SYSTEMEXCLAMATION
Definition: mmsystem.h:174
#define SND_ALIAS_SYSTEMSTART
Definition: mmsystem.h:172
#define SND_ALIAS_SYSTEMDEFAULT
Definition: mmsystem.h:175
#define SND_ALIAS_SYSTEMHAND
Definition: mmsystem.h:170
#define SND_ALIAS_SYSTEMEXIT
Definition: mmsystem.h:171
#define SND_RESOURCE
Definition: mmsystem.h:163
#define SND_ALIAS_SYSTEMWELCOME
Definition: mmsystem.h:173
#define SND_FILENAME
Definition: mmsystem.h:162
#define FOURCC_MEM
Definition: mmsystem.h:567
#define SND_ALIAS_ID
Definition: mmsystem.h:161
#define SND_MEMORY
Definition: mmsystem.h:156
#define SND_ALIAS
Definition: mmsystem.h:160
#define SND_ALIAS_SYSTEMQUESTION
Definition: mmsystem.h:169
#define SND_NODEFAULT
Definition: mmsystem.h:155
#define SND_ALIAS_SYSTEMASTERISK
Definition: mmsystem.h:168
static HMMIO get_mmioFromFile(LPCWSTR lpszName)
Definition: playsound.c:42
static HMMIO get_mmioFromProfile(UINT uFlags, LPCWSTR lpszName)
Definition: playsound.c:59
LONG cchBuffer
Definition: mmsystem.h:1491
HPSTR pchBuffer
Definition: mmsystem.h:1492
FOURCC fccIOProc
Definition: mmsystem.h:1487
void * PVOID
Definition: typedefs.h:50
#define ZeroMemory
Definition: winbase.h:1737

Referenced by PlaySound_AllocAndGetMMIO().

◆ PlaySound_IsString()

static BOOL PlaySound_IsString ( DWORD  fdwSound,
const void psz 
)
static

Definition at line 347 of file playsound.c.

348{
349 /* SND_RESOURCE is 0x40004 while
350 * SND_MEMORY is 0x00004
351 */
352 switch (fdwSound & (SND_RESOURCE | SND_ALIAS_ID | SND_FILENAME))
353 {
354 case SND_RESOURCE:
355 return HIWORD(psz) != 0; /* by name or by ID ? */
356
357 case SND_ALIAS_ID:
358 case SND_MEMORY:
359 return FALSE;
360
361 case SND_ALIAS:
362 case SND_FILENAME:
363 case 0:
364 return TRUE;
365
366 default:
367 FIXME("WTF\n");
368 return FALSE;
369 }
370}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define HIWORD(l)
Definition: typedefs.h:247

Referenced by PlaySound_AllocAndGetMMIO().

◆ PlaySound_WaitDone()

static void PlaySound_WaitDone ( struct playsound_data s)
static

Definition at line 337 of file playsound.c.

338{
339 for (;;) {
340 if (InterlockedDecrement(&s->dwEventCount) >= 0) break;
341 InterlockedIncrement(&s->dwEventCount);
342
344 }
345}
#define InterlockedDecrement
Definition: armddk.h:52

Referenced by proc_PlaySound().

◆ PlaySoundA()

BOOL WINAPI PlaySoundA ( LPCSTR  pszSoundA,
HMODULE  hmod,
DWORD  fdwSound 
)

Definition at line 645 of file playsound.c.

646{
647 return MULTIMEDIA_PlaySound(pszSoundA, hmod, fdwSound, FALSE);
648}
static BOOL MULTIMEDIA_PlaySound(const void *pszSound, HMODULE hmod, DWORD fdwSound, BOOL bUnicode)
Definition: playsound.c:589

Referenced by test_PlaySound().

◆ PlaySoundAsyncThreadProc()

static DWORD WINAPI PlaySoundAsyncThreadProc ( LPVOID  lpParameter)
static

Definition at line 561 of file playsound.c.

562{
563 WINE_PLAYSOUND *wps = (WINE_PLAYSOUND*)lpParameter;
564
565 /* Play the sound */
566 proc_PlaySound(wps);
567
568 return 0;
569}

Referenced by proc_PlaySoundAsync().

◆ PlaySoundW()

BOOL WINAPI PlaySoundW ( LPCWSTR  pszSoundW,
HMODULE  hmod,
DWORD  fdwSound 
)

◆ proc_PlaySound()

static BOOL proc_PlaySound ( WINE_PLAYSOUND wps)
static

Definition at line 423 of file playsound.c.

424{
425 BOOL bRet = FALSE;
426 MMCKINFO ckMainRIFF;
427 MMCKINFO mmckInfo;
428 LPWAVEFORMATEX lpWaveFormat = NULL;
429 HWAVEOUT hWave = 0;
430 LPWAVEHDR waveHdr = NULL;
432 struct playsound_data s;
433 LONG r;
434
435 s.hEvent = 0;
436
437 if (mmioDescend(wps->hmmio, &ckMainRIFF, NULL, 0))
438 goto errCleanUp;
439
440 TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08X\n",
441 (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize);
442
443 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
444 (ckMainRIFF.fccType != mmioFOURCC('W', 'A', 'V', 'E')))
445 goto errCleanUp;
446
447 mmckInfo.ckid = mmioFOURCC('f', 'm', 't', ' ');
448 if (mmioDescend(wps->hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK))
449 goto errCleanUp;
450
451 TRACE("Chunk Found ckid=%.4s fccType=%08x cksize=%08X\n",
452 (LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize);
453
454 lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
455 if (!lpWaveFormat)
456 goto errCleanUp;
457 r = mmioRead(wps->hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize);
458 if (r < 0 || r < sizeof(PCMWAVEFORMAT))
459 goto errCleanUp;
460
461 TRACE("wFormatTag=%04X !\n", lpWaveFormat->wFormatTag);
462 TRACE("nChannels=%d\n", lpWaveFormat->nChannels);
463 TRACE("nSamplesPerSec=%d\n", lpWaveFormat->nSamplesPerSec);
464 TRACE("nAvgBytesPerSec=%d\n", lpWaveFormat->nAvgBytesPerSec);
465 TRACE("nBlockAlign=%d\n", lpWaveFormat->nBlockAlign);
466 TRACE("wBitsPerSample=%u !\n", lpWaveFormat->wBitsPerSample);
467
468 /* move to end of 'fmt ' chunk */
469 mmioAscend(wps->hmmio, &mmckInfo, 0);
470
471 mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
472 if (mmioDescend(wps->hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK))
473 goto errCleanUp;
474
475 TRACE("Chunk Found ckid=%.4s fccType=%08x cksize=%08X\n",
476 (LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize);
477
478 s.hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
479 if (!s.hEvent || bPlaySoundStop)
480 goto errCleanUp;
481
484 goto errCleanUp;
485
486 /* make it so that 3 buffers per second are needed */
487 bufsize = (((lpWaveFormat->nAvgBytesPerSec / 3) - 1) / lpWaveFormat->nBlockAlign + 1) *
488 lpWaveFormat->nBlockAlign;
489 waveHdr = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(WAVEHDR) + 2 * bufsize);
490 if (!waveHdr)
491 goto errCleanUp;
492 waveHdr[0].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR);
493 waveHdr[1].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR) + bufsize;
494 waveHdr[0].dwUser = waveHdr[1].dwUser = 0L;
495 waveHdr[0].dwLoops = waveHdr[1].dwLoops = 0L;
496 waveHdr[0].dwFlags = waveHdr[1].dwFlags = 0L;
497 waveHdr[0].dwBufferLength = waveHdr[1].dwBufferLength = bufsize;
498 if (waveOutPrepareHeader(hWave, &waveHdr[0], sizeof(WAVEHDR)) ||
499 waveOutPrepareHeader(hWave, &waveHdr[1], sizeof(WAVEHDR))) {
500 goto errCleanUp;
501 }
502
503 wps->hWave = hWave;
504 s.dwEventCount = 1L; /* for first buffer */
505 index = 0;
506
507 do {
508 left = mmckInfo.cksize;
509
510 mmioSeek(wps->hmmio, mmckInfo.dwDataOffset, SEEK_SET);
511 while (left)
512 {
513 if (bPlaySoundStop)
514 {
515 wps->bLoop = FALSE;
516 break;
517 }
518 count = mmioRead(wps->hmmio, waveHdr[index].lpData, min(bufsize, left));
519 if (count < 1) break;
520 left -= count;
521 waveHdr[index].dwBufferLength = count;
522 if (waveOutWrite(hWave, &waveHdr[index], sizeof(WAVEHDR)) == MMSYSERR_NOERROR) {
523 index ^= 1;
525 }
526 else {
527 ERR("Aborting play loop, waveOutWrite error\n");
528 wps->bLoop = FALSE;
529 break;
530 }
531 }
532 bRet = TRUE;
533 } while (wps->bLoop);
534
535 PlaySound_WaitDone(&s); /* to balance first buffer */
537
538 waveOutUnprepareHeader(hWave, &waveHdr[0], sizeof(WAVEHDR));
539 waveOutUnprepareHeader(hWave, &waveHdr[1], sizeof(WAVEHDR));
540
541errCleanUp:
542 TRACE("Done playing sound => %s!\n", bRet ? "ok" : "ko");
543 HeapFree(GetProcessHeap(), 0, lpWaveFormat);
544 if (hWave)
545 {
547 /* the CS prevents a concurrent waveOutReset */
548 wps->hWave = 0;
551 Sleep(100);
552 }
553 CloseHandle(s.hEvent);
554 HeapFree(GetProcessHeap(), 0, waveHdr);
555
556 PlaySound_Free(wps);
557
558 return bRet;
559}
#define index(s, c)
Definition: various.h:29
#define CloseHandle
Definition: compat.h:739
MMRESULT WINAPI mmioAscend(HMMIO hmmio, LPMMCKINFO lpck, UINT uFlags)
Definition: mmio.c:1205
LONG WINAPI mmioSeek(HMMIO hmmio, LONG lOffset, INT iOrigin)
Definition: mmio.c:836
MMRESULT WINAPI mmioDescend(HMMIO hmmio, LPMMCKINFO lpck, const MMCKINFO *lpckParent, UINT uFlags)
Definition: mmio.c:1107
LONG WINAPI mmioRead(HMMIO hmmio, HPSTR pch, LONG cch)
Definition: mmio.c:733
HWAVEOUT hWave
Definition: main.h:78
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint index
Definition: glext.h:6031
GLint left
Definition: glext.h:7726
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
#define SEEK_SET
Definition: jmemansi.c:26
#define WAVERR_STILLPLAYING
Definition: mmsystem.h:177
struct wavehdr_tag WAVEHDR
#define FOURCC_RIFF
Definition: mmsystem.h:564
#define MMIO_FINDCHUNK
Definition: mmsystem.h:551
#define WAVE_MAPPER
Definition: mmsystem.h:187
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define mmioFOURCC(c0, c1, c2, c3)
Definition: mmsystem.h:38
#define CALLBACK_FUNCTION
Definition: mmsystem.h:150
char * HPSTR
Definition: mmsystem.h:1477
#define min(a, b)
Definition: monoChain.cc:55
long LONG
Definition: pedump.c:60
static void CALLBACK PlaySound_Callback(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
Definition: playsound.c:317
static void PlaySound_WaitDone(struct playsound_data *s)
Definition: playsound.c:337
FOURCC ckid
Definition: mmsystem.h:1507
DWORD cksize
Definition: mmsystem.h:1508
DWORD dwDataOffset
Definition: mmsystem.h:1510
FOURCC fccType
Definition: mmsystem.h:1509
WORD nBlockAlign
Definition: mmreg.h:82
DWORD nAvgBytesPerSec
Definition: mmreg.h:81
DWORD nSamplesPerSec
Definition: mmreg.h:80
WORD nChannels
Definition: mmreg.h:79
WORD wFormatTag
Definition: mmreg.h:78
WORD wBitsPerSample
Definition: mmreg.h:83
DWORD dwBufferLength
Definition: mmsystem.h:1015
DWORD dwLoops
Definition: mmsystem.h:1019
DWORD dwFlags
Definition: mmsystem.h:1018
DWORD_PTR dwUser
Definition: mmsystem.h:1017
LPSTR lpData
Definition: mmsystem.h:1014
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
uint32_t DWORD_PTR
Definition: typedefs.h:65
int32_t INT
Definition: typedefs.h:58
UINT WINAPI waveOutWrite(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr, UINT uSize)
Definition: winmm.c:2341
UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr, UINT uSize)
Definition: winmm.c:2307
MMRESULT WINAPI waveOutOpen(LPHWAVEOUT lphWaveOut, UINT uDeviceID, LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
Definition: winmm.c:2246
UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut, WAVEHDR *lpWaveOutHdr, UINT uSize)
Definition: winmm.c:2277
UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)
Definition: winmm.c:2257
char * LPSTR
Definition: xmlstorage.h:182

Referenced by MULTIMEDIA_PlaySound(), and PlaySoundAsyncThreadProc().

◆ proc_PlaySoundAsync()

static BOOL proc_PlaySoundAsync ( WINE_PLAYSOUND wps)
static

Definition at line 571 of file playsound.c.

572{
574
575 /* Create a thread to play the sound asynchronously */
577 if (hThread)
578 {
581 return TRUE;
582 }
583
584 /* Error cases */
585 PlaySound_Free(wps);
586 return FALSE;
587}
BOOL WINAPI SetThreadPriority(IN HANDLE hThread, IN int nPriority)
Definition: thread.c:700
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
HANDLE hThread
Definition: wizard.c:28
static DWORD WINAPI PlaySoundAsyncThreadProc(LPVOID lpParameter)
Definition: playsound.c:561
#define THREAD_PRIORITY_TIME_CRITICAL
Definition: winbase.h:307

Referenced by MULTIMEDIA_PlaySound().

◆ sndPlaySoundA()

BOOL WINAPI sndPlaySoundA ( LPCSTR  pszSoundA,
UINT  uFlags 
)

Definition at line 661 of file playsound.c.

Referenced by test_sndPlaySound().

◆ sndPlaySoundW()

BOOL WINAPI sndPlaySoundW ( LPCWSTR  pszSound,
UINT  uFlags 
)

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( winmm  )

Variable Documentation

◆ bPlaySoundStop

BOOL bPlaySoundStop
static

Definition at line 40 of file playsound.c.

Referenced by MULTIMEDIA_PlaySound(), and proc_PlaySound().

◆ PlaySoundCurrent

WINE_PLAYSOUND* PlaySoundCurrent
static

Definition at line 39 of file playsound.c.

Referenced by MULTIMEDIA_PlaySound(), and PlaySound_Free().