--- np2/win9x/soundmng.cpp 2005/03/02 04:28:08 1.11 +++ np2/win9x/soundmng.cpp 2011/03/07 09:54:11 1.17 @@ -1,20 +1,38 @@ -#include "compiler.h" -#include -#include "parts.h" -#include "wavefile.h" -#include "np2.h" -#include "soundmng.h" -#include "extromio.h" -#include "sound.h" -#include "juliet.h" +/** + * @file soundmng.cpp + * @brief Sound Manager (DirectSound3) + * + * @author $Author: yui $ + * @date $Date: 2011/03/07 09:54:11 $ + */ + +#include "compiler.h" +#include +#include "parts.h" +#include "wavefile.h" +#include "np2.h" +#include "soundmng.h" +#include "extromio.h" +#include "sound.h" +#include "juliet.h" #if defined(VERMOUTH_LIB) -#include "vermouth.h" +#include "vermouth.h" #endif #if defined(MT32SOUND_DLL) -#include "mt32snd.h" +#include "mt32snd.h" #endif +#if !defined(__GNUC__) +#pragma comment(lib, "dsound.lib") +#endif // !defined(__GNUC__) +#if defined(_M_IA64) || defined(_M_AMD64) +#define SOUNDBUFFERALIGN (1 << 3) +#else +#define SOUNDBUFFERALIGN (1 << 2) +#endif + +#if !defined(_WIN64) #ifdef __cplusplus extern "C" { #endif @@ -22,6 +40,7 @@ void __fastcall satuation_s16mmx(SINT16 #ifdef __cplusplus } #endif +#endif #if 1 @@ -54,14 +73,16 @@ static void (PARTSCALL *fnmix)(SINT16 // ---- directsound -static BRESULT dsoundcreate(void) { - +static BRESULT dsoundcreate(HWND hWnd) +{ // DirectSound¤Î½é´ü²½ if (FAILED(DirectSoundCreate(0, &pDSound, 0))) { goto dscre_err; } - if (FAILED(pDSound->SetCooperativeLevel(hWndMain, DSSCL_PRIORITY))) { - if (FAILED(pDSound->SetCooperativeLevel(hWndMain, DSSCL_NORMAL))) { + if (FAILED(pDSound->SetCooperativeLevel(hWnd, DSSCL_PRIORITY))) + { + if (FAILED(pDSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL))) + { goto dscre_err; } } @@ -79,11 +100,13 @@ UINT soundmng_create(UINT rate, UINT ms) UINT samples; DSBUFFERDESC dsbdesc; PCMWAVEFORMAT pcmwf; + int i; if ((pDSound == NULL) || (rate != 11025) && (rate != 22050) && (rate != 44100)) { goto stcre_err1; } + if (ms < 40) { ms = 40; } @@ -95,7 +118,7 @@ UINT soundmng_create(UINT rate, UINT ms) // keydispr_delayinit((UINT8)((ms * 10 + 563) / 564)); samples = (rate * ms) / 2000; - samples = (samples + 3) & (~3); + samples = (samples + SOUNDBUFFERALIGN - 1) & (~(SOUNDBUFFERALIGN - 1)); dsstreambytes = samples * 2 * sizeof(SINT16); soundmng_setreverse(FALSE); @@ -107,14 +130,19 @@ UINT soundmng_create(UINT rate, UINT ms) pcmwf.wf.nBlockAlign = 2 * sizeof(SINT16); pcmwf.wf.nAvgBytesPerSec = rate * 2 * sizeof(SINT16); - ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC)); - dsbdesc.dwSize = DSBUFFERDESC_SIZE; - dsbdesc.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | + for (i=0; i<2; i++) { + ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC)); + dsbdesc.dwSize = i ? sizeof(dsbdesc) : DSBUFFERDESC_SIZE; + dsbdesc.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2; - dsbdesc.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf; - dsbdesc.dwBufferBytes = dsstreambytes * 2; - if (FAILED(pDSound->CreateSoundBuffer(&dsbdesc, &pDSData3, NULL))) { + dsbdesc.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf; + dsbdesc.dwBufferBytes = dsstreambytes * 2; + if (SUCCEEDED(pDSound->CreateSoundBuffer(&dsbdesc, &pDSData3, NULL))) { + break; + } + } + if (i >= 2) { goto stcre_err2; } @@ -122,11 +150,12 @@ UINT soundmng_create(UINT rate, UINT ms) vermouth_module = midimod_create(rate); midimod_loadall(vermouth_module); #endif + #if defined(MT32SOUND_DLL) mt32sound_setrate(rate); #endif + dsstreamevent = (UINT8)-1; - soundmng_reset(); return(samples); stcre_err2: @@ -257,12 +286,16 @@ void soundmng_sync(void) { void soundmng_setreverse(BOOL reverse) { if (!reverse) { +#if !defined(_WIN64) if (mmxflag) { fnmix = satuation_s16; } else { fnmix = satuation_s16mmx; } +#else + fnmix = satuation_s16; +#endif } else { fnmix = satuation_s16x; @@ -450,7 +483,7 @@ void soundmng_pcmstop(UINT num) { BRESULT soundmng_initialize(void) { - if (dsoundcreate() != SUCCESS) { + if (dsoundcreate(g_hWndMain) != SUCCESS) { goto smcre_err; } pcmcreate();