Wrap DirectSound

See #17, #24
This commit is contained in:
Alexander Batalov 2022-05-29 20:07:43 +03:00
parent 6dd55e4ee9
commit ca68373e74
11 changed files with 200 additions and 11 deletions

View File

@ -233,6 +233,7 @@ add_executable(${EXECUTABLE_NAME} WIN32
) )
target_sources(${EXECUTABLE_NAME} PUBLIC target_sources(${EXECUTABLE_NAME} PUBLIC
"src/dsound_compat.h"
"src/fps_limiter.cc" "src/fps_limiter.cc"
"src/fps_limiter.h" "src/fps_limiter.h"
"src/platform_compat.cc" "src/platform_compat.cc"

View File

@ -28,6 +28,7 @@
#include "tile.h" #include "tile.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
// 0x51805C // 0x51805C
@ -1399,7 +1400,6 @@ Object* _ai_danger_source(Object* a1)
attackWho = -1; attackWho = -1;
} }
Object* whoHitMe = a1->data.critter.combat.whoHitMe; Object* whoHitMe = a1->data.critter.combat.whoHitMe;
if (whoHitMe == NULL || a1 == whoHitMe) { if (whoHitMe == NULL || a1 == whoHitMe) {
targets[0] = NULL; targets[0] = NULL;

17
src/dsound_compat.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef DSOUND_COMPAT_H
#define DSOUND_COMPAT_H
#ifdef _WIN32
#define HAVE_DSOUND 1
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <mmreg.h>
#define DIRECTSOUND_VERSION 0x0300
#include <dsound.h>
#endif
#endif /* DSOUND_COMPAT_H */

View File

@ -330,8 +330,12 @@ int _noop()
void movieInit() void movieInit()
{ {
movieLibSetMemoryProcs(movieMallocImpl, movieFreeImpl); movieLibSetMemoryProcs(movieMallocImpl, movieFreeImpl);
#ifdef HAVE_DSOUND
movieLibSetDirectSound(gDirectSound); movieLibSetDirectSound(gDirectSound);
gMovieDirectSoundInitialized = (gDirectSound != NULL); gMovieDirectSoundInitialized = (gDirectSound != NULL);
#else
gMovieDirectSoundInitialized = false;
#endif
movieLibSetPaletteEntriesProc(movieSetPaletteEntriesImpl); movieLibSetPaletteEntriesProc(movieSetPaletteEntriesImpl);
_MVE_sfSVGA(640, 480, 480, 0, 0, 0, 0, 0, 0); _MVE_sfSVGA(640, 480, 480, 0, 0, 0, 0, 0, 0);
movieLibSetReadProc(movieReadImpl); movieLibSetReadProc(movieReadImpl);

View File

@ -63,11 +63,15 @@ int _sync_late = 0;
// 0x51EDEC // 0x51EDEC
int _sync_FrameDropped = 0; int _sync_FrameDropped = 0;
#ifdef HAVE_DSOUND
// 0x51EDF0 // 0x51EDF0
LPDIRECTSOUND gMovieLibDirectSound = NULL; LPDIRECTSOUND gMovieLibDirectSound = NULL;
#endif
#ifdef HAVE_DSOUND
// 0x51EDF4 // 0x51EDF4
LPDIRECTSOUNDBUFFER gMovieLibDirectSoundBuffer = NULL; LPDIRECTSOUNDBUFFER gMovieLibDirectSoundBuffer = NULL;
#endif
// 0x51EDF8 // 0x51EDF8
int gMovieLibVolume = 0; int gMovieLibVolume = 0;
@ -261,8 +265,10 @@ unsigned int _$$R0063[256] = {
// 0x6B3660 // 0x6B3660
int dword_6B3660; int dword_6B3660;
#ifdef HAVE_DSOUND
// 0x6B3668 // 0x6B3668
DSBCAPS stru_6B3668; DSBCAPS stru_6B3668;
#endif
// 0x6B367C // 0x6B367C
int _sf_ScreenWidth; int _sf_ScreenWidth;
@ -469,20 +475,24 @@ void _MVE_MemFree(STRUCT_6B3690* a1)
a1->field_4 = 0; a1->field_4 = 0;
} }
#ifdef HAVE_DSOUND
// 0x4F48F0 // 0x4F48F0
void movieLibSetDirectSound(LPDIRECTSOUND ds) void movieLibSetDirectSound(LPDIRECTSOUND ds)
{ {
gMovieLibDirectSound = ds; gMovieLibDirectSound = ds;
} }
#endif
// 0x4F4900 // 0x4F4900
void movieLibSetVolume(int volume) void movieLibSetVolume(int volume)
{ {
gMovieLibVolume = volume; gMovieLibVolume = volume;
#ifdef HAVE_DSOUND
if (gMovieLibDirectSoundBuffer != NULL) { if (gMovieLibDirectSoundBuffer != NULL) {
IDirectSoundBuffer_SetVolume(gMovieLibDirectSoundBuffer, volume); IDirectSoundBuffer_SetVolume(gMovieLibDirectSoundBuffer, volume);
} }
#endif
} }
// 0x4F4920 // 0x4F4920
@ -490,9 +500,11 @@ void movieLibSetPan(int pan)
{ {
gMovieLibPan = pan; gMovieLibPan = pan;
#ifdef HAVE_DSOUND
if (gMovieLibDirectSoundBuffer != NULL) { if (gMovieLibDirectSoundBuffer != NULL) {
IDirectSoundBuffer_SetPan(gMovieLibDirectSoundBuffer, pan); IDirectSoundBuffer_SetPan(gMovieLibDirectSoundBuffer, pan);
} }
#endif
} }
// 0x4F4940 // 0x4F4940
@ -733,9 +745,11 @@ int _syncWait()
// 0x4F4EA0 // 0x4F4EA0
void _MVE_sndPause() void _MVE_sndPause()
{ {
#ifdef HAVE_DSOUND
if (gMovieLibDirectSoundBuffer != NULL) { if (gMovieLibDirectSoundBuffer != NULL) {
IDirectSoundBuffer_Stop(gMovieLibDirectSoundBuffer); IDirectSoundBuffer_Stop(gMovieLibDirectSoundBuffer);
} }
#endif
} }
// 0x4F4EC0 // 0x4F4EC0
@ -1051,6 +1065,7 @@ void _syncReset(int a1)
// 0x4F5570 // 0x4F5570
int _MVE_sndConfigure(int a1, int a2, int a3, int a4, int a5, int a6) int _MVE_sndConfigure(int a1, int a2, int a3, int a4, int a5, int a6)
{ {
#ifdef HAVE_DSOUND
DSBUFFERDESC dsbd; DSBUFFERDESC dsbd;
WAVEFORMATEX wfxFormat; WAVEFORMATEX wfxFormat;
@ -1096,6 +1111,9 @@ int _MVE_sndConfigure(int a1, int a2, int a3, int a4, int a5, int a6)
} }
return 1; return 1;
#else
return 0;
#endif
} }
// 0x4F56C0 // 0x4F56C0
@ -1110,16 +1128,19 @@ void _MVE_syncSync()
// 0x4F56F0 // 0x4F56F0
void _MVE_sndReset() void _MVE_sndReset()
{ {
#ifdef HAVE_DSOUND
if (gMovieLibDirectSoundBuffer != NULL) { if (gMovieLibDirectSoundBuffer != NULL) {
IDirectSoundBuffer_Stop(gMovieLibDirectSoundBuffer); IDirectSoundBuffer_Stop(gMovieLibDirectSoundBuffer);
IDirectSoundBuffer_Release(gMovieLibDirectSoundBuffer); IDirectSoundBuffer_Release(gMovieLibDirectSoundBuffer);
gMovieLibDirectSoundBuffer = NULL; gMovieLibDirectSoundBuffer = NULL;
} }
#endif
} }
// 0x4F5720 // 0x4F5720
void _MVE_sndSync() void _MVE_sndSync()
{ {
#ifdef HAVE_DSOUND
DWORD dwCurrentPlayCursor; DWORD dwCurrentPlayCursor;
DWORD dwCurrentWriteCursor; DWORD dwCurrentWriteCursor;
bool v10; bool v10;
@ -1257,6 +1278,10 @@ void _MVE_sndSync()
++dword_6B3660; ++dword_6B3660;
} }
} }
#else
_sync_late = _syncWaitLevel(_sync_wait_quanta >> 2) > -_sync_wait_quanta >> 1 && !_sync_FrameDropped;
_sync_FrameDropped = 0;
#endif
} }
// 0x4F59B0 // 0x4F59B0
@ -1282,6 +1307,7 @@ int _syncWaitLevel(int a1)
// 0x4F5A00 // 0x4F5A00
void _CallsSndBuff_Loc(unsigned char* a1, int a2) void _CallsSndBuff_Loc(unsigned char* a1, int a2)
{ {
#ifdef HAVE_DSOUND
int v2; int v2;
int v3; int v3;
int v5; int v5;
@ -1343,6 +1369,7 @@ void _CallsSndBuff_Loc(unsigned char* a1, int a2)
} else { } else {
++dword_6B3AE4; ++dword_6B3AE4;
} }
#endif
} }
// 0x4F5B70 // 0x4F5B70

View File

@ -1,13 +1,11 @@
#ifndef MOVIE_LIB_H #ifndef MOVIE_LIB_H
#define MOVIE_LIB_H #define MOVIE_LIB_H
#include "dsound_compat.h"
#include "memory_defs.h" #include "memory_defs.h"
#include <SDL.h> #include <SDL.h>
#define DIRECTSOUND_VERSION 0x0300
#include <dsound.h>
typedef struct STRUCT_6B3690 { typedef struct STRUCT_6B3690 {
void* field_0; void* field_0;
int field_4; int field_4;
@ -56,8 +54,10 @@ extern unsigned short word_51EBE0[256];
extern int _sync_active; extern int _sync_active;
extern int _sync_late; extern int _sync_late;
extern int _sync_FrameDropped; extern int _sync_FrameDropped;
#ifdef HAVE_DSOUND
extern LPDIRECTSOUND gMovieLibDirectSound; extern LPDIRECTSOUND gMovieLibDirectSound;
extern LPDIRECTSOUNDBUFFER gMovieLibDirectSoundBuffer; extern LPDIRECTSOUNDBUFFER gMovieLibDirectSoundBuffer;
#endif
extern int gMovieLibVolume; extern int gMovieLibVolume;
extern int gMovieLibPan; extern int gMovieLibPan;
extern MovieShowFrameProc* _sf_ShowFrame; extern MovieShowFrameProc* _sf_ShowFrame;
@ -74,7 +74,9 @@ extern unsigned int _$$R0004[256];
extern unsigned int _$$R0063[256]; extern unsigned int _$$R0063[256];
extern int dword_6B3660; extern int dword_6B3660;
#ifdef HAVE_DSOUND
extern DSBCAPS stru_6B3668; extern DSBCAPS stru_6B3668;
#endif
extern int _sf_ScreenWidth; extern int _sf_ScreenWidth;
extern int dword_6B3680; extern int dword_6B3680;
extern int _rm_FrameDropCount; extern int _rm_FrameDropCount;
@ -138,7 +140,9 @@ void movieLibSetMemoryProcs(MallocProc* mallocProc, FreeProc* freeProc);
void movieLibSetReadProc(MovieReadProc* readProc); void movieLibSetReadProc(MovieReadProc* readProc);
void _MVE_MemInit(STRUCT_6B3690* a1, int a2, void* a3); void _MVE_MemInit(STRUCT_6B3690* a1, int a2, void* a3);
void _MVE_MemFree(STRUCT_6B3690* a1); void _MVE_MemFree(STRUCT_6B3690* a1);
#ifdef HAVE_DSOUND
void movieLibSetDirectSound(LPDIRECTSOUND ds); void movieLibSetDirectSound(LPDIRECTSOUND ds);
#endif
void movieLibSetVolume(int volume); void movieLibSetVolume(int volume);
void movieLibSetPan(int pan); void movieLibSetPan(int pan);
void _MVE_sfSVGA(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9); void _MVE_sfSVGA(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9);

View File

@ -25,6 +25,7 @@
#include "window_manager_private.h" #include "window_manager_private.h"
#include "world_map.h" #include "world_map.h"
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>

View File

@ -80,6 +80,7 @@ const char* gSoundErrorDescriptions[SOUND_ERR_COUNT] = {
"sound.c: invalid handle", "sound.c: invalid handle",
"sound.c: no memory available", "sound.c: no memory available",
"sound.c: unknown error", "sound.c: unknown error",
"sound.c: not implemented",
}; };
// 0x668150 // 0x668150
@ -88,8 +89,10 @@ int gSoundLastError;
// 0x668154 // 0x668154
int _masterVol; int _masterVol;
#ifdef HAVE_DSOUND
// 0x668158 // 0x668158
LPDIRECTSOUNDBUFFER gDirectSoundPrimaryBuffer; LPDIRECTSOUNDBUFFER gDirectSoundPrimaryBuffer;
#endif
// 0x66815C // 0x66815C
int _sampleRate; int _sampleRate;
@ -114,8 +117,10 @@ bool gSoundInitialized;
// 0x668174 // 0x668174
Sound* gSoundListHead; Sound* gSoundListHead;
#ifdef HAVE_DSOUND
// 0x668178 // 0x668178
LPDIRECTSOUND gDirectSound; LPDIRECTSOUND gDirectSound;
#endif
// 0x4AC6F0 // 0x4AC6F0
void* soundMallocProcDefaultImpl(size_t size) void* soundMallocProcDefaultImpl(size_t size)
@ -166,6 +171,7 @@ const char* soundGetErrorDescription(int err)
// 0x4AC7B0 // 0x4AC7B0
void _refreshSoundBuffers(Sound* sound) void _refreshSoundBuffers(Sound* sound)
{ {
#ifdef HAVE_DSOUND
if (sound->field_3C & 0x80) { if (sound->field_3C & 0x80) {
return; return;
} }
@ -340,11 +346,13 @@ void _refreshSoundBuffers(Sound* sound)
sound->field_70 = v6; sound->field_70 = v6;
return; return;
#endif
} }
// 0x4ACC58 // 0x4ACC58
int soundInit(int a1, int a2, int a3, int a4, int rate) int soundInit(int a1, int a2, int a3, int a4, int rate)
{ {
#ifdef HAVE_DSOUND
HRESULT hr; HRESULT hr;
DWORD v24; DWORD v24;
@ -475,11 +483,16 @@ out:
gSoundLastError = SOUND_NO_ERROR; gSoundLastError = SOUND_NO_ERROR;
return 0; return 0;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4AD04C // 0x4AD04C
void soundExit() void soundExit()
{ {
#ifdef HAVE_DSOUND
while (gSoundListHead != NULL) { while (gSoundListHead != NULL) {
Sound* next = gSoundListHead->next; Sound* next = gSoundListHead->next;
soundDelete(gSoundListHead); soundDelete(gSoundListHead);
@ -508,11 +521,13 @@ void soundExit()
gSoundLastError = SOUND_NO_ERROR; gSoundLastError = SOUND_NO_ERROR;
gSoundInitialized = false; gSoundInitialized = false;
#endif
} }
// 0x4AD0FC // 0x4AD0FC
Sound* soundAllocate(int a1, int a2) Sound* soundAllocate(int a1, int a2)
{ {
#ifdef HAVE_DSOUND
if (!gSoundInitialized) { if (!gSoundInitialized) {
gSoundLastError = SOUND_NOT_INITIALIZED; gSoundLastError = SOUND_NOT_INITIALIZED;
return NULL; return NULL;
@ -588,6 +603,10 @@ Sound* soundAllocate(int a1, int a2)
gSoundListHead = sound; gSoundListHead = sound;
return sound; return sound;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return NULL;
#endif
} }
// 0x4AD308 // 0x4AD308
@ -680,6 +699,7 @@ int soundLoad(Sound* sound, char* filePath)
// 0x4AD504 // 0x4AD504
int _soundRewind(Sound* sound) int _soundRewind(Sound* sound)
{ {
#ifdef HAVE_DSOUND
HRESULT hr; HRESULT hr;
if (!gSoundInitialized) { if (!gSoundInitialized) {
@ -713,11 +733,16 @@ int _soundRewind(Sound* sound)
gSoundLastError = SOUND_NO_ERROR; gSoundLastError = SOUND_NO_ERROR;
return gSoundLastError; return gSoundLastError;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4AD5C8 // 0x4AD5C8
int _addSoundData(Sound* sound, unsigned char* buf, int size) int _addSoundData(Sound* sound, unsigned char* buf, int size)
{ {
#ifdef HAVE_DSOUND
HRESULT hr; HRESULT hr;
void* audio_ptr_1; void* audio_ptr_1;
DWORD audio_bytes_1; DWORD audio_bytes_1;
@ -749,11 +774,16 @@ int _addSoundData(Sound* sound, unsigned char* buf, int size)
gSoundLastError = SOUND_NO_ERROR; gSoundLastError = SOUND_NO_ERROR;
return gSoundLastError; return gSoundLastError;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4AD6C0 // 0x4AD6C0
int _soundSetData(Sound* sound, unsigned char* buf, int size) int _soundSetData(Sound* sound, unsigned char* buf, int size)
{ {
#ifdef HAVE_DSOUND
if (!gSoundInitialized) { if (!gSoundInitialized) {
gSoundLastError = SOUND_NOT_INITIALIZED; gSoundLastError = SOUND_NOT_INITIALIZED;
return gSoundLastError; return gSoundLastError;
@ -774,11 +804,16 @@ int _soundSetData(Sound* sound, unsigned char* buf, int size)
} }
return _addSoundData(sound, buf, size); return _addSoundData(sound, buf, size);
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4AD73C // 0x4AD73C
int soundPlay(Sound* sound) int soundPlay(Sound* sound)
{ {
#ifdef HAVE_DSOUND
HRESULT hr; HRESULT hr;
DWORD readPos; DWORD readPos;
DWORD writePos; DWORD writePos;
@ -816,11 +851,16 @@ int soundPlay(Sound* sound)
gSoundLastError = SOUND_NO_ERROR; gSoundLastError = SOUND_NO_ERROR;
return gSoundLastError; return gSoundLastError;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4AD828 // 0x4AD828
int soundStop(Sound* sound) int soundStop(Sound* sound)
{ {
#ifdef HAVE_DSOUND
HRESULT hr; HRESULT hr;
if (!gSoundInitialized) { if (!gSoundInitialized) {
@ -849,6 +889,10 @@ int soundStop(Sound* sound)
gSoundLastError = SOUND_NO_ERROR; gSoundLastError = SOUND_NO_ERROR;
return gSoundLastError; return gSoundLastError;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4AD8DC // 0x4AD8DC
@ -878,6 +922,7 @@ int soundDelete(Sound* sample)
// 0x4AD948 // 0x4AD948
int soundContinue(Sound* sound) int soundContinue(Sound* sound)
{ {
#ifdef HAVE_DSOUND
HRESULT hr; HRESULT hr;
DWORD status; DWORD status;
@ -942,11 +987,16 @@ int soundContinue(Sound* sound)
gSoundLastError = SOUND_NO_ERROR; gSoundLastError = SOUND_NO_ERROR;
return gSoundLastError; return gSoundLastError;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4ADA84 // 0x4ADA84
bool soundIsPlaying(Sound* sound) bool soundIsPlaying(Sound* sound)
{ {
#ifdef HAVE_DSOUND
if (!gSoundInitialized) { if (!gSoundInitialized) {
gSoundLastError = SOUND_NOT_INITIALIZED; gSoundLastError = SOUND_NOT_INITIALIZED;
return false; return false;
@ -958,11 +1008,16 @@ bool soundIsPlaying(Sound* sound)
} }
return (sound->field_40 & SOUND_FLAG_SOUND_IS_PLAYING) != 0; return (sound->field_40 & SOUND_FLAG_SOUND_IS_PLAYING) != 0;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return false;
#endif
} }
// 0x4ADAC4 // 0x4ADAC4
bool _soundDone(Sound* sound) bool _soundDone(Sound* sound)
{ {
#ifdef HAVE_DSOUND
if (!gSoundInitialized) { if (!gSoundInitialized) {
gSoundLastError = SOUND_NOT_INITIALIZED; gSoundLastError = SOUND_NOT_INITIALIZED;
return false; return false;
@ -974,11 +1029,16 @@ bool _soundDone(Sound* sound)
} }
return sound->field_40 & 1; return sound->field_40 & 1;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return false;
#endif
} }
// 0x4ADB44 // 0x4ADB44
bool soundIsPaused(Sound* sound) bool soundIsPaused(Sound* sound)
{ {
#ifdef HAVE_DSOUND
if (!gSoundInitialized) { if (!gSoundInitialized) {
gSoundLastError = SOUND_NOT_INITIALIZED; gSoundLastError = SOUND_NOT_INITIALIZED;
return false; return false;
@ -990,11 +1050,16 @@ bool soundIsPaused(Sound* sound)
} }
return (sound->field_40 & SOUND_FLAG_SOUND_IS_PAUSED) != 0; return (sound->field_40 & SOUND_FLAG_SOUND_IS_PAUSED) != 0;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return false;
#endif
} }
// 0x4ADBC4 // 0x4ADBC4
int _soundType(Sound* sound, int a2) int _soundType(Sound* sound, int a2)
{ {
#ifdef HAVE_DSOUND
if (!gSoundInitialized) { if (!gSoundInitialized) {
gSoundLastError = SOUND_NOT_INITIALIZED; gSoundLastError = SOUND_NOT_INITIALIZED;
return 0; return 0;
@ -1006,11 +1071,16 @@ int _soundType(Sound* sound, int a2)
} }
return sound->field_44 & a2; return sound->field_44 & a2;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return 0;
#endif
} }
// 0x4ADC04 // 0x4ADC04
int soundGetDuration(Sound* sound) int soundGetDuration(Sound* sound)
{ {
#ifdef HAVE_DSOUND
if (!gSoundInitialized) { if (!gSoundInitialized) {
gSoundLastError = SOUND_NOT_INITIALIZED; gSoundLastError = SOUND_NOT_INITIALIZED;
return gSoundLastError; return gSoundLastError;
@ -1030,6 +1100,10 @@ int soundGetDuration(Sound* sound)
} }
return result; return result;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4ADD00 // 0x4ADD00
@ -1083,6 +1157,7 @@ int _soundVolumeHMItoDirectSound(int volume)
// 0x4ADE0C // 0x4ADE0C
int soundSetVolume(Sound* sound, int volume) int soundSetVolume(Sound* sound, int volume)
{ {
#ifdef HAVE_DSOUND
int normalizedVolume; int normalizedVolume;
HRESULT hr; HRESULT hr;
@ -1113,11 +1188,16 @@ int soundSetVolume(Sound* sound, int volume)
gSoundLastError = SOUND_NO_ERROR; gSoundLastError = SOUND_NO_ERROR;
return gSoundLastError; return gSoundLastError;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4ADE80 // 0x4ADE80
int _soundGetVolume(Sound* sound) int _soundGetVolume(Sound* sound)
{ {
#ifdef HAVE_DSOUND
long volume; long volume;
int v13; int v13;
int v8; int v8;
@ -1150,6 +1230,10 @@ int _soundGetVolume(Sound* sound)
} }
return sound->volume; return sound->volume;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4ADFF0 // 0x4ADFF0
@ -1175,6 +1259,7 @@ int soundSetCallback(Sound* sound, SoundCallback* callback, void* userData)
// 0x4AE02C // 0x4AE02C
int soundSetChannels(Sound* sound, int channels) int soundSetChannels(Sound* sound, int channels)
{ {
#ifdef HAVE_DSOUND
LPWAVEFORMATEX format; LPWAVEFORMATEX format;
if (!gSoundInitialized) { if (!gSoundInitialized) {
@ -1197,6 +1282,10 @@ int soundSetChannels(Sound* sound, int channels)
gSoundLastError = SOUND_NO_ERROR; gSoundLastError = SOUND_NO_ERROR;
return gSoundLastError; return gSoundLastError;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4AE0B0 // 0x4AE0B0
@ -1223,6 +1312,7 @@ int soundSetReadLimit(Sound* sound, int readLimit)
// 0x4AE0E4 // 0x4AE0E4
int soundPause(Sound* sound) int soundPause(Sound* sound)
{ {
#ifdef HAVE_DSOUND
HRESULT hr; HRESULT hr;
DWORD readPos; DWORD readPos;
DWORD writePos; DWORD writePos;
@ -1262,6 +1352,10 @@ int soundPause(Sound* sound)
sound->field_40 |= SOUND_FLAG_SOUND_IS_PAUSED; sound->field_40 |= SOUND_FLAG_SOUND_IS_PAUSED;
return soundStop(sound); return soundStop(sound);
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// TODO: Check, looks like it uses couple of inlined functions. // TODO: Check, looks like it uses couple of inlined functions.
@ -1269,6 +1363,7 @@ int soundPause(Sound* sound)
// 0x4AE1F0 // 0x4AE1F0
int soundResume(Sound* sound) int soundResume(Sound* sound)
{ {
#ifdef HAVE_DSOUND
HRESULT hr; HRESULT hr;
if (!gSoundInitialized) { if (!gSoundInitialized) {
@ -1301,6 +1396,10 @@ int soundResume(Sound* sound)
sound->field_48 = 0; sound->field_48 = 0;
return soundPlay(sound); return soundPlay(sound);
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4AE2FC // 0x4AE2FC
@ -1351,6 +1450,7 @@ int soundSetFileIO(Sound* sound, SoundOpenProc* openProc, SoundCloseProc* closeP
// 0x4AE378 // 0x4AE378
void soundDeleteInternal(Sound* sound) void soundDeleteInternal(Sound* sound)
{ {
#ifdef HAVE_DSOUND
STRUCT_51D478* curr; STRUCT_51D478* curr;
Sound* v10; Sound* v10;
Sound* v11; Sound* v11;
@ -1409,6 +1509,7 @@ void soundDeleteInternal(Sound* sound)
} }
gSoundFreeProc(sound); gSoundFreeProc(sound);
#endif
} }
// 0x4AE578 // 0x4AE578
@ -1454,6 +1555,7 @@ void _removeTimedEvent(unsigned int* timerId)
// 0x4AE634 // 0x4AE634
int _soundGetPosition(Sound* sound) int _soundGetPosition(Sound* sound)
{ {
#ifdef HAVE_DSOUND
if (!gSoundInitialized) { if (!gSoundInitialized) {
gSoundLastError = SOUND_NOT_INITIALIZED; gSoundLastError = SOUND_NOT_INITIALIZED;
return gSoundLastError; return gSoundLastError;
@ -1477,11 +1579,16 @@ int _soundGetPosition(Sound* sound)
} }
return playPos; return playPos;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4AE6CC // 0x4AE6CC
int _soundSetPosition(Sound* sound, int a2) int _soundSetPosition(Sound* sound, int a2)
{ {
#ifdef HAVE_DSOUND
if (!gSoundInitialized) { if (!gSoundInitialized) {
gSoundLastError = SOUND_NOT_INITIALIZED; gSoundLastError = SOUND_NOT_INITIALIZED;
return gSoundLastError; return gSoundLastError;
@ -1529,6 +1636,10 @@ int _soundSetPosition(Sound* sound, int a2)
gSoundLastError = SOUND_NO_ERROR; gSoundLastError = SOUND_NO_ERROR;
return gSoundLastError; return gSoundLastError;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4AE830 // 0x4AE830
@ -1613,6 +1724,7 @@ void _fadeSounds()
// 0x4AE988 // 0x4AE988
int _internalSoundFade(Sound* sound, int a2, int a3, int a4) int _internalSoundFade(Sound* sound, int a2, int a3, int a4)
{ {
#ifdef HAVE_DSOUND
STRUCT_51D478* ptr; STRUCT_51D478* ptr;
if (!_deviceInit) { if (!_deviceInit) {
@ -1701,6 +1813,10 @@ int _internalSoundFade(Sound* sound, int a2, int a3, int a4)
gSoundLastError = SOUND_NO_ERROR; gSoundLastError = SOUND_NO_ERROR;
return gSoundLastError; return gSoundLastError;
#else
gSoundLastError = SOUND_NOT_IMPLEMENTED;
return gSoundLastError;
#endif
} }
// 0x4AEB0C // 0x4AEB0C

View File

@ -44,6 +44,8 @@ typedef enum SoundError {
SOUND_INVALID_HANDLE = 30, SOUND_INVALID_HANDLE = 30,
SOUND_NO_MEMORY_AVAILABLE = 31, SOUND_NO_MEMORY_AVAILABLE = 31,
SOUND_UNKNOWN_ERROR = 32, SOUND_UNKNOWN_ERROR = 32,
// TODO: Remove once DirectX -> SDL transition is completed.
SOUND_NOT_IMPLEMENTED = 33,
SOUND_ERR_COUNT, SOUND_ERR_COUNT,
} SoundError; } SoundError;
@ -72,8 +74,10 @@ typedef void SoundCallback(void* userData, int a2);
typedef struct Sound { typedef struct Sound {
SoundFileIO io; SoundFileIO io;
unsigned char* field_20; unsigned char* field_20;
#ifdef HAVE_DSOUND
LPDIRECTSOUNDBUFFER directSoundBuffer; LPDIRECTSOUNDBUFFER directSoundBuffer;
DSBUFFERDESC directSoundBufferDescription; DSBUFFERDESC directSoundBufferDescription;
#endif
int field_3C; int field_3C;
// flags // flags
int field_40; int field_40;
@ -128,7 +132,9 @@ extern const char* gSoundErrorDescriptions[SOUND_ERR_COUNT];
extern int gSoundLastError; extern int gSoundLastError;
extern int _masterVol; extern int _masterVol;
#ifdef HAVE_DSOUND
extern LPDIRECTSOUNDBUFFER gDirectSoundPrimaryBuffer; extern LPDIRECTSOUNDBUFFER gDirectSoundPrimaryBuffer;
#endif
extern int _sampleRate; extern int _sampleRate;
extern int _numSounds; extern int _numSounds;
extern int _deviceInit; extern int _deviceInit;
@ -136,7 +142,9 @@ extern int _dataSize;
extern int _numBuffers; extern int _numBuffers;
extern bool gSoundInitialized; extern bool gSoundInitialized;
extern Sound* gSoundListHead; extern Sound* gSoundListHead;
#ifdef HAVE_DSOUND
extern LPDIRECTSOUND gDirectSound; extern LPDIRECTSOUND gDirectSound;
#endif
void* soundMallocProcDefaultImpl(size_t size); void* soundMallocProcDefaultImpl(size_t size);
void* soundReallocProcDefaultImpl(void* ptr, size_t size); void* soundReallocProcDefaultImpl(void* ptr, size_t size);

View File

@ -5,9 +5,12 @@
#include "window_manager.h" #include "window_manager.h"
#include <SDL.h> #include <SDL.h>
#include <stdlib.h>
#ifdef HAVE_DSOUND
// 0x51E430 // 0x51E430
DirectSoundCreateProc* gDirectSoundCreateProc = NULL; DirectSoundCreateProc* gDirectSoundCreateProc = NULL;
#endif
// 0x51E434 // 0x51E434
HWND gProgramWindow = NULL; HWND gProgramWindow = NULL;
@ -18,8 +21,10 @@ bool gProgramIsActive = false;
// GNW95MUTEX // GNW95MUTEX
HANDLE _GNW95_mutex = NULL; HANDLE _GNW95_mutex = NULL;
#ifdef HAVE_DSOUND
// 0x51E454 // 0x51E454
HMODULE gDSoundDLL = NULL; HMODULE gDSoundDLL = NULL;
#endif
// 0x4DE700 // 0x4DE700
int main(int argc, char* argv[]) int main(int argc, char* argv[])
@ -39,6 +44,7 @@ int main(int argc, char* argv[])
// 0x4DE8D0 // 0x4DE8D0
bool _LoadDirectX() bool _LoadDirectX()
{ {
#ifdef HAVE_DSOUND
gDSoundDLL = LoadLibraryA("DSOUND.DLL"); gDSoundDLL = LoadLibraryA("DSOUND.DLL");
if (gDSoundDLL == NULL) { if (gDSoundDLL == NULL) {
goto err; goto err;
@ -48,6 +54,7 @@ bool _LoadDirectX()
if (gDirectSoundCreateProc == NULL) { if (gDirectSoundCreateProc == NULL) {
goto err; goto err;
} }
#endif
atexit(_UnloadDirectX); atexit(_UnloadDirectX);
@ -55,7 +62,7 @@ bool _LoadDirectX()
err: err:
_UnloadDirectX(); _UnloadDirectX();
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not load DirectX", "This program requires DirectX 3.0a or later.", NULL); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not load DirectX", "This program requires DirectX 3.0a or later.", NULL);
return false; return false;
@ -64,8 +71,10 @@ err:
// 0x4DE988 // 0x4DE988
void _UnloadDirectX(void) void _UnloadDirectX(void)
{ {
#ifdef HAVE_DSOUND
if (gDSoundDLL != NULL) { if (gDSoundDLL != NULL) {
FreeLibrary(gDSoundDLL); FreeLibrary(gDSoundDLL);
gDSoundDLL = NULL; gDSoundDLL = NULL;
} }
#endif
} }

View File

@ -1,23 +1,25 @@
#ifndef WIN32_H #ifndef WIN32_H
#define WIN32_H #define WIN32_H
#include "dsound_compat.h"
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOMINMAX #define NOMINMAX
#include <windows.h> #include <windows.h>
#include <mmreg.h> #ifdef HAVE_DSOUND
#define DIRECTSOUND_VERSION 0x0300
#include <dsound.h>
typedef HRESULT(__stdcall DirectSoundCreateProc)(GUID*, LPDIRECTSOUND*, IUnknown*); typedef HRESULT(__stdcall DirectSoundCreateProc)(GUID*, LPDIRECTSOUND*, IUnknown*);
#endif
#ifdef HAVE_DSOUND
extern DirectSoundCreateProc* gDirectSoundCreateProc; extern DirectSoundCreateProc* gDirectSoundCreateProc;
#endif
extern HWND gProgramWindow; extern HWND gProgramWindow;
extern bool gProgramIsActive; extern bool gProgramIsActive;
extern HANDLE _GNW95_mutex; extern HANDLE _GNW95_mutex;
#ifdef HAVE_DSOUND
extern HMODULE gDSoundDLL; extern HMODULE gDSoundDLL;
#endif
bool _LoadDirectX(); bool _LoadDirectX();
void _UnloadDirectX(void); void _UnloadDirectX(void);