From 501ae1161de1a67e91dad38d712032a736b8201d Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Mon, 30 May 2022 00:40:09 +0300 Subject: [PATCH] Wrap sound stuff See #17, #24 --- src/platform_compat.cc | 20 ++++++++++++++++++++ src/platform_compat.h | 4 ++++ src/sound.cc | 17 +++++++++++++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/platform_compat.cc b/src/platform_compat.cc index 837903f..b71be7b 100644 --- a/src/platform_compat.cc +++ b/src/platform_compat.cc @@ -101,6 +101,26 @@ void compat_makepath(char* path, const char* drive, const char* dir, const char* #endif } +int compat_read(int fileHandle, void* buf, unsigned int size) +{ + return read(fileHandle, buf, size); +} + +int compat_write(int fileHandle, const void* buf, unsigned int size) +{ + return write(fileHandle, buf, size); +} + +long compat_lseek(int fileHandle, long offset, int origin) +{ + return lseek(fileHandle, offset, origin); +} + +long compat_tell(int fd) +{ + return lseek(fd, 0, SEEK_CUR); +} + long compat_filelength(int fd) { long originalOffset = lseek(fd, 0, SEEK_CUR); diff --git a/src/platform_compat.h b/src/platform_compat.h index 1ba9358..77b762d 100644 --- a/src/platform_compat.h +++ b/src/platform_compat.h @@ -24,6 +24,10 @@ char* compat_strlwr(char* string); char* compat_itoa(int value, char* buffer, int radix); void compat_splitpath(const char* path, char* drive, char* dir, char* fname, char* ext); void compat_makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext); +int compat_read(int fileHandle, void* buf, unsigned int size); +int compat_write(int fileHandle, const void* buf, unsigned int size); +long compat_lseek(int fileHandle, long offset, int origin); +long compat_tell(int fileHandle); long compat_filelength(int fd); int compat_mkdir(const char* path); unsigned int compat_timeGetTime(); diff --git a/src/sound.cc b/src/sound.cc index 00291cb..7170986 100644 --- a/src/sound.cc +++ b/src/sound.cc @@ -4,10 +4,17 @@ #include "memory.h" #include "platform_compat.h" +#ifdef _WIN32 #include +#else +#include +#include +#endif #include #include +#ifdef HAVE_DSOUND #include +#endif #include #include @@ -35,10 +42,10 @@ FreeProc* gSoundFreeProc = soundFreeProcDefaultImpl; SoundFileIO gSoundDefaultFileIO = { open, close, - read, - write, - lseek, - tell, + compat_read, + compat_write, + compat_lseek, + compat_tell, compat_filelength, -1, }; @@ -1718,10 +1725,12 @@ void _fadeSounds() } } +#ifdef HAVE_DSOUND if (_fadeHead == NULL && _fadeEventHandle != -1) { timeKillEvent(_fadeEventHandle); _fadeEventHandle = -1; } +#endif } // 0x4AE988