--- np2/win9x/soundmng.cpp 2003/10/16 17:58:48 1.1.1.1 +++ np2/win9x/soundmng.cpp 2006/12/24 00:52:29 1.12 @@ -6,9 +6,23 @@ #include "soundmng.h" #include "extromio.h" #include "sound.h" +#include "juliet.h" #if defined(VERMOUTH_LIB) #include "vermouth.h" #endif +#if defined(MT32SOUND_DLL) +#include "mt32snd.h" +#endif + +#if !defined(_WIN64) +#ifdef __cplusplus +extern "C" { +#endif +void __fastcall satuation_s16mmx(SINT16 *dst, const SINT32 *src, UINT size); +#ifdef __cplusplus +} +#endif +#endif #if 1 @@ -28,9 +42,11 @@ static LPDIRECTSOUND pDSound; static LPDIRECTSOUNDBUFFER pDSData3; static UINT dsstreambytes; -static BYTE dsstreamevent; +static UINT8 dsstreamevent; static LPDIRECTSOUNDBUFFER pDSwave3[SOUND_MAXPCM]; -static BYTE mute; +static UINT mute; +static void (PARTSCALL *fnmix)(SINT16 *dst, + const SINT32 *src, UINT size); #if defined(VERMOUTH_LIB) MIDIMOD vermouth_module = NULL; @@ -39,7 +55,7 @@ static BYTE mute; // ---- directsound -static BOOL dsoundcreate(void) { +static BRESULT dsoundcreate(void) { // DirectSoundの初期化 if (FAILED(DirectSoundCreate(0, &pDSound, 0))) { @@ -64,27 +80,26 @@ UINT soundmng_create(UINT rate, UINT ms) UINT samples; DSBUFFERDESC dsbdesc; PCMWAVEFORMAT pcmwf; -#if defined(VERMOUTH_LIB) - UINT num; -#endif + int i; if ((pDSound == NULL) || (rate != 11025) && (rate != 22050) && (rate != 44100)) { goto stcre_err1; } - if (ms < 50) { - ms = 50; + if (ms < 40) { + ms = 40; } else if (ms > 1000) { ms = 1000; } // キーボード表示のディレイ設定 -// keydispr_delayinit((BYTE)((ms * 10 + 563) / 564)); +// keydispr_delayinit((UINT8)((ms * 10 + 563) / 564)); samples = (rate * ms) / 2000; samples = (samples + 3) & (~3); dsstreambytes = samples * 2 * sizeof(SINT16); + soundmng_setreverse(FALSE); ZeroMemory(&pcmwf, sizeof(PCMWAVEFORMAT)); pcmwf.wf.wFormatTag = WAVE_FORMAT_PCM; @@ -94,26 +109,30 @@ 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; } #if defined(VERMOUTH_LIB) vermouth_module = midimod_create(rate); - for (num=0; num<128; num++) { - midimod_loadprogram(vermouth_module, num); - midimod_loadrhythm(vermouth_module, num); - } + midimod_loadall(vermouth_module); #endif - dsstreamevent = (BYTE)-1; - soundmng_reset(); +#if defined(MT32SOUND_DLL) + mt32sound_setrate(rate); +#endif + dsstreamevent = (UINT8)-1; return(samples); stcre_err2: @@ -140,7 +159,7 @@ void soundmng_reset(void) { } pDSData3->Unlock(blockptr1, blocksize1, blockptr2, blocksize2); pDSData3->SetCurrentPosition(0); - dsstreamevent = (BYTE)-1; + dsstreamevent = (UINT8)-1; } } @@ -151,6 +170,9 @@ void soundmng_destroy(void) { midimod_destroy(vermouth_module); vermouth_module = NULL; #endif +#if defined(MT32SOUND_DLL) + mt32sound_setrate(0); +#endif pDSData3->Stop(); pDSData3->Release(); pDSData3 = NULL; @@ -167,6 +189,7 @@ static void streamenable(BOOL play) { pDSData3->Stop(); } } + juliet_YMF288Enable(play); } void soundmng_play(void) { @@ -204,7 +227,7 @@ const SINT32 *pcm; } if (SUCCEEDED(hr)) { if (pcm) { - satuation_s16((SINT16 *)blockptr1, pcm, blocksize1); + (*fnmix)((SINT16 *)blockptr1, pcm, blocksize1); } else { ZeroMemory(blockptr1, blocksize1); @@ -238,6 +261,22 @@ 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; + } } @@ -278,7 +317,7 @@ static void pcmstop(void) { } } -void soundmng_pcmload(UINT num, const char *filename, UINT type) { +void soundmng_pcmload(UINT num, const OEMCHAR *filename, UINT type) { EXTROMH erh; RIFF_HEADER riff; @@ -389,7 +428,7 @@ void soundmng_pcmvolume(UINT num, int vo } } -BOOL soundmng_pcmplay(UINT num, BOOL loop) { +BRESULT soundmng_pcmplay(UINT num, BOOL loop) { LPDIRECTSOUNDBUFFER dsbuf; @@ -419,12 +458,15 @@ void soundmng_pcmstop(UINT num) { // ---- -BOOL soundmng_initialize(void) { +BRESULT soundmng_initialize(void) { if (dsoundcreate() != SUCCESS) { goto smcre_err; } pcmcreate(); +#if defined(MT32SOUND_DLL) + mt32sound_initialize(); +#endif return(SUCCESS); smcre_err: @@ -434,6 +476,9 @@ smcre_err: void soundmng_deinitialize(void) { +#if defined(MT32SOUND_DLL) + mt32sound_deinitialize(); +#endif pcmdestroy(); soundmng_destroy(); RELEASE(pDSound); @@ -442,21 +487,24 @@ void soundmng_deinitialize(void) { // ---- -void soundmng_enable(void) { +void soundmng_enable(UINT proc) { - if (mute) { - mute = 0; + if (!(mute & (1 << proc))) { + return; + } + mute &= ~(1 << proc); + if (!mute) { soundmng_reset(); streamenable(TRUE); } } -void soundmng_disable(void) { +void soundmng_disable(UINT proc) { if (!mute) { - mute = 1; streamenable(FALSE); pcmstop(); } + mute |= 1 << proc; }