ReactOS 0.4.15-dev-7887-g64a59a1
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 40 of file playsound.c.

41{
42 HMMIO ret;
43 WCHAR buf[256];
45
46 ret = mmioOpenW((LPWSTR)lpszName, NULL,
48 if (ret != 0) return ret;
49 if (SearchPathW(NULL, lpszName, L".wav", ARRAY_SIZE(buf), buf, &dummy))
50 {
51 return mmioOpenW(buf, NULL,
53 }
54 return 0;
55}
#define ARRAY_SIZE(A)
Definition: main.h:33
#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 57 of file playsound.c.

58{
59 WCHAR str[128];
60 LPWSTR ptr, pszSnd;
61 HMMIO hmmio;
62 HKEY hUserKey, hRegSnd, hRegApp, hScheme, hSnd;
64 BOOL bIsDefault;
65
66 TRACE("searching in SystemSound list for %s\n", debugstr_w(lpszName));
67
68 bIsDefault = (_wcsicmp(lpszName, L"SystemDefault") == 0);
69
70 GetProfileStringW(L"Sounds",
71 bIsDefault ? L"Default" : lpszName,
72 L"",
73 str,
75 if (!*str)
76 goto Next;
77
78 for (ptr = str; *ptr && *ptr != L','; ptr++);
79
80 if (*ptr)
82
84 if (hmmio)
85 return hmmio;
86
87Next:
88 /* we look up the registry under
89 * HKCU\AppEvents\Schemes\Apps\.Default
90 * HKCU\AppEvents\Schemes\Apps<AppName>
91 */
92 err = RegOpenCurrentUser(KEY_READ, &hUserKey);
93 if (err == ERROR_SUCCESS)
94 {
95 err = RegOpenKeyW(hUserKey, L"AppEvents\\Schemes\\Apps", &hRegSnd);
96 RegCloseKey(hUserKey);
97 }
98
99 if (err != ERROR_SUCCESS)
100 goto None;
101
103 {
104 DWORD len;
105
106 err = ERROR_FILE_NOT_FOUND; /* error */
108 if (len > 0 && len < ARRAY_SIZE(str))
109 {
110 for (ptr = str + lstrlenW(str) - 1; ptr >= str; ptr--)
111 {
112 if (*ptr == L'.')
113 *ptr = UNICODE_NULL;
114
115 if (*ptr == L'\\')
116 {
117 err = RegOpenKeyW(hRegSnd, ptr + 1, &hRegApp);
118 break;
119 }
120 }
121 }
122 }
123 else
124 {
125 err = RegOpenKeyW(hRegSnd, L".Default", &hRegApp);
126 }
127
128 RegCloseKey(hRegSnd);
129
130 if (err != ERROR_SUCCESS)
131 goto None;
132
133 err = RegOpenKeyW(hRegApp,
134 bIsDefault ? L".Default" : lpszName,
135 &hScheme);
136
137 RegCloseKey(hRegApp);
138
139 if (err != ERROR_SUCCESS)
140 goto None;
141
142 err = RegOpenKeyW(hScheme, L".Current", &hSnd);
143
144 RegCloseKey(hScheme);
145
146 if (err != ERROR_SUCCESS)
147 goto None;
148
149 count = sizeof(str);
150 err = RegQueryValueExW(hSnd, NULL, 0, &type, (LPBYTE)str, &count);
151
152 RegCloseKey(hSnd);
153
154 if (err != ERROR_SUCCESS || !*str)
155 goto None;
156
157 if (type == REG_EXPAND_SZ)
158 {
160 if (count == 0)
161 goto None;
162
163 pszSnd = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
164 if (!pszSnd)
165 goto None;
166
167 if (ExpandEnvironmentStringsW(str, pszSnd, count) == 0)
168 {
169 HeapFree(GetProcessHeap(), 0, pszSnd);
170 goto None;
171 }
172 }
173 else if (type == REG_SZ)
174 {
175 /* The type is REG_SZ, no need to expand */
176 pszSnd = str;
177 }
178 else
179 {
180 /* Invalid type */
181 goto None;
182 }
183
185
186 if (type == REG_EXPAND_SZ)
187 HeapFree(GetProcessHeap(), 0, pszSnd);
188
189 if (hmmio)
190 return hmmio;
191
192None:
193 WARN("can't find SystemSound=%s !\n", debugstr_w(lpszName));
194 return NULL;
195}
@ None
Definition: install.h:14
#define WARN(fmt,...)
Definition: debug.h:112
#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 677 of file playsound.c.

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

◆ MULTIMEDIA_PlaySound()

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

Definition at line 587 of file playsound.c.

588{
589 WINE_PLAYSOUND* wps = NULL;
590
591 TRACE("pszSound='%p' hmod=%p fdwSound=%08X\n",
592 pszSound, hmod, fdwSound);
593
594 /* SND_NOWAIT is ignored in w95/2k/xp. */
595 if ((fdwSound & SND_NOSTOP) && PlaySoundCurrent != NULL)
596 return FALSE;
597
598 /* alloc internal structure, if we need to play something */
599 if (pszSound && !(fdwSound & SND_PURGE))
600 {
601 if (!(wps = PlaySound_AllocAndGetMMIO(pszSound, hmod, fdwSound, bUnicode)))
602 return FALSE;
603 }
604
606 /* since several threads can enter PlaySound in parallel, we're not
607 * sure, at this point, that another thread didn't start a new playsound
608 */
609 while (PlaySoundCurrent != NULL)
610 {
612 /* FIXME: doc says we have to stop all instances of pszSound if it's non
613 * NULL... as of today, we stop all playing instances */
617
621
623 }
624
625 PlaySoundCurrent = wps;
627
628 if (!wps) return TRUE;
629
630 if (fdwSound & SND_ASYNC)
631 {
632 wps->bLoop = (fdwSound & SND_LOOP) ? TRUE : FALSE;
633
634 return proc_PlaySoundAsync(wps);
635 }
636
637 return proc_PlaySound(wps);
638}
#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:37
static BOOL proc_PlaySound(WINE_PLAYSOUND *wps)
Definition: playsound.c:421
static WINE_PLAYSOUND * PlaySound_AllocAndGetMMIO(const void *pszSound, HMODULE hmod, DWORD fdwSound, BOOL bUnicode)
Definition: playsound.c:380
static BOOL bPlaySoundStop
Definition: playsound.c:38
static BOOL proc_PlaySoundAsync(WINE_PLAYSOUND *wps)
Definition: playsound.c:569
unsigned bLoop
Definition: playsound.c:32
HWAVEOUT hWave
Definition: playsound.c:34
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 380 of file playsound.c.

382{
383 BOOL bIsString;
384 LPCWSTR pszSoundW;
385 UNICODE_STRING usBuffer;
386 WINE_PLAYSOUND* wps;
387
388 bIsString = PlaySound_IsString(fdwSound, pszSound);
389
390 if (bIsString && !bUnicode)
391 {
392 RtlCreateUnicodeStringFromAsciiz(&usBuffer, pszSound);
393 if (!usBuffer.Buffer)
394 return NULL;
395
396 pszSoundW = usBuffer.Buffer;
397 }
398 else
399 {
400 pszSoundW = pszSound;
401 }
402
403 wps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wps));
404 if (wps)
405 {
406 /* construct an MMIO stream (either in memory, or from a file) */
407 wps->hmmio = PlaySound_GetMMIO(pszSoundW, hmod, fdwSound);
408 if (!wps->hmmio)
409 {
410 PlaySound_Free(wps);
411 wps = NULL;
412 }
413 }
414
415 if (bIsString && !bUnicode)
416 RtlFreeUnicodeString(&usBuffer);
417
418 return wps;
419}
#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:370
static HMMIO PlaySound_GetMMIO(LPCWSTR pszSound, HMODULE hMod, DWORD fdwSound)
Definition: playsound.c:197
static BOOL PlaySound_IsString(DWORD fdwSound, const void *psz)
Definition: playsound.c:345
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 315 of file playsound.c.

318{
319 struct playsound_data* s = (struct playsound_data*)dwInstance;
320
321 switch (uMsg) {
322 case WOM_OPEN:
323 case WOM_CLOSE:
324 break;
325 case WOM_DONE:
326 InterlockedIncrement(&s->dwEventCount);
327 TRACE("Returning waveHdr=%lx\n", dwParam1);
328 SetEvent(s->hEvent);
329 break;
330 default:
331 ERR("Unknown uMsg=%d\n", uMsg);
332 }
333}
#define InterlockedIncrement
Definition: armddk.h:53
#define ERR(fmt,...)
Definition: debug.h:110
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 370 of file playsound.c.

371{
376 if (wps->hmmio) mmioClose(wps->hmmio, 0);
377 HeapFree(GetProcessHeap(), 0, wps);
378}
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 197 of file playsound.c.

198{
199 BOOL bIsDefault = FALSE;
200 HMMIO hmmio = NULL;
201
202 TRACE("SoundName=%s !\n", debugstr_w(pszSound));
203
204 if (fdwSound & SND_MEMORY)
205 {
206 PVOID data;
207 MMIOINFO mminfo;
208
209 /* NOTE: SND_RESOURCE has the SND_MEMORY bit set */
210 if ((fdwSound & SND_RESOURCE) == SND_RESOURCE)
211 {
212 HRSRC hRes;
213 HGLOBAL hGlob;
214
215 hRes = FindResourceW(hMod, pszSound, L"WAVE");
216 hGlob = LoadResource(hMod, hRes);
217 if (!hRes || !hGlob)
218 goto Quit;
219
220 data = LockResource(hGlob);
221 FreeResource(hGlob);
222 if (!data)
223 goto Quit;
224 }
225 else
226 {
227 data = (PVOID)pszSound;
228 }
229
230 ZeroMemory(&mminfo, sizeof(mminfo));
231 mminfo.fccIOProc = FOURCC_MEM;
232 mminfo.pchBuffer = data;
233 mminfo.cchBuffer = -1; /* FIXME: when a resource, could grab real size */
234
235 TRACE("Memory sound %p\n", data);
236
237 hmmio = mmioOpenW(NULL, &mminfo, MMIO_READ);
238 }
239 else if (fdwSound & SND_ALIAS)
240 {
241 LPCWSTR pszName;
242
243 /* NOTE: SND_ALIAS_ID has the SND_ALIAS bit set */
244 if ((fdwSound & SND_ALIAS_ID) == SND_ALIAS_ID)
245 {
246 if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMASTERISK)
247 pszName = L"SystemAsterisk";
248 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMDEFAULT)
249 pszName = L"SystemDefault";
250 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMEXCLAMATION)
251 pszName = L"SystemExclamation";
252 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMEXIT)
253 pszName = L"SystemExit";
254 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMHAND)
255 pszName = L"SystemHand";
256 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMQUESTION)
257 pszName = L"SystemQuestion";
258 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMSTART)
259 pszName = L"SystemStart";
260 else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMWELCOME)
261 pszName = L"SystemWelcome";
262 else
263 goto Quit;
264 }
265 else
266 {
267 pszName = pszSound;
268 }
269
270 bIsDefault = (_wcsicmp(pszName, L"SystemDefault") == 0);
271 hmmio = get_mmioFromProfile(fdwSound, pszName);
272 }
273 else if (fdwSound & SND_FILENAME)
274 {
275 hmmio = get_mmioFromFile(pszSound);
276 }
277 else
278 {
279 hmmio = get_mmioFromProfile(fdwSound, pszSound);
280 if (!hmmio)
281 hmmio = get_mmioFromFile(pszSound);
282 }
283
284Quit:
285 if (!hmmio && !(fdwSound & SND_NODEFAULT))
286 {
287 if (fdwSound & SND_APPLICATION)
288 {
289 if (!bIsDefault)
290 {
291 /* Find application-defined default sound */
292 hmmio = get_mmioFromProfile(fdwSound, L"SystemDefault");
293 if (hmmio)
294 return hmmio;
295 }
296
297 /* Find system default sound */
298 hmmio = get_mmioFromProfile(fdwSound & ~SND_APPLICATION, L"SystemDefault");
299 }
300 else if (!bIsDefault)
301 {
302 hmmio = get_mmioFromProfile(fdwSound, L"SystemDefault");
303 }
304 }
305
306 return hmmio;
307}
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:40
static HMMIO get_mmioFromProfile(UINT uFlags, LPCWSTR lpszName)
Definition: playsound.c:57
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:1712

Referenced by PlaySound_AllocAndGetMMIO().

◆ PlaySound_IsString()

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

Definition at line 345 of file playsound.c.

346{
347 /* SND_RESOURCE is 0x40004 while
348 * SND_MEMORY is 0x00004
349 */
350 switch (fdwSound & (SND_RESOURCE | SND_ALIAS_ID | SND_FILENAME))
351 {
352 case SND_RESOURCE:
353 return HIWORD(psz) != 0; /* by name or by ID ? */
354
355 case SND_ALIAS_ID:
356 case SND_MEMORY:
357 return FALSE;
358
359 case SND_ALIAS:
360 case SND_FILENAME:
361 case 0:
362 return TRUE;
363
364 default:
365 FIXME("WTF\n");
366 return FALSE;
367 }
368}
#define FIXME(fmt,...)
Definition: debug.h:111
#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 335 of file playsound.c.

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

Referenced by proc_PlaySound().

◆ PlaySoundA()

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

Definition at line 643 of file playsound.c.

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

Referenced by test_PlaySound().

◆ PlaySoundAsyncThreadProc()

static DWORD WINAPI PlaySoundAsyncThreadProc ( LPVOID  lpParameter)
static

Definition at line 559 of file playsound.c.

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

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 421 of file playsound.c.

422{
423 BOOL bRet = FALSE;
424 MMCKINFO ckMainRIFF;
425 MMCKINFO mmckInfo;
426 LPWAVEFORMATEX lpWaveFormat = NULL;
427 HWAVEOUT hWave = 0;
428 LPWAVEHDR waveHdr = NULL;
430 struct playsound_data s;
431 LONG r;
432
433 s.hEvent = 0;
434
435 if (mmioDescend(wps->hmmio, &ckMainRIFF, NULL, 0))
436 goto errCleanUp;
437
438 TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08X\n",
439 (LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize);
440
441 if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
442 (ckMainRIFF.fccType != mmioFOURCC('W', 'A', 'V', 'E')))
443 goto errCleanUp;
444
445 mmckInfo.ckid = mmioFOURCC('f', 'm', 't', ' ');
446 if (mmioDescend(wps->hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK))
447 goto errCleanUp;
448
449 TRACE("Chunk Found ckid=%.4s fccType=%08x cksize=%08X\n",
450 (LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize);
451
452 lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
453 if (!lpWaveFormat)
454 goto errCleanUp;
455 r = mmioRead(wps->hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize);
456 if (r < 0 || r < sizeof(PCMWAVEFORMAT))
457 goto errCleanUp;
458
459 TRACE("wFormatTag=%04X !\n", lpWaveFormat->wFormatTag);
460 TRACE("nChannels=%d\n", lpWaveFormat->nChannels);
461 TRACE("nSamplesPerSec=%d\n", lpWaveFormat->nSamplesPerSec);
462 TRACE("nAvgBytesPerSec=%d\n", lpWaveFormat->nAvgBytesPerSec);
463 TRACE("nBlockAlign=%d\n", lpWaveFormat->nBlockAlign);
464 TRACE("wBitsPerSample=%u !\n", lpWaveFormat->wBitsPerSample);
465
466 /* move to end of 'fmt ' chunk */
467 mmioAscend(wps->hmmio, &mmckInfo, 0);
468
469 mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
470 if (mmioDescend(wps->hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK))
471 goto errCleanUp;
472
473 TRACE("Chunk Found ckid=%.4s fccType=%08x cksize=%08X\n",
474 (LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize);
475
476 s.hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
477 if (!s.hEvent || bPlaySoundStop)
478 goto errCleanUp;
479
482 goto errCleanUp;
483
484 /* make it so that 3 buffers per second are needed */
485 bufsize = (((lpWaveFormat->nAvgBytesPerSec / 3) - 1) / lpWaveFormat->nBlockAlign + 1) *
486 lpWaveFormat->nBlockAlign;
487 waveHdr = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(WAVEHDR) + 2 * bufsize);
488 if (!waveHdr)
489 goto errCleanUp;
490 waveHdr[0].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR);
491 waveHdr[1].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR) + bufsize;
492 waveHdr[0].dwUser = waveHdr[1].dwUser = 0L;
493 waveHdr[0].dwLoops = waveHdr[1].dwLoops = 0L;
494 waveHdr[0].dwFlags = waveHdr[1].dwFlags = 0L;
495 waveHdr[0].dwBufferLength = waveHdr[1].dwBufferLength = bufsize;
496 if (waveOutPrepareHeader(hWave, &waveHdr[0], sizeof(WAVEHDR)) ||
497 waveOutPrepareHeader(hWave, &waveHdr[1], sizeof(WAVEHDR))) {
498 goto errCleanUp;
499 }
500
501 wps->hWave = hWave;
502 s.dwEventCount = 1L; /* for first buffer */
503 index = 0;
504
505 do {
506 left = mmckInfo.cksize;
507
508 mmioSeek(wps->hmmio, mmckInfo.dwDataOffset, SEEK_SET);
509 while (left)
510 {
511 if (bPlaySoundStop)
512 {
513 wps->bLoop = FALSE;
514 break;
515 }
516 count = mmioRead(wps->hmmio, waveHdr[index].lpData, min(bufsize, left));
517 if (count < 1) break;
518 left -= count;
519 waveHdr[index].dwBufferLength = count;
520 if (waveOutWrite(hWave, &waveHdr[index], sizeof(WAVEHDR)) == MMSYSERR_NOERROR) {
521 index ^= 1;
523 }
524 else {
525 ERR("Aborting play loop, waveOutWrite error\n");
526 wps->bLoop = FALSE;
527 break;
528 }
529 }
530 bRet = TRUE;
531 } while (wps->bLoop);
532
533 PlaySound_WaitDone(&s); /* to balance first buffer */
535
536 waveOutUnprepareHeader(hWave, &waveHdr[0], sizeof(WAVEHDR));
537 waveOutUnprepareHeader(hWave, &waveHdr[1], sizeof(WAVEHDR));
538
539errCleanUp:
540 TRACE("Done playing sound => %s!\n", bRet ? "ok" : "ko");
541 HeapFree(GetProcessHeap(), 0, lpWaveFormat);
542 if (hWave)
543 {
545 /* the CS prevents a concurrent waveOutReset */
546 wps->hWave = 0;
549 Sleep(100);
550 }
551 CloseHandle(s.hEvent);
552 HeapFree(GetProcessHeap(), 0, waveHdr);
553
554 PlaySound_Free(wps);
555
556 return bRet;
557}
#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:315
static void PlaySound_WaitDone(struct playsound_data *s)
Definition: playsound.c:335
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 569 of file playsound.c.

570{
572
573 /* Create a thread to play the sound asynchronously */
575 if (hThread)
576 {
579 return TRUE;
580 }
581
582 /* Error cases */
583 PlaySound_Free(wps);
584 return FALSE;
585}
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:559
#define THREAD_PRIORITY_TIME_CRITICAL
Definition: winbase.h:281

Referenced by MULTIMEDIA_PlaySound().

◆ sndPlaySoundA()

BOOL WINAPI sndPlaySoundA ( LPCSTR  pszSoundA,
UINT  uFlags 
)

Definition at line 659 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 38 of file playsound.c.

Referenced by MULTIMEDIA_PlaySound(), and proc_PlaySound().

◆ PlaySoundCurrent

WINE_PLAYSOUND* PlaySoundCurrent
static

Definition at line 37 of file playsound.c.

Referenced by MULTIMEDIA_PlaySound(), and PlaySound_Free().