Review sound IO functions

This commit is contained in:
Alexander Batalov 2023-02-13 11:51:09 +03:00
parent 36b5ceba8a
commit 075de8f837
11 changed files with 73 additions and 35 deletions

View File

@ -58,7 +58,7 @@ static int audioSoundDecoderReadHandler(void* data, void* buffer, unsigned int s
// AudioOpen
// 0x41A2EC
int audioOpen(const char* fname, int flags, ...)
int audioOpen(const char* fname, int flags)
{
char path[80];
snprintf(path, sizeof(path), "%s", fname);

View File

@ -5,7 +5,7 @@ namespace fallout {
typedef bool(AudioQueryCompressedFunc)(char* filePath);
int audioOpen(const char* fname, int mode, ...);
int audioOpen(const char* fname, int mode);
int audioClose(int handle);
int audioRead(int handle, void* buffer, unsigned int size);
long audioSeek(int handle, long offset, int origin);

View File

@ -57,7 +57,7 @@ static int audioFileSoundDecoderReadHandler(void* data, void* buffer, unsigned i
}
// 0x41A88C
int audioFileOpen(const char* fname, int flags, ...)
int audioFileOpen(const char* fname, int flags)
{
char path[COMPAT_MAX_PATH];
strcpy(path, fname);

View File

@ -5,7 +5,7 @@ namespace fallout {
typedef bool(AudioFileQueryCompressedFunc)(char* filePath);
int audioFileOpen(const char* fname, int flags, ...);
int audioFileOpen(const char* fname, int flags);
int audioFileClose(int handle);
int audioFileRead(int handle, void* buf, unsigned int size);
long audioFileSeek(int handle, long offset, int origin);

View File

@ -157,7 +157,7 @@ static int _gsound_speech_volume_get_set(int volume);
static void speechPause();
static void speechResume();
static void _gsound_bkg_proc();
static int gameSoundFileOpen(const char* fname, int access, ...);
static int gameSoundFileOpen(const char* fname, int access);
static long _gsound_write_();
static long gameSoundFileTellNotImplemented(int handle);
static int gameSoundFileWrite(int handle, const void* buf, unsigned int size);
@ -898,7 +898,7 @@ int speechLoad(const char* fname, int a2, int a3, int a4)
return -1;
}
if (soundSetFileIO(gSpeechSound, &audioOpen, &audioClose, &audioRead, NULL, &audioSeek, &gameSoundFileTellNotImplemented, &audioGetSize)) {
if (soundSetFileIO(gSpeechSound, audioOpen, audioClose, audioRead, NULL, audioSeek, gameSoundFileTellNotImplemented, audioGetSize)) {
if (gGameSoundDebugEnabled) {
debugPrint("failed because file IO could not be set for compression.\n");
}
@ -1548,7 +1548,7 @@ void _gsound_bkg_proc()
}
// 0x451A08
int gameSoundFileOpen(const char* fname, int flags, ...)
int gameSoundFileOpen(const char* fname, int flags)
{
if ((flags & 2) != 0) {
return -1;

View File

@ -187,21 +187,6 @@ 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);

View File

@ -29,9 +29,6 @@ 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);

View File

@ -45,6 +45,13 @@ typedef struct FadeSound {
static void* soundMallocProcDefaultImpl(size_t size);
static void* soundReallocProcDefaultImpl(void* ptr, size_t size);
static void soundFreeProcDefaultImpl(void* ptr);
static long soundFileSize(int fileHandle);
static long soundTellData(int fileHandle);
static int soundWriteData(int fileHandle, const void* buf, unsigned int size);
static int soundReadData(int fileHandle, void* buf, unsigned int size);
static int soundOpenData(const char* filePath, int flags);
static long soundSeekData(int fileHandle, long offset, int origin);
static int soundCloseData(int fileHandle);
static char* soundFileManglerDefaultImpl(char* fname);
static void _refreshSoundBuffers(Sound* sound);
static int _preloadBuffers(Sound* sound);
@ -77,13 +84,13 @@ static FreeProc* gSoundFreeProc = soundFreeProcDefaultImpl;
// 0x51D494
static SoundFileIO gSoundDefaultFileIO = {
open,
close,
compat_read,
compat_write,
compat_lseek,
compat_tell,
compat_filelength,
soundOpenData,
soundCloseData,
soundReadData,
soundWriteData,
soundSeekData,
soundTellData,
soundFileSize,
-1,
};
@ -184,6 +191,55 @@ void soundSetMemoryProcs(MallocProc* mallocProc, ReallocProc* reallocProc, FreeP
gSoundFreeProc = freeProc;
}
// 0x4AC71C
static long soundFileSize(int fileHandle)
{
long pos;
long size;
pos = compat_tell(fileHandle);
size = lseek(fileHandle, 0, SEEK_END);
lseek(fileHandle, pos, SEEK_SET);
return size;
}
// 0x4AC750
static long soundTellData(int fileHandle)
{
return compat_tell(fileHandle);
}
// 0x4AC758
static int soundWriteData(int fileHandle, const void* buf, unsigned int size)
{
return write(fileHandle, buf, size);
}
// 0x4AC760
static int soundReadData(int fileHandle, void* buf, unsigned int size)
{
return read(fileHandle, buf, size);
}
// 0x4AC768
static int soundOpenData(const char* filePath, int flags)
{
return open(filePath, flags);
}
// 0x4AC774
static long soundSeekData(int fileHandle, long offset, int origin)
{
return lseek(fileHandle, offset, origin);
}
// 0x4AC77C
static int soundCloseData(int fileHandle)
{
return close(fileHandle);
}
// 0x4AC78C
char* soundFileManglerDefaultImpl(char* fname)
{

View File

@ -46,7 +46,7 @@ typedef enum SoundError {
SOUND_ERR_COUNT,
} SoundError;
typedef int SoundOpenProc(const char* filePath, int flags, ...);
typedef int SoundOpenProc(const char* filePath, int flags);
typedef int SoundCloseProc(int fileHandle);
typedef int SoundReadProc(int fileHandle, void* buf, unsigned int size);
typedef int SoundWriteProc(int fileHandle, const void* buf, unsigned int size);

View File

@ -154,7 +154,7 @@ void soundEffectsCacheFlush()
// sfxc_cached_open
// 0x4A915C
int soundEffectsCacheFileOpen(const char* fname, int mode, ...)
int soundEffectsCacheFileOpen(const char* fname, int mode)
{
if (_sfxc_files_open >= SOUND_EFFECTS_MAX_COUNT) {
return -1;

View File

@ -11,7 +11,7 @@ int soundEffectsCacheInit(int cache_size, const char* effectsPath);
void soundEffectsCacheExit();
int soundEffectsCacheInitialized();
void soundEffectsCacheFlush();
int soundEffectsCacheFileOpen(const char* fname, int mode, ...);
int soundEffectsCacheFileOpen(const char* fname, int mode);
int soundEffectsCacheFileClose(int handle);
int soundEffectsCacheFileRead(int handle, void* buf, unsigned int size);
int soundEffectsCacheFileWrite(int handle, const void* buf, unsigned int size);