mirror of
https://github.com/alexbatalov/fallout2-ce.git
synced 2024-09-04 22:09:01 +00:00
parent
a2eabd668b
commit
69e4adf5b3
28
src/audio.cc
28
src/audio.cc
@ -58,7 +58,7 @@ static int audioSoundDecoderReadHandler(void* data, void* buffer, unsigned int s
|
|||||||
|
|
||||||
// AudioOpen
|
// AudioOpen
|
||||||
// 0x41A2EC
|
// 0x41A2EC
|
||||||
int audioOpen(const char* fname, int flags)
|
int audioOpen(const char* fname, int* channels, int* sampleRate)
|
||||||
{
|
{
|
||||||
char path[80];
|
char path[80];
|
||||||
snprintf(path, sizeof(path), "%s", fname);
|
snprintf(path, sizeof(path), "%s", fname);
|
||||||
@ -70,28 +70,7 @@ int audioOpen(const char* fname, int flags)
|
|||||||
compression = 0;
|
compression = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char mode[4];
|
File* stream = fileOpen(path, "rb");
|
||||||
memset(mode, 0, 4);
|
|
||||||
|
|
||||||
// NOTE: Original implementation is slightly different, it uses separate
|
|
||||||
// variable to track index where to set 't' and 'b'.
|
|
||||||
char* pm = mode;
|
|
||||||
if (flags & 1) {
|
|
||||||
*pm++ = 'w';
|
|
||||||
} else if (flags & 2) {
|
|
||||||
*pm++ = 'w';
|
|
||||||
*pm++ = '+';
|
|
||||||
} else {
|
|
||||||
*pm++ = 'r';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & 0x100) {
|
|
||||||
*pm++ = 't';
|
|
||||||
} else if (flags & 0x200) {
|
|
||||||
*pm++ = 'b';
|
|
||||||
}
|
|
||||||
|
|
||||||
File* stream = fileOpen(path, mode);
|
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
debugPrint("AudioOpen: Couldn't open %s for read\n", path);
|
debugPrint("AudioOpen: Couldn't open %s for read\n", path);
|
||||||
return -1;
|
return -1;
|
||||||
@ -121,6 +100,9 @@ int audioOpen(const char* fname, int flags)
|
|||||||
audioFile->flags |= AUDIO_COMPRESSED;
|
audioFile->flags |= AUDIO_COMPRESSED;
|
||||||
audioFile->soundDecoder = soundDecoderInit(audioSoundDecoderReadHandler, audioFile->stream, &(audioFile->channels), &(audioFile->sampleRate), &(audioFile->fileSize));
|
audioFile->soundDecoder = soundDecoderInit(audioSoundDecoderReadHandler, audioFile->stream, &(audioFile->channels), &(audioFile->sampleRate), &(audioFile->fileSize));
|
||||||
audioFile->fileSize *= 2;
|
audioFile->fileSize *= 2;
|
||||||
|
|
||||||
|
*channels = audioFile->channels;
|
||||||
|
*sampleRate = audioFile->sampleRate;
|
||||||
} else {
|
} else {
|
||||||
audioFile->fileSize = fileGetSize(stream);
|
audioFile->fileSize = fileGetSize(stream);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ namespace fallout {
|
|||||||
|
|
||||||
typedef bool(AudioQueryCompressedFunc)(char* filePath);
|
typedef bool(AudioQueryCompressedFunc)(char* filePath);
|
||||||
|
|
||||||
int audioOpen(const char* fname, int mode);
|
int audioOpen(const char* fname, int* channels, int* sampleRate);
|
||||||
int audioClose(int handle);
|
int audioClose(int handle);
|
||||||
int audioRead(int handle, void* buffer, unsigned int size);
|
int audioRead(int handle, void* buffer, unsigned int size);
|
||||||
long audioSeek(int handle, long offset, int origin);
|
long audioSeek(int handle, long offset, int origin);
|
||||||
|
@ -57,7 +57,7 @@ static int audioFileSoundDecoderReadHandler(void* data, void* buffer, unsigned i
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 0x41A88C
|
// 0x41A88C
|
||||||
int audioFileOpen(const char* fname, int flags)
|
int audioFileOpen(const char* fname, int* channels, int* sampleRate)
|
||||||
{
|
{
|
||||||
char path[COMPAT_MAX_PATH];
|
char path[COMPAT_MAX_PATH];
|
||||||
strcpy(path, fname);
|
strcpy(path, fname);
|
||||||
@ -69,28 +69,7 @@ int audioFileOpen(const char* fname, int flags)
|
|||||||
compression = 0;
|
compression = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char mode[4];
|
FILE* stream = compat_fopen(path, "rb");
|
||||||
memset(mode, '\0', 4);
|
|
||||||
|
|
||||||
// NOTE: Original implementation is slightly different, it uses separate
|
|
||||||
// variable to track index where to set 't' and 'b'.
|
|
||||||
char* pm = mode;
|
|
||||||
if (flags & 0x01) {
|
|
||||||
*pm++ = 'w';
|
|
||||||
} else if (flags & 0x02) {
|
|
||||||
*pm++ = 'w';
|
|
||||||
*pm++ = '+';
|
|
||||||
} else {
|
|
||||||
*pm++ = 'r';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & 0x0100) {
|
|
||||||
*pm++ = 't';
|
|
||||||
} else if (flags & 0x0200) {
|
|
||||||
*pm++ = 'b';
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE* stream = compat_fopen(path, mode);
|
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -119,6 +98,9 @@ int audioFileOpen(const char* fname, int flags)
|
|||||||
audioFile->flags |= AUDIO_FILE_COMPRESSED;
|
audioFile->flags |= AUDIO_FILE_COMPRESSED;
|
||||||
audioFile->soundDecoder = soundDecoderInit(audioFileSoundDecoderReadHandler, audioFile->stream, &(audioFile->channels), &(audioFile->sampleRate), &(audioFile->fileSize));
|
audioFile->soundDecoder = soundDecoderInit(audioFileSoundDecoderReadHandler, audioFile->stream, &(audioFile->channels), &(audioFile->sampleRate), &(audioFile->fileSize));
|
||||||
audioFile->fileSize *= 2;
|
audioFile->fileSize *= 2;
|
||||||
|
|
||||||
|
*channels = audioFile->channels;
|
||||||
|
*sampleRate = audioFile->sampleRate;
|
||||||
} else {
|
} else {
|
||||||
audioFile->fileSize = getFileSize(stream);
|
audioFile->fileSize = getFileSize(stream);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ namespace fallout {
|
|||||||
|
|
||||||
typedef bool(AudioFileQueryCompressedFunc)(char* filePath);
|
typedef bool(AudioFileQueryCompressedFunc)(char* filePath);
|
||||||
|
|
||||||
int audioFileOpen(const char* fname, int flags);
|
int audioFileOpen(const char* fname, int* channels, int* sampleRate);
|
||||||
int audioFileClose(int handle);
|
int audioFileClose(int handle);
|
||||||
int audioFileRead(int handle, void* buf, unsigned int size);
|
int audioFileRead(int handle, void* buf, unsigned int size);
|
||||||
long audioFileSeek(int handle, long offset, int origin);
|
long audioFileSeek(int handle, long offset, int origin);
|
||||||
|
@ -157,7 +157,7 @@ static int _gsound_speech_volume_get_set(int volume);
|
|||||||
static void speechPause();
|
static void speechPause();
|
||||||
static void speechResume();
|
static void speechResume();
|
||||||
static void _gsound_bkg_proc();
|
static void _gsound_bkg_proc();
|
||||||
static int gameSoundFileOpen(const char* fname, int access);
|
static int gameSoundFileOpen(const char* fname, int* channels, int* sampleRate);
|
||||||
static long _gsound_write_();
|
static long _gsound_write_();
|
||||||
static long gameSoundFileTellNotImplemented(int handle);
|
static long gameSoundFileTellNotImplemented(int handle);
|
||||||
static int gameSoundFileWrite(int handle, const void* buf, unsigned int size);
|
static int gameSoundFileWrite(int handle, const void* buf, unsigned int size);
|
||||||
@ -1548,12 +1548,8 @@ void _gsound_bkg_proc()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 0x451A08
|
// 0x451A08
|
||||||
int gameSoundFileOpen(const char* fname, int flags)
|
int gameSoundFileOpen(const char* fname, int* channels, int* sampleRate)
|
||||||
{
|
{
|
||||||
if ((flags & 2) != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
File* stream = fileOpen(fname, "rb");
|
File* stream = fileOpen(fname, "rb");
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
10
src/sound.cc
10
src/sound.cc
@ -1,5 +1,6 @@
|
|||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -8,7 +9,6 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#else
|
#else
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ static long soundFileSize(int fileHandle);
|
|||||||
static long soundTellData(int fileHandle);
|
static long soundTellData(int fileHandle);
|
||||||
static int soundWriteData(int fileHandle, const void* buf, unsigned int size);
|
static int soundWriteData(int fileHandle, const void* buf, unsigned int size);
|
||||||
static int soundReadData(int fileHandle, void* buf, unsigned int size);
|
static int soundReadData(int fileHandle, void* buf, unsigned int size);
|
||||||
static int soundOpenData(const char* filePath, int flags);
|
static int soundOpenData(const char* filePath, int* channels, int* sampleRate);
|
||||||
static long soundSeekData(int fileHandle, long offset, int origin);
|
static long soundSeekData(int fileHandle, long offset, int origin);
|
||||||
static int soundCloseData(int fileHandle);
|
static int soundCloseData(int fileHandle);
|
||||||
static char* soundFileManglerDefaultImpl(char* fname);
|
static char* soundFileManglerDefaultImpl(char* fname);
|
||||||
@ -223,9 +223,9 @@ static int soundReadData(int fileHandle, void* buf, unsigned int size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 0x4AC768
|
// 0x4AC768
|
||||||
static int soundOpenData(const char* filePath, int flags)
|
static int soundOpenData(const char* filePath, int* channels, int* sampleRate)
|
||||||
{
|
{
|
||||||
return open(filePath, flags);
|
return open(filePath, _O_RDONLY | _O_BINARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0x4AC774
|
// 0x4AC774
|
||||||
@ -608,7 +608,7 @@ int soundLoad(Sound* sound, char* filePath)
|
|||||||
return gSoundLastError;
|
return gSoundLastError;
|
||||||
}
|
}
|
||||||
|
|
||||||
sound->io.fd = sound->io.open(gSoundFileNameMangler(filePath), 0x0200);
|
sound->io.fd = sound->io.open(gSoundFileNameMangler(filePath), &(sound->channels), &(sound->rate));
|
||||||
if (sound->io.fd == -1) {
|
if (sound->io.fd == -1) {
|
||||||
gSoundLastError = SOUND_FILE_NOT_FOUND;
|
gSoundLastError = SOUND_FILE_NOT_FOUND;
|
||||||
return gSoundLastError;
|
return gSoundLastError;
|
||||||
|
@ -46,7 +46,7 @@ typedef enum SoundError {
|
|||||||
SOUND_ERR_COUNT,
|
SOUND_ERR_COUNT,
|
||||||
} SoundError;
|
} SoundError;
|
||||||
|
|
||||||
typedef int SoundOpenProc(const char* filePath, int flags);
|
typedef int SoundOpenProc(const char* filePath, int* channels, int* sampleRate);
|
||||||
typedef int SoundCloseProc(int fileHandle);
|
typedef int SoundCloseProc(int fileHandle);
|
||||||
typedef int SoundReadProc(int fileHandle, void* buf, unsigned int size);
|
typedef int SoundReadProc(int fileHandle, void* buf, unsigned int size);
|
||||||
typedef int SoundWriteProc(int fileHandle, const void* buf, unsigned int size);
|
typedef int SoundWriteProc(int fileHandle, const void* buf, unsigned int size);
|
||||||
|
@ -154,7 +154,7 @@ void soundEffectsCacheFlush()
|
|||||||
|
|
||||||
// sfxc_cached_open
|
// sfxc_cached_open
|
||||||
// 0x4A915C
|
// 0x4A915C
|
||||||
int soundEffectsCacheFileOpen(const char* fname, int mode)
|
int soundEffectsCacheFileOpen(const char* fname, int* channels, int* sampleRate)
|
||||||
{
|
{
|
||||||
if (_sfxc_files_open >= SOUND_EFFECTS_MAX_COUNT) {
|
if (_sfxc_files_open >= SOUND_EFFECTS_MAX_COUNT) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -11,7 +11,7 @@ int soundEffectsCacheInit(int cache_size, const char* effectsPath);
|
|||||||
void soundEffectsCacheExit();
|
void soundEffectsCacheExit();
|
||||||
int soundEffectsCacheInitialized();
|
int soundEffectsCacheInitialized();
|
||||||
void soundEffectsCacheFlush();
|
void soundEffectsCacheFlush();
|
||||||
int soundEffectsCacheFileOpen(const char* fname, int mode);
|
int soundEffectsCacheFileOpen(const char* fname, int* channels, int* sampleRate);
|
||||||
int soundEffectsCacheFileClose(int handle);
|
int soundEffectsCacheFileClose(int handle);
|
||||||
int soundEffectsCacheFileRead(int handle, void* buf, unsigned int size);
|
int soundEffectsCacheFileRead(int handle, void* buf, unsigned int size);
|
||||||
int soundEffectsCacheFileWrite(int handle, const void* buf, unsigned int size);
|
int soundEffectsCacheFileWrite(int handle, const void* buf, unsigned int size);
|
||||||
|
Loading…
Reference in New Issue
Block a user