|
|
| version 1.6, 2003/11/28 08:01:33 | version 1.17, 2011/03/07 09:54:11 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | /** |
| #include <dsound.h> | * @file soundmng.cpp |
| #include "parts.h" | * @brief Sound Manager (DirectSound3) |
| #include "wavefile.h" | * |
| #include "np2.h" | * @author $Author$ |
| #include "soundmng.h" | * @date $Date$ |
| #include "extromio.h" | */ |
| #include "sound.h" | |
| #include "compiler.h" | |
| #include <dsound.h> | |
| #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) | #if defined(VERMOUTH_LIB) |
| #include "vermouth.h" | #include "vermouth.h" |
| #endif | |
| #if defined(MT32SOUND_DLL) | |
| #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 | #endif |
| #if !defined(_WIN64) | |
| #ifdef __cplusplus | #ifdef __cplusplus |
| extern "C" { | extern "C" { |
| #endif | #endif |
| Line 17 void __fastcall satuation_s16mmx(SINT16 | Line 40 void __fastcall satuation_s16mmx(SINT16 |
| #ifdef __cplusplus | #ifdef __cplusplus |
| } | } |
| #endif | #endif |
| #endif | |
| #if 1 | #if 1 |
| Line 36 void __fastcall satuation_s16mmx(SINT16 | Line 60 void __fastcall satuation_s16mmx(SINT16 |
| static LPDIRECTSOUND pDSound; | static LPDIRECTSOUND pDSound; |
| static LPDIRECTSOUNDBUFFER pDSData3; | static LPDIRECTSOUNDBUFFER pDSData3; |
| static UINT dsstreambytes; | static UINT dsstreambytes; |
| static BYTE dsstreamevent; | static UINT8 dsstreamevent; |
| static LPDIRECTSOUNDBUFFER pDSwave3[SOUND_MAXPCM]; | static LPDIRECTSOUNDBUFFER pDSwave3[SOUND_MAXPCM]; |
| static UINT mute; | static UINT mute; |
| static void (PARTSCALL *fnmix)(SINT16 *dst, | static void (PARTSCALL *fnmix)(SINT16 *dst, |
| Line 49 static void (PARTSCALL *fnmix)(SINT16 | Line 73 static void (PARTSCALL *fnmix)(SINT16 |
| // ---- directsound | // ---- directsound |
| static BOOL dsoundcreate(void) { | static BRESULT dsoundcreate(HWND hWnd) |
| { | |
| // DirectSoundの初期化 | // DirectSoundの初期化 |
| if (FAILED(DirectSoundCreate(0, &pDSound, 0))) { | if (FAILED(DirectSoundCreate(0, &pDSound, 0))) { |
| goto dscre_err; | goto dscre_err; |
| } | } |
| if (FAILED(pDSound->SetCooperativeLevel(hWndMain, DSSCL_PRIORITY))) { | if (FAILED(pDSound->SetCooperativeLevel(hWnd, DSSCL_PRIORITY))) |
| if (FAILED(pDSound->SetCooperativeLevel(hWndMain, DSSCL_NORMAL))) { | { |
| if (FAILED(pDSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL))) | |
| { | |
| goto dscre_err; | goto dscre_err; |
| } | } |
| } | } |
| Line 74 UINT soundmng_create(UINT rate, UINT ms) | Line 100 UINT soundmng_create(UINT rate, UINT ms) |
| UINT samples; | UINT samples; |
| DSBUFFERDESC dsbdesc; | DSBUFFERDESC dsbdesc; |
| PCMWAVEFORMAT pcmwf; | PCMWAVEFORMAT pcmwf; |
| int i; | |
| if ((pDSound == NULL) || | if ((pDSound == NULL) || |
| (rate != 11025) && (rate != 22050) && (rate != 44100)) { | (rate != 11025) && (rate != 22050) && (rate != 44100)) { |
| goto stcre_err1; | goto stcre_err1; |
| } | } |
| if (ms < 40) { | if (ms < 40) { |
| ms = 40; | ms = 40; |
| } | } |
| Line 87 UINT soundmng_create(UINT rate, UINT ms) | Line 115 UINT soundmng_create(UINT rate, UINT ms) |
| } | } |
| // キーボード表示のディレイ設定 | // キーボード表示のディレイ設定 |
| // keydispr_delayinit((BYTE)((ms * 10 + 563) / 564)); | // keydispr_delayinit((UINT8)((ms * 10 + 563) / 564)); |
| samples = (rate * ms) / 2000; | samples = (rate * ms) / 2000; |
| samples = (samples + 3) & (~3); | samples = (samples + SOUNDBUFFERALIGN - 1) & (~(SOUNDBUFFERALIGN - 1)); |
| dsstreambytes = samples * 2 * sizeof(SINT16); | dsstreambytes = samples * 2 * sizeof(SINT16); |
| soundmng_setreverse(FALSE); | soundmng_setreverse(FALSE); |
| Line 102 UINT soundmng_create(UINT rate, UINT ms) | Line 130 UINT soundmng_create(UINT rate, UINT ms) |
| pcmwf.wf.nBlockAlign = 2 * sizeof(SINT16); | pcmwf.wf.nBlockAlign = 2 * sizeof(SINT16); |
| pcmwf.wf.nAvgBytesPerSec = rate * 2 * sizeof(SINT16); | pcmwf.wf.nAvgBytesPerSec = rate * 2 * sizeof(SINT16); |
| ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC)); | for (i=0; i<2; i++) { |
| dsbdesc.dwSize = DSBUFFERDESC_SIZE; | ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC)); |
| dsbdesc.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | | dsbdesc.dwSize = i ? sizeof(dsbdesc) : DSBUFFERDESC_SIZE; |
| dsbdesc.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | | |
| DSBCAPS_CTRLFREQUENCY | | DSBCAPS_CTRLFREQUENCY | |
| DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2; | DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2; |
| dsbdesc.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf; | dsbdesc.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf; |
| dsbdesc.dwBufferBytes = dsstreambytes * 2; | dsbdesc.dwBufferBytes = dsstreambytes * 2; |
| if (FAILED(pDSound->CreateSoundBuffer(&dsbdesc, &pDSData3, NULL))) { | if (SUCCEEDED(pDSound->CreateSoundBuffer(&dsbdesc, &pDSData3, NULL))) { |
| break; | |
| } | |
| } | |
| if (i >= 2) { | |
| goto stcre_err2; | goto stcre_err2; |
| } | } |
| Line 117 UINT soundmng_create(UINT rate, UINT ms) | Line 150 UINT soundmng_create(UINT rate, UINT ms) |
| vermouth_module = midimod_create(rate); | vermouth_module = midimod_create(rate); |
| midimod_loadall(vermouth_module); | midimod_loadall(vermouth_module); |
| #endif | #endif |
| dsstreamevent = (BYTE)-1; | |
| soundmng_reset(); | #if defined(MT32SOUND_DLL) |
| mt32sound_setrate(rate); | |
| #endif | |
| dsstreamevent = (UINT8)-1; | |
| return(samples); | return(samples); |
| stcre_err2: | stcre_err2: |
| Line 145 void soundmng_reset(void) { | Line 182 void soundmng_reset(void) { |
| } | } |
| pDSData3->Unlock(blockptr1, blocksize1, blockptr2, blocksize2); | pDSData3->Unlock(blockptr1, blocksize1, blockptr2, blocksize2); |
| pDSData3->SetCurrentPosition(0); | pDSData3->SetCurrentPosition(0); |
| dsstreamevent = (BYTE)-1; | dsstreamevent = (UINT8)-1; |
| } | } |
| } | } |
| Line 156 void soundmng_destroy(void) { | Line 193 void soundmng_destroy(void) { |
| midimod_destroy(vermouth_module); | midimod_destroy(vermouth_module); |
| vermouth_module = NULL; | vermouth_module = NULL; |
| #endif | #endif |
| #if defined(MT32SOUND_DLL) | |
| mt32sound_setrate(0); | |
| #endif | |
| pDSData3->Stop(); | pDSData3->Stop(); |
| pDSData3->Release(); | pDSData3->Release(); |
| pDSData3 = NULL; | pDSData3 = NULL; |
| Line 172 static void streamenable(BOOL play) { | Line 212 static void streamenable(BOOL play) { |
| pDSData3->Stop(); | pDSData3->Stop(); |
| } | } |
| } | } |
| juliet_YMF288Enable(play); | |
| } | } |
| void soundmng_play(void) { | void soundmng_play(void) { |
| Line 245 void soundmng_sync(void) { | Line 286 void soundmng_sync(void) { |
| void soundmng_setreverse(BOOL reverse) { | void soundmng_setreverse(BOOL reverse) { |
| if (!reverse) { | if (!reverse) { |
| #if !defined(_WIN64) | |
| if (mmxflag) { | if (mmxflag) { |
| fnmix = satuation_s16; | fnmix = satuation_s16; |
| } | } |
| else { | else { |
| fnmix = satuation_s16mmx; | fnmix = satuation_s16mmx; |
| } | } |
| #else | |
| fnmix = satuation_s16; | |
| #endif | |
| } | } |
| else { | else { |
| fnmix = satuation_s16x; | fnmix = satuation_s16x; |
| Line 295 static void pcmstop(void) { | Line 340 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; | EXTROMH erh; |
| RIFF_HEADER riff; | RIFF_HEADER riff; |
| Line 406 void soundmng_pcmvolume(UINT num, int vo | Line 451 void soundmng_pcmvolume(UINT num, int vo |
| } | } |
| } | } |
| BOOL soundmng_pcmplay(UINT num, BOOL loop) { | BRESULT soundmng_pcmplay(UINT num, BOOL loop) { |
| LPDIRECTSOUNDBUFFER dsbuf; | LPDIRECTSOUNDBUFFER dsbuf; |
| Line 436 void soundmng_pcmstop(UINT num) { | Line 481 void soundmng_pcmstop(UINT num) { |
| // ---- | // ---- |
| BOOL soundmng_initialize(void) { | BRESULT soundmng_initialize(void) { |
| if (dsoundcreate() != SUCCESS) { | if (dsoundcreate(g_hWndMain) != SUCCESS) { |
| goto smcre_err; | goto smcre_err; |
| } | } |
| pcmcreate(); | pcmcreate(); |
| #if defined(MT32SOUND_DLL) | |
| mt32sound_initialize(); | |
| #endif | |
| return(SUCCESS); | return(SUCCESS); |
| smcre_err: | smcre_err: |
| Line 451 smcre_err: | Line 499 smcre_err: |
| void soundmng_deinitialize(void) { | void soundmng_deinitialize(void) { |
| #if defined(MT32SOUND_DLL) | |
| mt32sound_deinitialize(); | |
| #endif | |
| pcmdestroy(); | pcmdestroy(); |
| soundmng_destroy(); | soundmng_destroy(); |
| RELEASE(pDSound); | RELEASE(pDSound); |