|
|
|
|
@ -2,7 +2,6 @@
|
|
|
|
|
|
|
|
|
|
#include "../types.h" |
|
|
|
|
|
|
|
|
|
static float sound_cpp_init_value = INFINITY; |
|
|
|
|
LPDIRECTSOUNDBUFFER DSBs[8]; |
|
|
|
|
LPDIRECTSOUND sglpDS; |
|
|
|
|
char gbSndInited; |
|
|
|
|
@ -41,11 +40,20 @@ void __fastcall snd_update(BOOL bStopAll)
|
|
|
|
|
if (!DSBs[i]) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
if (!bStopAll && !DSBs[i]->GetStatus(&error_code) && error_code == DSBSTATUS_PLAYING) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
DSBs[i]->Stop(); |
|
|
|
|
DSBs[i]->Release(); |
|
|
|
|
#else |
|
|
|
|
if (!bStopAll && !DSBs[i]->lpVtbl->GetStatus(DSBs[i], &error_code) && error_code == DSBSTATUS_PLAYING) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
DSBs[i]->lpVtbl->Stop(DSBs[i]); |
|
|
|
|
DSBs[i]->lpVtbl->Release(DSBs[i]); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
DSBs[i] = NULL; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -53,7 +61,11 @@ void __fastcall snd_update(BOOL bStopAll)
|
|
|
|
|
void __fastcall snd_stop_snd(TSnd *pSnd) |
|
|
|
|
{ |
|
|
|
|
if (pSnd && pSnd->DSB) |
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
pSnd->DSB->Stop(); |
|
|
|
|
#else |
|
|
|
|
pSnd->DSB->lpVtbl->Stop(pSnd->DSB); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BOOL __fastcall snd_playing(TSnd *pSnd) |
|
|
|
|
@ -66,7 +78,11 @@ BOOL __fastcall snd_playing(TSnd *pSnd)
|
|
|
|
|
if (pSnd->DSB == NULL) |
|
|
|
|
return FALSE; |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
if (pSnd->DSB->GetStatus(&error_code)) |
|
|
|
|
#else |
|
|
|
|
if (pSnd->DSB->lpVtbl->GetStatus(pSnd->DSB, &error_code)) |
|
|
|
|
#endif |
|
|
|
|
return FALSE; |
|
|
|
|
|
|
|
|
|
return error_code == DSBSTATUS_PLAYING; |
|
|
|
|
@ -95,7 +111,7 @@ void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
|
|
|
|
|
|
|
|
|
|
if (snd_playing(pSnd)) { |
|
|
|
|
DSB = sound_dup_channel(pSnd->DSB); |
|
|
|
|
if (DSB == 0) { |
|
|
|
|
if (DSB == NULL) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -106,17 +122,29 @@ void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
|
|
|
|
|
} else if (lVolume > VOLUME_MAX) { |
|
|
|
|
lVolume = VOLUME_MAX; |
|
|
|
|
} |
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
DSB->SetVolume(lVolume); |
|
|
|
|
|
|
|
|
|
DSB->SetPan(lPan); |
|
|
|
|
|
|
|
|
|
error_code = DSB->Play(0, 0, 0); |
|
|
|
|
#else |
|
|
|
|
DSB->lpVtbl->SetVolume(DSB, lVolume); |
|
|
|
|
DSB->lpVtbl->SetPan(DSB, lPan); |
|
|
|
|
|
|
|
|
|
error_code = DSB->lpVtbl->Play(DSB, 0, 0, 0); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (error_code != DSERR_BUFFERLOST) { |
|
|
|
|
if (error_code != DS_OK) { |
|
|
|
|
DSErrMsg(error_code, 261, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); |
|
|
|
|
} |
|
|
|
|
} else if (sound_file_reload(pSnd, DSB)) { |
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
DSB->Play(0, 0, 0); |
|
|
|
|
#else |
|
|
|
|
DSB->lpVtbl->Play(DSB, 0, 0, 0); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pSnd->start_tc = tc; |
|
|
|
|
@ -132,7 +160,11 @@ LPDIRECTSOUNDBUFFER __fastcall sound_dup_channel(LPDIRECTSOUNDBUFFER DSB)
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) { |
|
|
|
|
if (!DSBs[i]) { |
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
if (sglpDS->DuplicateSoundBuffer(DSB, &DSBs[i]) != DS_OK) { |
|
|
|
|
#else |
|
|
|
|
if (sglpDS->lpVtbl->DuplicateSoundBuffer(sglpDS, DSB, &DSBs[i]) != DS_OK) { |
|
|
|
|
#endif |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -150,19 +182,31 @@ BOOL __fastcall sound_file_reload(TSnd *sound_file, LPDIRECTSOUNDBUFFER DSB)
|
|
|
|
|
DWORD size1, size2; |
|
|
|
|
BOOL rv; |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
if (DSB->Restore()) |
|
|
|
|
#else |
|
|
|
|
if (DSB->lpVtbl->Restore(DSB)) |
|
|
|
|
#endif |
|
|
|
|
return FALSE; |
|
|
|
|
|
|
|
|
|
rv = FALSE; |
|
|
|
|
|
|
|
|
|
WOpenFile(sound_file->sound_path, &file, 0); |
|
|
|
|
WSetFilePointer(file, sound_file->chunk.dwOffset, 0, 0); |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
if (DSB->Lock(0, sound_file->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0) == DS_OK) { |
|
|
|
|
WReadFile(file, buf1, size1); |
|
|
|
|
if (DSB->Unlock(buf1, size1, buf2, size2) == DS_OK) { |
|
|
|
|
if (DSB->Unlock(buf1, size1, buf2, size2) == DS_OK) |
|
|
|
|
rv = TRUE; |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
if (DSB->lpVtbl->Lock(DSB, 0, sound_file->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0) == DS_OK) { |
|
|
|
|
WReadFile(file, buf1, size1); |
|
|
|
|
if (DSB->lpVtbl->Unlock(DSB, buf1, size1, buf2, size2) == DS_OK) |
|
|
|
|
rv = TRUE; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
WCloseFile(file); |
|
|
|
|
|
|
|
|
|
@ -192,13 +236,21 @@ TSnd *__fastcall sound_file_load(char *path)
|
|
|
|
|
|
|
|
|
|
sound_CreateSoundBuffer(pSnd); |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
error_code = pSnd->DSB->Lock(0, pSnd->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0); |
|
|
|
|
#else |
|
|
|
|
error_code = pSnd->DSB->lpVtbl->Lock(pSnd->DSB, 0, pSnd->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0); |
|
|
|
|
#endif |
|
|
|
|
if (error_code != DS_OK) |
|
|
|
|
DSErrMsg(error_code, 318, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); |
|
|
|
|
|
|
|
|
|
memcpy(buf1, (char *)wave_file + pSnd->chunk.dwOffset, size1); |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
error_code = pSnd->DSB->Unlock(buf1, size1, buf2, size2); |
|
|
|
|
#else |
|
|
|
|
error_code = pSnd->DSB->lpVtbl->Unlock(pSnd->DSB, buf1, size1, buf2, size2); |
|
|
|
|
#endif |
|
|
|
|
if (error_code != DS_OK) |
|
|
|
|
DSErrMsg(error_code, 325, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); |
|
|
|
|
|
|
|
|
|
@ -220,7 +272,11 @@ void __fastcall sound_CreateSoundBuffer(TSnd *sound_file)
|
|
|
|
|
DSB.dwSize = sizeof(DSBUFFERDESC); |
|
|
|
|
DSB.dwFlags = DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN | DSBCAPS_STATIC; |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
error_code = sglpDS->CreateSoundBuffer(&DSB, &sound_file->DSB, NULL); |
|
|
|
|
#else |
|
|
|
|
error_code = sglpDS->lpVtbl->CreateSoundBuffer(sglpDS, &DSB, &sound_file->DSB, NULL); |
|
|
|
|
#endif |
|
|
|
|
if (error_code != ERROR_SUCCESS) |
|
|
|
|
DSErrMsg(error_code, 282, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); |
|
|
|
|
} |
|
|
|
|
@ -229,8 +285,13 @@ void __fastcall sound_file_cleanup(TSnd *sound_file)
|
|
|
|
|
{ |
|
|
|
|
if (sound_file) { |
|
|
|
|
if (sound_file->DSB) { |
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
sound_file->DSB->Stop(); |
|
|
|
|
sound_file->DSB->Release(); |
|
|
|
|
#else |
|
|
|
|
sound_file->DSB->lpVtbl->Stop(sound_file->DSB); |
|
|
|
|
sound_file->DSB->lpVtbl->Release(sound_file->DSB); |
|
|
|
|
#endif |
|
|
|
|
sound_file->DSB = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -249,7 +310,11 @@ void __fastcall snd_init(HWND hWnd)
|
|
|
|
|
if (sound_DirectSoundCreate(NULL, &sglpDS, NULL) != DS_OK) |
|
|
|
|
sglpDS = NULL; |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
if (sglpDS && sglpDS->SetCooperativeLevel(hWnd, DSSCL_EXCLUSIVE) == DS_OK) |
|
|
|
|
#else |
|
|
|
|
if (sglpDS && sglpDS->lpVtbl->SetCooperativeLevel(sglpDS, hWnd, DSSCL_EXCLUSIVE) == DS_OK) |
|
|
|
|
#endif |
|
|
|
|
sound_create_primary_buffer(0); |
|
|
|
|
|
|
|
|
|
SVidInitialize(sglpDS); |
|
|
|
|
@ -285,7 +350,11 @@ void __fastcall sound_create_primary_buffer(HANDLE music_track)
|
|
|
|
|
dsbuf.dwSize = sizeof(DSBUFFERDESC); |
|
|
|
|
dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER; |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
error_code = sglpDS->CreateSoundBuffer(&dsbuf, &sglpDSB, NULL); |
|
|
|
|
#else |
|
|
|
|
error_code = sglpDS->lpVtbl->CreateSoundBuffer(sglpDS, &dsbuf, &sglpDSB, NULL); |
|
|
|
|
#endif |
|
|
|
|
if (error_code != DS_OK) |
|
|
|
|
DSErrMsg(error_code, 375, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); |
|
|
|
|
} |
|
|
|
|
@ -294,7 +363,11 @@ void __fastcall sound_create_primary_buffer(HANDLE music_track)
|
|
|
|
|
DSCAPS dsbcaps; |
|
|
|
|
dsbcaps.dwSize = sizeof(DSCAPS); |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
error_code = sglpDS->GetCaps(&dsbcaps); |
|
|
|
|
#else |
|
|
|
|
error_code = sglpDS->lpVtbl->GetCaps(sglpDS, &dsbcaps); |
|
|
|
|
#endif |
|
|
|
|
if (error_code != DS_OK) |
|
|
|
|
DSErrMsg(error_code, 383, "C:\\Src\\Diablo\\Source\\SOUND.CPP"); |
|
|
|
|
|
|
|
|
|
@ -310,13 +383,20 @@ void __fastcall sound_create_primary_buffer(HANDLE music_track)
|
|
|
|
|
format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8; |
|
|
|
|
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
sglpDSB->SetFormat(&format); |
|
|
|
|
#else |
|
|
|
|
sglpDSB->lpVtbl->SetFormat(sglpDSB, &format); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 69F100: using guessed type int sglpDSB;
|
|
|
|
|
|
|
|
|
|
HRESULT __fastcall sound_DirectSoundCreate(LPGUID lpGuid, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter) |
|
|
|
|
{ |
|
|
|
|
HRESULT(WINAPI * DirectSoundCreate) |
|
|
|
|
(LPGUID lpGuid, LPDIRECTSOUND * ppDS, LPUNKNOWN pUnkOuter); |
|
|
|
|
|
|
|
|
|
if (hDsound_dll == NULL) { |
|
|
|
|
hDsound_dll = LoadLibrary("dsound.dll"); |
|
|
|
|
if (hDsound_dll == NULL) { |
|
|
|
|
@ -324,8 +404,6 @@ HRESULT __fastcall sound_DirectSoundCreate(LPGUID lpGuid, LPDIRECTSOUND *ppDS, L
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
HRESULT(WINAPI * DirectSoundCreate) |
|
|
|
|
(LPGUID lpGuid, LPDIRECTSOUND * ppDS, LPUNKNOWN pUnkOuter); |
|
|
|
|
DirectSoundCreate = (HRESULT(WINAPI *)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN))GetProcAddress(hDsound_dll, "DirectSoundCreate"); |
|
|
|
|
if (DirectSoundCreate == NULL) { |
|
|
|
|
ErrDlg(IDD_DIALOG5, GetLastError(), "C:\\Src\\Diablo\\Source\\SOUND.CPP", 427); |
|
|
|
|
@ -340,7 +418,11 @@ void __cdecl sound_cleanup()
|
|
|
|
|
SFileDdaDestroy(); |
|
|
|
|
|
|
|
|
|
if (sglpDS) { |
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
sglpDS->Release(); |
|
|
|
|
#else |
|
|
|
|
sglpDS->lpVtbl->Release(sglpDS); |
|
|
|
|
#endif |
|
|
|
|
sglpDS = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|