2002-10-10 05:43:53 +02:00
|
|
|
/* -*- tab-width: 8; c-basic-offset: 4 -*- */
|
|
|
|
|
|
|
|
/*
|
2008-05-06 20:01:59 +02:00
|
|
|
* MMSYSTEM functions
|
2002-10-10 05:43:53 +02:00
|
|
|
*
|
|
|
|
* Copyright 1993 Martin Ayotte
|
|
|
|
* 1998-2002 Eric Pouech
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-10-10 05:43:53 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-10-10 05:43:53 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-10-10 05:43:53 +02:00
|
|
|
#include "winbase.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "mmsystem.h"
|
2002-10-10 05:43:53 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winemm.h"
|
2003-01-24 00:07:38 +01:00
|
|
|
#include "winternl.h"
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winmm);
|
|
|
|
|
2007-06-07 17:50:28 +02:00
|
|
|
typedef struct tagWINE_PLAYSOUND
|
|
|
|
{
|
|
|
|
unsigned bLoop : 1,
|
|
|
|
bAlloc : 1;
|
|
|
|
LPCWSTR pszSound;
|
|
|
|
HMODULE hMod;
|
|
|
|
DWORD fdwSound;
|
2012-02-14 19:27:30 +01:00
|
|
|
HWAVEOUT hWave;
|
2007-06-07 17:50:28 +02:00
|
|
|
} WINE_PLAYSOUND;
|
|
|
|
|
2012-02-14 19:27:30 +01:00
|
|
|
static WINE_PLAYSOUND *PlaySoundCurrent;
|
2011-03-26 12:36:49 +01:00
|
|
|
static BOOL bPlaySoundStop;
|
2007-06-07 17:50:28 +02:00
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
static HMMIO get_mmioFromFile(LPCWSTR lpszName)
|
|
|
|
{
|
|
|
|
HMMIO ret;
|
|
|
|
WCHAR buf[256];
|
|
|
|
LPWSTR dummy;
|
2015-02-24 17:38:47 +01:00
|
|
|
static const WCHAR dotwav[] = {'.','w','a','v',0};
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
ret = mmioOpenW((LPWSTR)lpszName, NULL,
|
|
|
|
MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
|
|
|
|
if (ret != 0) return ret;
|
2018-09-19 21:01:11 +02:00
|
|
|
if (SearchPathW(NULL, lpszName, dotwav, ARRAY_SIZE(buf), buf, &dummy))
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
return mmioOpenW(buf, NULL,
|
|
|
|
MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HMMIO get_mmioFromProfile(UINT uFlags, LPCWSTR lpszName)
|
|
|
|
{
|
|
|
|
WCHAR str[128];
|
|
|
|
LPWSTR ptr;
|
|
|
|
HMMIO hmmio;
|
|
|
|
HKEY hRegSnd, hRegApp, hScheme, hSnd;
|
|
|
|
DWORD err, type, count;
|
|
|
|
|
2004-04-20 02:34:52 +02:00
|
|
|
static const WCHAR wszSounds[] = {'S','o','u','n','d','s',0};
|
|
|
|
static const WCHAR wszDefault[] = {'D','e','f','a','u','l','t',0};
|
|
|
|
static const WCHAR wszKey[] = {'A','p','p','E','v','e','n','t','s','\\',
|
2002-10-10 05:43:53 +02:00
|
|
|
'S','c','h','e','m','e','s','\\',
|
|
|
|
'A','p','p','s',0};
|
2004-04-20 02:34:52 +02:00
|
|
|
static const WCHAR wszDotDefault[] = {'.','D','e','f','a','u','l','t',0};
|
2004-06-14 18:55:33 +02:00
|
|
|
static const WCHAR wszDotCurrent[] = {'.','C','u','r','r','e','n','t',0};
|
2004-04-20 02:34:52 +02:00
|
|
|
static const WCHAR wszNull[] = {0};
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
TRACE("searching in SystemSound list for %s\n", debugstr_w(lpszName));
|
2018-09-19 21:01:11 +02:00
|
|
|
GetProfileStringW(wszSounds, lpszName, wszNull, str, ARRAY_SIZE(str));
|
2002-10-10 05:43:53 +02:00
|
|
|
if (lstrlenW(str) == 0)
|
|
|
|
{
|
|
|
|
if (uFlags & SND_NODEFAULT) goto next;
|
2018-09-19 21:01:11 +02:00
|
|
|
GetProfileStringW(wszSounds, wszDefault, wszNull, str, ARRAY_SIZE(str));
|
2002-10-10 05:43:53 +02:00
|
|
|
if (lstrlenW(str) == 0) goto next;
|
|
|
|
}
|
|
|
|
for (ptr = str; *ptr && *ptr != ','; ptr++);
|
|
|
|
if (*ptr) *ptr = 0;
|
|
|
|
hmmio = mmioOpenW(str, NULL, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
|
|
|
|
if (hmmio != 0) return hmmio;
|
|
|
|
next:
|
|
|
|
/* we look up the registry under
|
|
|
|
* HKCU\AppEvents\Schemes\Apps\.Default
|
|
|
|
* HKCU\AppEvents\Schemes\Apps\<AppName>
|
|
|
|
*/
|
|
|
|
if (RegOpenKeyW(HKEY_CURRENT_USER, wszKey, &hRegSnd) != 0) goto none;
|
|
|
|
if (uFlags & SND_APPLICATION)
|
|
|
|
{
|
2004-05-19 05:22:55 +02:00
|
|
|
DWORD len;
|
|
|
|
|
2002-10-10 05:43:53 +02:00
|
|
|
err = 1; /* error */
|
2018-09-19 21:01:11 +02:00
|
|
|
len = GetModuleFileNameW(0, str, ARRAY_SIZE(str));
|
|
|
|
if (len > 0 && len < ARRAY_SIZE(str))
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
for (ptr = str + lstrlenW(str) - 1; ptr >= str; ptr--)
|
|
|
|
{
|
|
|
|
if (*ptr == '.') *ptr = 0;
|
|
|
|
if (*ptr == '\\')
|
|
|
|
{
|
2004-06-14 18:55:33 +02:00
|
|
|
err = RegOpenKeyW(hRegSnd, ptr+1, &hRegApp);
|
2002-10-10 05:43:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
err = RegOpenKeyW(hRegSnd, wszDotDefault, &hRegApp);
|
|
|
|
}
|
|
|
|
RegCloseKey(hRegSnd);
|
|
|
|
if (err != 0) goto none;
|
|
|
|
err = RegOpenKeyW(hRegApp, lpszName, &hScheme);
|
|
|
|
RegCloseKey(hRegApp);
|
|
|
|
if (err != 0) goto none;
|
2004-06-14 18:55:33 +02:00
|
|
|
/* what's the difference between .Current and .Default ? */
|
2002-10-10 05:43:53 +02:00
|
|
|
err = RegOpenKeyW(hScheme, wszDotDefault, &hSnd);
|
2004-06-14 18:55:33 +02:00
|
|
|
if (err != 0)
|
|
|
|
{
|
|
|
|
err = RegOpenKeyW(hScheme, wszDotCurrent, &hSnd);
|
|
|
|
RegCloseKey(hScheme);
|
|
|
|
if (err != 0)
|
|
|
|
goto none;
|
|
|
|
}
|
2017-02-12 14:00:47 +01:00
|
|
|
count = sizeof(str);
|
2002-10-10 05:43:53 +02:00
|
|
|
err = RegQueryValueExW(hSnd, NULL, 0, &type, (LPBYTE)str, &count);
|
|
|
|
RegCloseKey(hSnd);
|
|
|
|
if (err != 0 || !*str) goto none;
|
|
|
|
hmmio = mmioOpenW(str, NULL, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
|
|
|
|
if (hmmio) return hmmio;
|
|
|
|
none:
|
2007-01-18 11:40:15 +01:00
|
|
|
WARN("can't find SystemSound=%s !\n", debugstr_w(lpszName));
|
2002-10-10 05:43:53 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct playsound_data
|
|
|
|
{
|
|
|
|
HANDLE hEvent;
|
2005-07-13 13:59:15 +02:00
|
|
|
LONG dwEventCount;
|
2002-10-10 05:43:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void CALLBACK PlaySound_Callback(HWAVEOUT hwo, UINT uMsg,
|
2009-05-20 17:50:54 +02:00
|
|
|
DWORD_PTR dwInstance,
|
|
|
|
DWORD_PTR dwParam1, DWORD_PTR dwParam2)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
struct playsound_data* s = (struct playsound_data*)dwInstance;
|
|
|
|
|
|
|
|
switch (uMsg) {
|
|
|
|
case WOM_OPEN:
|
|
|
|
case WOM_CLOSE:
|
|
|
|
break;
|
|
|
|
case WOM_DONE:
|
|
|
|
InterlockedIncrement(&s->dwEventCount);
|
2009-05-20 17:50:54 +02:00
|
|
|
TRACE("Returning waveHdr=%lx\n", dwParam1);
|
2002-10-10 05:43:53 +02:00
|
|
|
SetEvent(s->hEvent);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Unknown uMsg=%d\n", uMsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PlaySound_WaitDone(struct playsound_data* s)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
if (InterlockedDecrement(&s->dwEventCount) >= 0) break;
|
|
|
|
InterlockedIncrement(&s->dwEventCount);
|
|
|
|
|
|
|
|
WaitForSingleObject(s->hEvent, INFINITE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL PlaySound_IsString(DWORD fdwSound, const void* psz)
|
|
|
|
{
|
|
|
|
/* SND_RESOURCE is 0x40004 while
|
|
|
|
* SND_MEMORY is 0x00004
|
|
|
|
*/
|
2009-03-29 17:22:43 +02:00
|
|
|
switch (fdwSound & (SND_RESOURCE|SND_ALIAS_ID|SND_FILENAME))
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
case SND_RESOURCE: return HIWORD(psz) != 0; /* by name or by ID ? */
|
2009-03-29 17:22:43 +02:00
|
|
|
case SND_ALIAS_ID:
|
2002-10-10 05:43:53 +02:00
|
|
|
case SND_MEMORY: return FALSE;
|
2009-03-29 17:22:43 +02:00
|
|
|
case SND_ALIAS:
|
2002-10-10 05:43:53 +02:00
|
|
|
case SND_FILENAME:
|
2010-03-17 23:41:09 +01:00
|
|
|
case SND_ALIAS|SND_FILENAME:
|
2002-10-10 05:43:53 +02:00
|
|
|
case 0: return TRUE;
|
|
|
|
default: FIXME("WTF\n"); return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PlaySound_Free(WINE_PLAYSOUND* wps)
|
|
|
|
{
|
2007-06-07 17:50:28 +02:00
|
|
|
EnterCriticalSection(&WINMM_cs);
|
2012-02-14 19:27:30 +01:00
|
|
|
PlaySoundCurrent = NULL;
|
|
|
|
SetEvent(psLastEvent);
|
2007-06-07 17:50:28 +02:00
|
|
|
LeaveCriticalSection(&WINMM_cs);
|
2002-10-10 05:43:53 +02:00
|
|
|
if (wps->bAlloc) HeapFree(GetProcessHeap(), 0, (void*)wps->pszSound);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wps);
|
|
|
|
}
|
|
|
|
|
|
|
|
static WINE_PLAYSOUND* PlaySound_Alloc(const void* pszSound, HMODULE hmod,
|
|
|
|
DWORD fdwSound, BOOL bUnicode)
|
|
|
|
{
|
|
|
|
WINE_PLAYSOUND* wps;
|
|
|
|
|
|
|
|
wps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wps));
|
|
|
|
if (!wps) return NULL;
|
|
|
|
|
|
|
|
wps->hMod = hmod;
|
|
|
|
wps->fdwSound = fdwSound;
|
|
|
|
if (PlaySound_IsString(fdwSound, pszSound))
|
|
|
|
{
|
|
|
|
if (bUnicode)
|
|
|
|
{
|
|
|
|
if (fdwSound & SND_ASYNC)
|
|
|
|
{
|
2006-11-22 17:15:40 +01:00
|
|
|
LPWSTR sound = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
(lstrlenW(pszSound)+1) * sizeof(WCHAR));
|
|
|
|
if (!sound) goto oom_error;
|
|
|
|
wps->pszSound = lstrcpyW(sound, pszSound);
|
2002-10-10 05:43:53 +02:00
|
|
|
wps->bAlloc = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wps->pszSound = pszSound;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-01-24 00:07:38 +01:00
|
|
|
UNICODE_STRING usBuffer;
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&usBuffer, pszSound);
|
|
|
|
wps->pszSound = usBuffer.Buffer;
|
2002-10-10 05:43:53 +02:00
|
|
|
if (!wps->pszSound) goto oom_error;
|
|
|
|
wps->bAlloc = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wps->pszSound = pszSound;
|
|
|
|
|
|
|
|
return wps;
|
|
|
|
oom_error:
|
2011-03-28 22:34:02 +02:00
|
|
|
if (wps->bAlloc) HeapFree(GetProcessHeap(), 0, (void*)wps->pszSound);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wps);
|
2002-10-10 05:43:53 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI proc_PlaySound(LPVOID arg)
|
|
|
|
{
|
2009-02-20 10:23:08 +01:00
|
|
|
WINE_PLAYSOUND* wps = arg;
|
2002-10-10 05:43:53 +02:00
|
|
|
BOOL bRet = FALSE;
|
|
|
|
HMMIO hmmio = 0;
|
|
|
|
MMCKINFO ckMainRIFF;
|
|
|
|
MMCKINFO mmckInfo;
|
|
|
|
LPWAVEFORMATEX lpWaveFormat = NULL;
|
2011-03-26 07:44:22 +01:00
|
|
|
HWAVEOUT hWave = 0;
|
2002-10-10 05:43:53 +02:00
|
|
|
LPWAVEHDR waveHdr = NULL;
|
|
|
|
INT count, bufsize, left, index;
|
|
|
|
struct playsound_data s;
|
|
|
|
void* data;
|
|
|
|
|
|
|
|
s.hEvent = 0;
|
|
|
|
|
2007-01-18 11:40:15 +01:00
|
|
|
TRACE("SoundName=%s !\n", debugstr_w(wps->pszSound));
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
/* if resource, grab it */
|
|
|
|
if ((wps->fdwSound & SND_RESOURCE) == SND_RESOURCE) {
|
2004-04-20 02:34:52 +02:00
|
|
|
static const WCHAR wszWave[] = {'W','A','V','E',0};
|
2002-10-10 05:43:53 +02:00
|
|
|
HRSRC hRes;
|
|
|
|
HGLOBAL hGlob;
|
|
|
|
|
|
|
|
if ((hRes = FindResourceW(wps->hMod, wps->pszSound, wszWave)) == 0 ||
|
|
|
|
(hGlob = LoadResource(wps->hMod, hRes)) == 0)
|
|
|
|
goto errCleanUp;
|
|
|
|
if ((data = LockResource(hGlob)) == NULL) {
|
|
|
|
FreeResource(hGlob);
|
|
|
|
goto errCleanUp;
|
|
|
|
}
|
|
|
|
FreeResource(hGlob);
|
|
|
|
} else
|
|
|
|
data = (void*)wps->pszSound;
|
|
|
|
|
|
|
|
/* construct an MMIO stream (either in memory, or from a file */
|
|
|
|
if (wps->fdwSound & SND_MEMORY)
|
|
|
|
{ /* NOTE: SND_RESOURCE has the SND_MEMORY bit set */
|
|
|
|
MMIOINFO mminfo;
|
|
|
|
|
|
|
|
memset(&mminfo, 0, sizeof(mminfo));
|
|
|
|
mminfo.fccIOProc = FOURCC_MEM;
|
2009-02-20 10:23:08 +01:00
|
|
|
mminfo.pchBuffer = data;
|
2002-10-10 05:43:53 +02:00
|
|
|
mminfo.cchBuffer = -1; /* FIXME: when a resource, could grab real size */
|
|
|
|
TRACE("Memory sound %p\n", data);
|
|
|
|
hmmio = mmioOpenW(NULL, &mminfo, MMIO_READ);
|
|
|
|
}
|
2010-03-17 23:41:09 +01:00
|
|
|
if (!hmmio && wps->fdwSound & SND_ALIAS)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
2009-04-02 15:32:59 +02:00
|
|
|
if ((wps->fdwSound & SND_ALIAS_ID) == SND_ALIAS_ID)
|
2009-03-29 17:22:43 +02:00
|
|
|
{
|
|
|
|
static const WCHAR wszSystemAsterisk[] = {'S','y','s','t','e','m','A','s','t','e','r','i','s','k',0};
|
|
|
|
static const WCHAR wszSystemDefault[] = {'S','y','s','t','e','m','D','e','f','a','u','l','t',0};
|
|
|
|
static const WCHAR wszSystemExclamation[] = {'S','y','s','t','e','m','E','x','c','l','a','m','a','t','i','o','n',0};
|
|
|
|
static const WCHAR wszSystemExit[] = {'S','y','s','t','e','m','E','x','i','t',0};
|
|
|
|
static const WCHAR wszSystemHand[] = {'S','y','s','t','e','m','H','a','n','d',0};
|
|
|
|
static const WCHAR wszSystemQuestion[] = {'S','y','s','t','e','m','Q','u','e','s','t','i','o','n',0};
|
|
|
|
static const WCHAR wszSystemStart[] = {'S','y','s','t','e','m','S','t','a','r','t',0};
|
|
|
|
static const WCHAR wszSystemWelcome[] = {'S','y','s','t','e','m','W','e','l','c','o','m','e',0};
|
|
|
|
|
|
|
|
wps->fdwSound &= ~(SND_ALIAS_ID ^ SND_ALIAS);
|
|
|
|
if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMASTERISK)
|
|
|
|
wps->pszSound = wszSystemAsterisk;
|
|
|
|
else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMDEFAULT)
|
|
|
|
wps->pszSound = wszSystemDefault;
|
|
|
|
else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMEXCLAMATION)
|
|
|
|
wps->pszSound = wszSystemExclamation;
|
|
|
|
else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMEXIT)
|
|
|
|
wps->pszSound = wszSystemExit;
|
|
|
|
else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMHAND)
|
|
|
|
wps->pszSound = wszSystemHand;
|
|
|
|
else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMQUESTION)
|
|
|
|
wps->pszSound = wszSystemQuestion;
|
|
|
|
else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMSTART)
|
|
|
|
wps->pszSound = wszSystemStart;
|
|
|
|
else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMWELCOME)
|
|
|
|
wps->pszSound = wszSystemWelcome;
|
2009-04-02 15:21:16 +02:00
|
|
|
else goto errCleanUp;
|
2009-03-29 17:22:43 +02:00
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
hmmio = get_mmioFromProfile(wps->fdwSound, wps->pszSound);
|
2014-07-04 17:37:12 +02:00
|
|
|
if (!hmmio)
|
|
|
|
{
|
|
|
|
wps->fdwSound &= ~SND_ALIAS;
|
|
|
|
wps->fdwSound |= SND_FILENAME;
|
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
2010-03-17 23:41:09 +01:00
|
|
|
if (!hmmio && wps->fdwSound & SND_FILENAME)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
hmmio = get_mmioFromFile(wps->pszSound);
|
|
|
|
}
|
2010-03-17 23:41:09 +01:00
|
|
|
if (!(wps->fdwSound & (SND_FILENAME|SND_ALIAS|SND_MEMORY)))
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
if ((hmmio = get_mmioFromProfile(wps->fdwSound | SND_NODEFAULT, wps->pszSound)) == 0)
|
|
|
|
{
|
|
|
|
if ((hmmio = get_mmioFromFile(wps->pszSound)) == 0)
|
|
|
|
{
|
|
|
|
hmmio = get_mmioFromProfile(wps->fdwSound, wps->pszSound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hmmio == 0) goto errCleanUp;
|
|
|
|
|
|
|
|
if (mmioDescend(hmmio, &ckMainRIFF, NULL, 0))
|
|
|
|
goto errCleanUp;
|
|
|
|
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08X\n",
|
2002-10-10 05:43:53 +02:00
|
|
|
(LPSTR)&ckMainRIFF.ckid, (LPSTR)&ckMainRIFF.fccType, ckMainRIFF.cksize);
|
|
|
|
|
|
|
|
if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
|
|
|
|
(ckMainRIFF.fccType != mmioFOURCC('W', 'A', 'V', 'E')))
|
|
|
|
goto errCleanUp;
|
|
|
|
|
|
|
|
mmckInfo.ckid = mmioFOURCC('f', 'm', 't', ' ');
|
|
|
|
if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK))
|
|
|
|
goto errCleanUp;
|
|
|
|
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("Chunk Found ckid=%.4s fccType=%08x cksize=%08X\n",
|
2005-09-09 12:05:02 +02:00
|
|
|
(LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
|
2011-03-28 22:34:02 +02:00
|
|
|
if (!lpWaveFormat)
|
|
|
|
goto errCleanUp;
|
2009-10-03 11:42:37 +02:00
|
|
|
if (mmioRead(hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize) < sizeof(PCMWAVEFORMAT))
|
2002-10-10 05:43:53 +02:00
|
|
|
goto errCleanUp;
|
|
|
|
|
|
|
|
TRACE("wFormatTag=%04X !\n", lpWaveFormat->wFormatTag);
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("nChannels=%d\n", lpWaveFormat->nChannels);
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("nSamplesPerSec=%d\n", lpWaveFormat->nSamplesPerSec);
|
|
|
|
TRACE("nAvgBytesPerSec=%d\n", lpWaveFormat->nAvgBytesPerSec);
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("nBlockAlign=%d\n", lpWaveFormat->nBlockAlign);
|
2002-10-10 05:43:53 +02:00
|
|
|
TRACE("wBitsPerSample=%u !\n", lpWaveFormat->wBitsPerSample);
|
|
|
|
|
|
|
|
/* move to end of 'fmt ' chunk */
|
|
|
|
mmioAscend(hmmio, &mmckInfo, 0);
|
|
|
|
|
|
|
|
mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a');
|
|
|
|
if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK))
|
|
|
|
goto errCleanUp;
|
|
|
|
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("Chunk Found ckid=%.4s fccType=%08x cksize=%08X\n",
|
2005-09-09 12:05:02 +02:00
|
|
|
(LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2004-12-06 21:55:25 +01:00
|
|
|
s.hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2012-02-14 19:27:30 +01:00
|
|
|
if (!s.hEvent || bPlaySoundStop)
|
2011-03-28 22:34:02 +02:00
|
|
|
goto errCleanUp;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2011-03-26 07:44:22 +01:00
|
|
|
if (waveOutOpen(&hWave, WAVE_MAPPER, lpWaveFormat, (DWORD_PTR)PlaySound_Callback,
|
2009-05-20 17:50:54 +02:00
|
|
|
(DWORD_PTR)&s, CALLBACK_FUNCTION) != MMSYSERR_NOERROR)
|
2002-10-10 05:43:53 +02:00
|
|
|
goto errCleanUp;
|
|
|
|
|
|
|
|
/* make it so that 3 buffers per second are needed */
|
|
|
|
bufsize = (((lpWaveFormat->nAvgBytesPerSec / 3) - 1) / lpWaveFormat->nBlockAlign + 1) *
|
|
|
|
lpWaveFormat->nBlockAlign;
|
|
|
|
waveHdr = HeapAlloc(GetProcessHeap(), 0, 2 * sizeof(WAVEHDR) + 2 * bufsize);
|
2011-03-28 22:34:02 +02:00
|
|
|
if (!waveHdr)
|
|
|
|
goto errCleanUp;
|
2002-10-10 05:43:53 +02:00
|
|
|
waveHdr[0].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR);
|
|
|
|
waveHdr[1].lpData = (char*)waveHdr + 2 * sizeof(WAVEHDR) + bufsize;
|
|
|
|
waveHdr[0].dwUser = waveHdr[1].dwUser = 0L;
|
|
|
|
waveHdr[0].dwLoops = waveHdr[1].dwLoops = 0L;
|
|
|
|
waveHdr[0].dwFlags = waveHdr[1].dwFlags = 0L;
|
|
|
|
waveHdr[0].dwBufferLength = waveHdr[1].dwBufferLength = bufsize;
|
2011-03-26 07:44:22 +01:00
|
|
|
if (waveOutPrepareHeader(hWave, &waveHdr[0], sizeof(WAVEHDR)) ||
|
|
|
|
waveOutPrepareHeader(hWave, &waveHdr[1], sizeof(WAVEHDR))) {
|
2002-10-10 05:43:53 +02:00
|
|
|
goto errCleanUp;
|
|
|
|
}
|
|
|
|
|
2012-02-14 19:27:30 +01:00
|
|
|
wps->hWave = hWave;
|
2002-10-10 05:43:53 +02:00
|
|
|
s.dwEventCount = 1L; /* for first buffer */
|
2004-12-06 21:55:25 +01:00
|
|
|
index = 0;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
do {
|
|
|
|
left = mmckInfo.cksize;
|
|
|
|
|
|
|
|
mmioSeek(hmmio, mmckInfo.dwDataOffset, SEEK_SET);
|
|
|
|
while (left)
|
|
|
|
{
|
2011-03-26 12:36:49 +01:00
|
|
|
if (bPlaySoundStop)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
wps->bLoop = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count = mmioRead(hmmio, waveHdr[index].lpData, min(bufsize, left));
|
|
|
|
if (count < 1) break;
|
|
|
|
left -= count;
|
|
|
|
waveHdr[index].dwBufferLength = count;
|
2011-03-26 07:44:22 +01:00
|
|
|
if (waveOutWrite(hWave, &waveHdr[index], sizeof(WAVEHDR)) == MMSYSERR_NOERROR) {
|
2002-10-10 05:43:53 +02:00
|
|
|
index ^= 1;
|
|
|
|
PlaySound_WaitDone(&s);
|
|
|
|
}
|
2011-03-26 07:36:47 +01:00
|
|
|
else {
|
|
|
|
ERR("Aborting play loop, waveOutWrite error\n");
|
|
|
|
wps->bLoop = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
bRet = TRUE;
|
|
|
|
} while (wps->bLoop);
|
|
|
|
|
2011-03-26 07:36:47 +01:00
|
|
|
PlaySound_WaitDone(&s); /* to balance first buffer */
|
2011-03-26 07:44:22 +01:00
|
|
|
waveOutReset(hWave);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2011-03-26 07:44:22 +01:00
|
|
|
waveOutUnprepareHeader(hWave, &waveHdr[0], sizeof(WAVEHDR));
|
|
|
|
waveOutUnprepareHeader(hWave, &waveHdr[1], sizeof(WAVEHDR));
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
errCleanUp:
|
2007-01-18 11:40:15 +01:00
|
|
|
TRACE("Done playing=%s => %s!\n", debugstr_w(wps->pszSound), bRet ? "ok" : "ko");
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpWaveFormat);
|
2012-02-14 19:27:30 +01:00
|
|
|
if (hWave)
|
|
|
|
{
|
|
|
|
EnterCriticalSection(&WINMM_cs);
|
|
|
|
/* the CS prevents a concurrent waveOutReset */
|
|
|
|
wps->hWave = 0;
|
|
|
|
LeaveCriticalSection(&WINMM_cs);
|
|
|
|
while (waveOutClose(hWave) == WAVERR_STILLPLAYING)
|
|
|
|
Sleep(100);
|
|
|
|
}
|
2011-03-28 22:34:02 +02:00
|
|
|
CloseHandle(s.hEvent);
|
|
|
|
HeapFree(GetProcessHeap(), 0, waveHdr);
|
2002-10-10 05:43:53 +02:00
|
|
|
if (hmmio) mmioClose(hmmio, 0);
|
|
|
|
|
|
|
|
PlaySound_Free(wps);
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2004-11-29 19:00:10 +01:00
|
|
|
static BOOL MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSound, BOOL bUnicode)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
|
|
|
WINE_PLAYSOUND* wps = NULL;
|
|
|
|
|
2006-11-08 22:24:36 +01:00
|
|
|
TRACE("pszSound='%p' hmod=%p fdwSound=%08X\n",
|
2002-10-10 05:43:53 +02:00
|
|
|
pszSound, hmod, fdwSound);
|
|
|
|
|
2011-01-11 23:30:34 +01:00
|
|
|
/* SND_NOWAIT is ignored in w95/2k/xp. */
|
2012-02-14 19:27:30 +01:00
|
|
|
if ((fdwSound & SND_NOSTOP) && PlaySoundCurrent != NULL)
|
2002-10-10 05:43:53 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* alloc internal structure, if we need to play something */
|
|
|
|
if (pszSound && !(fdwSound & SND_PURGE))
|
|
|
|
{
|
|
|
|
if (!(wps = PlaySound_Alloc(pszSound, hmod, fdwSound, bUnicode)))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-06-07 17:50:28 +02:00
|
|
|
EnterCriticalSection(&WINMM_cs);
|
2002-10-10 05:43:53 +02:00
|
|
|
/* since several threads can enter PlaySound in parallel, we're not
|
|
|
|
* sure, at this point, that another thread didn't start a new playsound
|
|
|
|
*/
|
2012-02-14 19:27:30 +01:00
|
|
|
while (PlaySoundCurrent != NULL)
|
2002-10-10 05:43:53 +02:00
|
|
|
{
|
2007-06-07 17:50:28 +02:00
|
|
|
ResetEvent(psLastEvent);
|
2002-10-10 05:43:53 +02:00
|
|
|
/* FIXME: doc says we have to stop all instances of pszSound if it's non
|
|
|
|
* NULL... as of today, we stop all playing instances */
|
2011-03-26 12:36:49 +01:00
|
|
|
bPlaySoundStop = TRUE;
|
2012-02-14 19:27:30 +01:00
|
|
|
if(PlaySoundCurrent->hWave)
|
|
|
|
waveOutReset(PlaySoundCurrent->hWave);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2007-06-07 17:50:28 +02:00
|
|
|
LeaveCriticalSection(&WINMM_cs);
|
|
|
|
WaitForSingleObject(psLastEvent, INFINITE);
|
|
|
|
EnterCriticalSection(&WINMM_cs);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2011-03-26 12:36:49 +01:00
|
|
|
bPlaySoundStop = FALSE;
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
|
2012-02-14 19:27:30 +01:00
|
|
|
PlaySoundCurrent = wps;
|
2007-06-07 17:50:28 +02:00
|
|
|
LeaveCriticalSection(&WINMM_cs);
|
2002-10-10 05:43:53 +02:00
|
|
|
|
2011-03-28 22:34:02 +02:00
|
|
|
if (!wps) return TRUE;
|
2002-10-10 05:43:53 +02:00
|
|
|
|
|
|
|
if (fdwSound & SND_ASYNC)
|
|
|
|
{
|
2004-01-20 02:45:05 +01:00
|
|
|
HANDLE handle;
|
2012-07-31 10:58:15 +02:00
|
|
|
wps->bLoop = (fdwSound & SND_LOOP) != 0;
|
2011-03-28 22:34:02 +02:00
|
|
|
if ((handle = CreateThread(NULL, 0, proc_PlaySound, wps, 0, NULL)) != 0) {
|
2005-04-27 11:39:55 +02:00
|
|
|
SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
|
2011-03-28 22:34:02 +02:00
|
|
|
CloseHandle(handle);
|
2002-10-10 05:43:53 +02:00
|
|
|
return TRUE;
|
2004-01-20 02:45:05 +01:00
|
|
|
}
|
2002-10-10 05:43:53 +02:00
|
|
|
}
|
|
|
|
else return proc_PlaySound(wps);
|
|
|
|
|
|
|
|
/* error cases */
|
|
|
|
PlaySound_Free(wps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* PlaySoundA [WINMM.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PlaySoundA(LPCSTR pszSoundA, HMODULE hmod, DWORD fdwSound)
|
|
|
|
{
|
|
|
|
return MULTIMEDIA_PlaySound(pszSoundA, hmod, fdwSound, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* PlaySoundW [WINMM.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI PlaySoundW(LPCWSTR pszSoundW, HMODULE hmod, DWORD fdwSound)
|
|
|
|
{
|
|
|
|
return MULTIMEDIA_PlaySound(pszSoundW, hmod, fdwSound, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* sndPlaySoundA [WINMM.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI sndPlaySoundA(LPCSTR pszSoundA, UINT uFlags)
|
|
|
|
{
|
2015-04-01 17:11:24 +02:00
|
|
|
uFlags &= SND_RESOURCE|SND_ALIAS_ID|SND_FILENAME|SND_ASYNC|SND_LOOP|SND_MEMORY|SND_NODEFAULT|SND_NOSTOP|SND_SYNC;
|
2002-10-10 05:43:53 +02:00
|
|
|
return MULTIMEDIA_PlaySound(pszSoundA, 0, uFlags, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* sndPlaySoundW [WINMM.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI sndPlaySoundW(LPCWSTR pszSound, UINT uFlags)
|
|
|
|
{
|
2015-04-01 17:11:24 +02:00
|
|
|
uFlags &= SND_RESOURCE|SND_ALIAS_ID|SND_FILENAME|SND_ASYNC|SND_LOOP|SND_MEMORY|SND_NODEFAULT|SND_NOSTOP|SND_SYNC;
|
2002-10-10 05:43:53 +02:00
|
|
|
return MULTIMEDIA_PlaySound(pszSound, 0, uFlags, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* mmsystemGetVersion [WINMM.@]
|
|
|
|
*/
|
|
|
|
UINT WINAPI mmsystemGetVersion(void)
|
|
|
|
{
|
|
|
|
TRACE("3.10 (Win95?)\n");
|
|
|
|
return 0x030a;
|
|
|
|
}
|