Improve sound_decoder.cc accuracy
This commit is contained in:
parent
f5d3cfb5e3
commit
36b5ceba8a
19
src/audio.cc
19
src/audio.cc
|
@ -7,7 +7,6 @@
|
|||
#include "db.h"
|
||||
#include "debug.h"
|
||||
#include "memory_manager.h"
|
||||
#include "pointer_registry.h"
|
||||
#include "sound.h"
|
||||
#include "sound_decoder.h"
|
||||
|
||||
|
@ -20,7 +19,7 @@ typedef enum AudioFlags {
|
|||
|
||||
typedef struct Audio {
|
||||
int flags;
|
||||
int stream;
|
||||
File* stream;
|
||||
SoundDecoder* soundDecoder;
|
||||
int fileSize;
|
||||
int sampleRate;
|
||||
|
@ -29,7 +28,7 @@ typedef struct Audio {
|
|||
} Audio;
|
||||
|
||||
static bool defaultCompressionFunc(char* filePath);
|
||||
static int audioSoundDecoderReadHandler(int fileHandle, void* buf, unsigned int size);
|
||||
static int audioSoundDecoderReadHandler(void* data, void* buf, unsigned int size);
|
||||
|
||||
// 0x5108BC
|
||||
static AudioQueryCompressedFunc* queryCompressedFunc = defaultCompressionFunc;
|
||||
|
@ -52,9 +51,9 @@ static bool defaultCompressionFunc(char* filePath)
|
|||
}
|
||||
|
||||
// 0x41A2D0
|
||||
static int audioSoundDecoderReadHandler(int handle, void* buffer, unsigned int size)
|
||||
static int audioSoundDecoderReadHandler(void* data, void* buffer, unsigned int size)
|
||||
{
|
||||
return fileRead(buffer, 1, size, (File*)intToPtr(handle));
|
||||
return fileRead(buffer, 1, size, reinterpret_cast<File*>(data));
|
||||
}
|
||||
|
||||
// AudioOpen
|
||||
|
@ -116,7 +115,7 @@ int audioOpen(const char* fname, int flags, ...)
|
|||
|
||||
Audio* audioFile = &(gAudioList[index]);
|
||||
audioFile->flags = AUDIO_IN_USE;
|
||||
audioFile->stream = ptrToInt(stream);
|
||||
audioFile->stream = stream;
|
||||
|
||||
if (compression == 2) {
|
||||
audioFile->flags |= AUDIO_COMPRESSED;
|
||||
|
@ -135,7 +134,7 @@ int audioOpen(const char* fname, int flags, ...)
|
|||
int audioClose(int handle)
|
||||
{
|
||||
Audio* audioFile = &(gAudioList[handle - 1]);
|
||||
fileClose((File*)intToPtr(audioFile->stream, true));
|
||||
fileClose(audioFile->stream);
|
||||
|
||||
if ((audioFile->flags & AUDIO_COMPRESSED) != 0) {
|
||||
soundDecoderFree(audioFile->soundDecoder);
|
||||
|
@ -155,7 +154,7 @@ int audioRead(int handle, void* buffer, unsigned int size)
|
|||
if ((audioFile->flags & AUDIO_COMPRESSED) != 0) {
|
||||
bytesRead = soundDecoderDecode(audioFile->soundDecoder, buffer, size);
|
||||
} else {
|
||||
bytesRead = fileRead(buffer, 1, size, (File*)intToPtr(audioFile->stream));
|
||||
bytesRead = fileRead(buffer, 1, size, audioFile->stream);
|
||||
}
|
||||
|
||||
audioFile->position += bytesRead;
|
||||
|
@ -189,7 +188,7 @@ long audioSeek(int handle, long offset, int origin)
|
|||
if ((audioFile->flags & AUDIO_COMPRESSED) != 0) {
|
||||
if (pos < audioFile->position) {
|
||||
soundDecoderFree(audioFile->soundDecoder);
|
||||
fileSeek((File*)intToPtr(audioFile->stream), 0, SEEK_SET);
|
||||
fileSeek(audioFile->stream, 0, SEEK_SET);
|
||||
audioFile->soundDecoder = soundDecoderInit(audioSoundDecoderReadHandler, audioFile->stream, &(audioFile->channels), &(audioFile->sampleRate), &(audioFile->fileSize));
|
||||
audioFile->position = 0;
|
||||
audioFile->fileSize *= 2;
|
||||
|
@ -224,7 +223,7 @@ long audioSeek(int handle, long offset, int origin)
|
|||
|
||||
return audioFile->position;
|
||||
} else {
|
||||
return fileSeek((File*)intToPtr(audioFile->stream), offset, origin);
|
||||
return fileSeek(audioFile->stream, offset, origin);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "debug.h"
|
||||
#include "memory_manager.h"
|
||||
#include "platform_compat.h"
|
||||
#include "pointer_registry.h"
|
||||
#include "sound.h"
|
||||
#include "sound_decoder.h"
|
||||
|
||||
|
@ -20,7 +19,7 @@ typedef enum AudioFileFlags {
|
|||
|
||||
typedef struct AudioFile {
|
||||
int flags;
|
||||
int stream;
|
||||
FILE* stream;
|
||||
SoundDecoder* soundDecoder;
|
||||
int fileSize;
|
||||
int sampleRate;
|
||||
|
@ -29,7 +28,7 @@ typedef struct AudioFile {
|
|||
} AudioFile;
|
||||
|
||||
static bool defaultCompressionFunc(char* filePath);
|
||||
static int audioFileSoundDecoderReadHandler(int handle, void* buffer, unsigned int size);
|
||||
static int audioFileSoundDecoderReadHandler(void* data, void* buffer, unsigned int size);
|
||||
|
||||
// 0x5108C0
|
||||
static AudioFileQueryCompressedFunc* queryCompressedFunc = defaultCompressionFunc;
|
||||
|
@ -52,9 +51,9 @@ static bool defaultCompressionFunc(char* filePath)
|
|||
}
|
||||
|
||||
// 0x41A870
|
||||
static int audioFileSoundDecoderReadHandler(int handle, void* buffer, unsigned int size)
|
||||
static int audioFileSoundDecoderReadHandler(void* data, void* buffer, unsigned int size)
|
||||
{
|
||||
return fread(buffer, 1, size, (FILE*)intToPtr(handle));
|
||||
return fread(buffer, 1, size, reinterpret_cast<FILE*>(data));
|
||||
}
|
||||
|
||||
// 0x41A88C
|
||||
|
@ -114,7 +113,7 @@ int audioFileOpen(const char* fname, int flags, ...)
|
|||
|
||||
AudioFile* audioFile = &(gAudioFileList[index]);
|
||||
audioFile->flags = AUDIO_FILE_IN_USE;
|
||||
audioFile->stream = ptrToInt(stream);
|
||||
audioFile->stream = stream;
|
||||
|
||||
if (compression == 2) {
|
||||
audioFile->flags |= AUDIO_FILE_COMPRESSED;
|
||||
|
@ -133,7 +132,7 @@ int audioFileOpen(const char* fname, int flags, ...)
|
|||
int audioFileClose(int handle)
|
||||
{
|
||||
AudioFile* audioFile = &(gAudioFileList[handle - 1]);
|
||||
fclose((FILE*)intToPtr(audioFile->stream, true));
|
||||
fclose(audioFile->stream);
|
||||
|
||||
if ((audioFile->flags & AUDIO_FILE_COMPRESSED) != 0) {
|
||||
soundDecoderFree(audioFile->soundDecoder);
|
||||
|
@ -155,7 +154,7 @@ int audioFileRead(int handle, void* buffer, unsigned int size)
|
|||
if ((ptr->flags & AUDIO_FILE_COMPRESSED) != 0) {
|
||||
bytesRead = soundDecoderDecode(ptr->soundDecoder, buffer, size);
|
||||
} else {
|
||||
bytesRead = fread(buffer, 1, size, (FILE*)intToPtr(ptr->stream));
|
||||
bytesRead = fread(buffer, 1, size, ptr->stream);
|
||||
}
|
||||
|
||||
ptr->position += bytesRead;
|
||||
|
@ -190,7 +189,7 @@ long audioFileSeek(int handle, long offset, int origin)
|
|||
if (a4 <= audioFile->position) {
|
||||
soundDecoderFree(audioFile->soundDecoder);
|
||||
|
||||
fseek((FILE*)intToPtr(audioFile->stream), 0, 0);
|
||||
fseek(audioFile->stream, 0, 0);
|
||||
|
||||
audioFile->soundDecoder = soundDecoderInit(audioFileSoundDecoderReadHandler, audioFile->stream, &(audioFile->channels), &(audioFile->sampleRate), &(audioFile->fileSize));
|
||||
audioFile->fileSize *= 2;
|
||||
|
@ -222,7 +221,7 @@ long audioFileSeek(int handle, long offset, int origin)
|
|||
return audioFile->position;
|
||||
}
|
||||
|
||||
return fseek((FILE*)intToPtr(audioFile->stream), offset, origin);
|
||||
return fseek(audioFile->stream, offset, origin);
|
||||
}
|
||||
|
||||
// 0x41AD20
|
||||
|
|
|
@ -17,27 +17,27 @@ namespace fallout {
|
|||
|
||||
typedef int (*ReadBandFunc)(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
|
||||
static bool soundDecoderPrepare(SoundDecoder* a1, SoundDecoderReadProc* readProc, int fileHandle);
|
||||
static unsigned char soundDecoderReadNextChunk(SoundDecoder* a1);
|
||||
static void _init_pack_tables();
|
||||
static int _ReadBand_Fail_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt0_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt3_16_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt17_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt18_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt19_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt20_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt21_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt22_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt23_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt24_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt26_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt27_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBand_Fmt29_(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int _ReadBands_(SoundDecoder* ptr);
|
||||
static void _untransform_subband0(unsigned char* a1, unsigned char* a2, int a3, int a4);
|
||||
static void _untransform_subband(unsigned char* a1, unsigned char* a2, int a3, int a4);
|
||||
static void _untransform_all(SoundDecoder* a1);
|
||||
static bool soundDecoderPrepare(SoundDecoder* soundDecoder, SoundDecoderReadProc* readProc, void* data);
|
||||
static unsigned char soundDecoderReadNextChunk(SoundDecoder* soundDecoder);
|
||||
static void init_pack_tables();
|
||||
static int ReadBand_Fail(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt0(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt3_16(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt17(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt18(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt19(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt20(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt21(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt22(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt23(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt24(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt26(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt27(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBand_Fmt29(SoundDecoder* soundDecoder, int offset, int bits);
|
||||
static int ReadBands(SoundDecoder* ptr);
|
||||
static void untransform_subband0(unsigned char* a1, unsigned char* a2, int a3, int a4);
|
||||
static void untransform_subband(unsigned char* a1, unsigned char* a2, int a3, int a4);
|
||||
static void untransform_all(SoundDecoder* soundDecoder);
|
||||
|
||||
static inline void soundDecoderRequireBits(SoundDecoder* soundDecoder, int bits);
|
||||
static inline void soundDecoderDropBits(SoundDecoder* soundDecoder, int bits);
|
||||
|
@ -47,38 +47,38 @@ static int gSoundDecodersCount = 0;
|
|||
|
||||
// 0x51E330
|
||||
static ReadBandFunc _ReadBand_tbl[32] = {
|
||||
_ReadBand_Fmt0_,
|
||||
_ReadBand_Fail_,
|
||||
_ReadBand_Fail_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt3_16_,
|
||||
_ReadBand_Fmt17_,
|
||||
_ReadBand_Fmt18_,
|
||||
_ReadBand_Fmt19_,
|
||||
_ReadBand_Fmt20_,
|
||||
_ReadBand_Fmt21_,
|
||||
_ReadBand_Fmt22_,
|
||||
_ReadBand_Fmt23_,
|
||||
_ReadBand_Fmt24_,
|
||||
_ReadBand_Fail_,
|
||||
_ReadBand_Fmt26_,
|
||||
_ReadBand_Fmt27_,
|
||||
_ReadBand_Fail_,
|
||||
_ReadBand_Fmt29_,
|
||||
_ReadBand_Fail_,
|
||||
_ReadBand_Fail_,
|
||||
ReadBand_Fmt0,
|
||||
ReadBand_Fail,
|
||||
ReadBand_Fail,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt3_16,
|
||||
ReadBand_Fmt17,
|
||||
ReadBand_Fmt18,
|
||||
ReadBand_Fmt19,
|
||||
ReadBand_Fmt20,
|
||||
ReadBand_Fmt21,
|
||||
ReadBand_Fmt22,
|
||||
ReadBand_Fmt23,
|
||||
ReadBand_Fmt24,
|
||||
ReadBand_Fail,
|
||||
ReadBand_Fmt26,
|
||||
ReadBand_Fmt27,
|
||||
ReadBand_Fail,
|
||||
ReadBand_Fmt29,
|
||||
ReadBand_Fail,
|
||||
ReadBand_Fail,
|
||||
};
|
||||
|
||||
// 0x6AD960
|
||||
|
@ -97,10 +97,10 @@ static unsigned char* _AudioDecoder_scale0;
|
|||
static unsigned char* _AudioDecoder_scale_tbl;
|
||||
|
||||
// 0x4D3BB0
|
||||
static bool soundDecoderPrepare(SoundDecoder* soundDecoder, SoundDecoderReadProc* readProc, int fileHandle)
|
||||
static bool soundDecoderPrepare(SoundDecoder* soundDecoder, SoundDecoderReadProc* readProc, void* data)
|
||||
{
|
||||
soundDecoder->readProc = readProc;
|
||||
soundDecoder->fd = fileHandle;
|
||||
soundDecoder->data = data;
|
||||
|
||||
soundDecoder->bufferIn = (unsigned char*)malloc(SOUND_DECODER_IN_BUFFER_SIZE);
|
||||
if (soundDecoder->bufferIn == NULL) {
|
||||
|
@ -116,7 +116,7 @@ static bool soundDecoderPrepare(SoundDecoder* soundDecoder, SoundDecoderReadProc
|
|||
// 0x4D3BE0
|
||||
static unsigned char soundDecoderReadNextChunk(SoundDecoder* soundDecoder)
|
||||
{
|
||||
soundDecoder->remainingInSize = soundDecoder->readProc(soundDecoder->fd, soundDecoder->bufferIn, soundDecoder->bufferInSize);
|
||||
soundDecoder->remainingInSize = soundDecoder->readProc(soundDecoder->data, soundDecoder->bufferIn, soundDecoder->bufferInSize);
|
||||
if (soundDecoder->remainingInSize == 0) {
|
||||
memset(soundDecoder->bufferIn, 0, soundDecoder->bufferInSize);
|
||||
soundDecoder->remainingInSize = soundDecoder->bufferInSize;
|
||||
|
@ -128,7 +128,7 @@ static unsigned char soundDecoderReadNextChunk(SoundDecoder* soundDecoder)
|
|||
}
|
||||
|
||||
// 0x4D3C78
|
||||
static void _init_pack_tables()
|
||||
static void init_pack_tables()
|
||||
{
|
||||
// 0x51E32C
|
||||
static bool inited = false;
|
||||
|
@ -167,13 +167,13 @@ static void _init_pack_tables()
|
|||
}
|
||||
|
||||
// 0x4D3D9C
|
||||
static int _ReadBand_Fail_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fail(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 0x4D3DA0
|
||||
static int _ReadBand_Fmt0_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt0(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
int* p = (int*)soundDecoder->samples;
|
||||
p += offset;
|
||||
|
@ -189,7 +189,7 @@ static int _ReadBand_Fmt0_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D3DC8
|
||||
static int _ReadBand_Fmt3_16_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt3_16(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
int value;
|
||||
int v14;
|
||||
|
@ -218,7 +218,7 @@ static int _ReadBand_Fmt3_16_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D3E90
|
||||
static int _ReadBand_Fmt17_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt17(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
short* base = (short*)_AudioDecoder_scale0;
|
||||
|
||||
|
@ -272,7 +272,7 @@ static int _ReadBand_Fmt17_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D3F98
|
||||
static int _ReadBand_Fmt18_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt18(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
short* base = (short*)_AudioDecoder_scale0;
|
||||
|
||||
|
@ -310,7 +310,7 @@ static int _ReadBand_Fmt18_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D4068
|
||||
static int _ReadBand_Fmt19_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt19(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
short* base = (short*)_AudioDecoder_scale0;
|
||||
base -= 1;
|
||||
|
@ -348,7 +348,7 @@ static int _ReadBand_Fmt19_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D4158
|
||||
static int _ReadBand_Fmt20_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt20(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
short* base = (short*)_AudioDecoder_scale0;
|
||||
|
||||
|
@ -411,7 +411,7 @@ static int _ReadBand_Fmt20_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D4254
|
||||
static int _ReadBand_Fmt21_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt21(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
short* base = (short*)_AudioDecoder_scale0;
|
||||
|
||||
|
@ -458,7 +458,7 @@ static int _ReadBand_Fmt21_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D4338
|
||||
static int _ReadBand_Fmt22_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt22(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
short* base = (short*)_AudioDecoder_scale0;
|
||||
base -= 2;
|
||||
|
@ -500,7 +500,7 @@ static int _ReadBand_Fmt22_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D4434
|
||||
static int _ReadBand_Fmt23_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt23(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
short* base = (short*)_AudioDecoder_scale0;
|
||||
|
||||
|
@ -569,7 +569,7 @@ static int _ReadBand_Fmt23_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D4584
|
||||
static int _ReadBand_Fmt24_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt24(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
short* base = (short*)_AudioDecoder_scale0;
|
||||
|
||||
|
@ -623,7 +623,7 @@ static int _ReadBand_Fmt24_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D4698
|
||||
static int _ReadBand_Fmt26_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt26(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
short* base = (short*)_AudioDecoder_scale0;
|
||||
|
||||
|
@ -679,7 +679,7 @@ static int _ReadBand_Fmt26_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D47A4
|
||||
static int _ReadBand_Fmt27_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt27(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
short* base = (short*)_AudioDecoder_scale0;
|
||||
|
||||
|
@ -719,7 +719,7 @@ static int _ReadBand_Fmt27_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D4870
|
||||
static int _ReadBand_Fmt29_(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
static int ReadBand_Fmt29(SoundDecoder* soundDecoder, int offset, int bits)
|
||||
{
|
||||
short* base = (short*)_AudioDecoder_scale0;
|
||||
|
||||
|
@ -751,7 +751,7 @@ static int _ReadBand_Fmt29_(SoundDecoder* soundDecoder, int offset, int bits)
|
|||
}
|
||||
|
||||
// 0x4D493C
|
||||
static int _ReadBands_(SoundDecoder* soundDecoder)
|
||||
static int ReadBands(SoundDecoder* soundDecoder)
|
||||
{
|
||||
int v9;
|
||||
int v15;
|
||||
|
@ -788,7 +788,7 @@ static int _ReadBands_(SoundDecoder* soundDecoder)
|
|||
v21 -= v15;
|
||||
}
|
||||
|
||||
_init_pack_tables();
|
||||
init_pack_tables();
|
||||
|
||||
for (int index = 0; index < soundDecoder->subbands; index++) {
|
||||
soundDecoderRequireBits(soundDecoder, 5);
|
||||
|
@ -804,7 +804,7 @@ static int _ReadBands_(SoundDecoder* soundDecoder)
|
|||
}
|
||||
|
||||
// 0x4D4ADC
|
||||
static void _untransform_subband0(unsigned char* a1, unsigned char* a2, int a3, int a4)
|
||||
static void untransform_subband0(unsigned char* a1, unsigned char* a2, int a3, int a4)
|
||||
{
|
||||
short* p;
|
||||
|
||||
|
@ -902,7 +902,7 @@ static void _untransform_subband0(unsigned char* a1, unsigned char* a2, int a3,
|
|||
}
|
||||
|
||||
// 0x4D4D1C
|
||||
static void _untransform_subband(unsigned char* a1, unsigned char* a2, int a3, int a4)
|
||||
static void untransform_subband(unsigned char* a1, unsigned char* a2, int a3, int a4)
|
||||
{
|
||||
int v13;
|
||||
int* v14;
|
||||
|
@ -993,7 +993,7 @@ static void _untransform_subband(unsigned char* a1, unsigned char* a2, int a3, i
|
|||
}
|
||||
|
||||
// 0x4D4E80
|
||||
static void _untransform_all(SoundDecoder* soundDecoder)
|
||||
static void untransform_all(SoundDecoder* soundDecoder)
|
||||
{
|
||||
int v8;
|
||||
unsigned char* ptr;
|
||||
|
@ -1019,7 +1019,7 @@ static void _untransform_all(SoundDecoder* soundDecoder)
|
|||
|
||||
v4 *= 2;
|
||||
|
||||
_untransform_subband0(soundDecoder->prev_samples, ptr, v3, v4);
|
||||
untransform_subband0(soundDecoder->prev_samples, ptr, v3, v4);
|
||||
|
||||
v5 = (int*)ptr;
|
||||
for (v6 = 0; v6 < v4; v6++) {
|
||||
|
@ -1034,7 +1034,7 @@ static void _untransform_all(SoundDecoder* soundDecoder)
|
|||
if (v3 == 0) {
|
||||
break;
|
||||
}
|
||||
_untransform_subband(j, ptr, v3, v4);
|
||||
untransform_subband(j, ptr, v3, v4);
|
||||
j += 8 * v3;
|
||||
}
|
||||
|
||||
|
@ -1063,11 +1063,11 @@ size_t soundDecoderDecode(SoundDecoder* soundDecoder, void* buffer, size_t size)
|
|||
break;
|
||||
}
|
||||
|
||||
if (!_ReadBands_(soundDecoder)) {
|
||||
if (!ReadBands(soundDecoder)) {
|
||||
break;
|
||||
}
|
||||
|
||||
_untransform_all(soundDecoder);
|
||||
untransform_all(soundDecoder);
|
||||
|
||||
soundDecoder->file_cnt -= soundDecoder->total_samples;
|
||||
soundDecoder->samp_ptr = soundDecoder->samples;
|
||||
|
@ -1122,7 +1122,7 @@ void soundDecoderFree(SoundDecoder* soundDecoder)
|
|||
}
|
||||
|
||||
// 0x4D50A8
|
||||
SoundDecoder* soundDecoderInit(SoundDecoderReadProc* readProc, int fileHandle, int* channelsPtr, int* sampleRatePtr, int* sampleCountPtr)
|
||||
SoundDecoder* soundDecoderInit(SoundDecoderReadProc* readProc, void* data, int* channelsPtr, int* sampleRatePtr, int* sampleCountPtr)
|
||||
{
|
||||
int v14;
|
||||
int v20;
|
||||
|
@ -1137,7 +1137,7 @@ SoundDecoder* soundDecoderInit(SoundDecoderReadProc* readProc, int fileHandle, i
|
|||
|
||||
gSoundDecodersCount++;
|
||||
|
||||
if (!soundDecoderPrepare(soundDecoder, readProc, fileHandle)) {
|
||||
if (!soundDecoderPrepare(soundDecoder, readProc, data)) {
|
||||
goto L66;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
|
||||
namespace fallout {
|
||||
|
||||
typedef int(SoundDecoderReadProc)(int fileHandle, void* buffer, unsigned int size);
|
||||
typedef int(SoundDecoderReadProc)(void* data, void* buffer, unsigned int size);
|
||||
|
||||
typedef struct SoundDecoder {
|
||||
SoundDecoderReadProc* readProc;
|
||||
int fd;
|
||||
void* data;
|
||||
unsigned char* bufferIn;
|
||||
size_t bufferInSize;
|
||||
|
||||
|
@ -41,7 +41,7 @@ typedef struct SoundDecoder {
|
|||
|
||||
size_t soundDecoderDecode(SoundDecoder* soundDecoder, void* buffer, size_t size);
|
||||
void soundDecoderFree(SoundDecoder* soundDecoder);
|
||||
SoundDecoder* soundDecoderInit(SoundDecoderReadProc* readProc, int fileHandle, int* channelsPtr, int* sampleRatePtr, int* sampleCountPtr);
|
||||
SoundDecoder* soundDecoderInit(SoundDecoderReadProc* readProc, void* data, int* channelsPtr, int* sampleRatePtr, int* sampleCountPtr);
|
||||
|
||||
} // namespace fallout
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ static void soundEffectsCacheFreeHandles();
|
|||
static int soundEffectsCreate(int* handlePtr, int id, void* data, CacheEntry* cacheHandle);
|
||||
static bool soundEffectsIsValidHandle(int a1);
|
||||
static int soundEffectsCacheFileReadCompressed(int handle, void* buf, unsigned int size);
|
||||
static int _sfxc_ad_reader(int handle, void* buf, unsigned int size);
|
||||
static int soundEffectsCacheSoundDecoderReadHandler(void* data, void* buf, unsigned int size);
|
||||
|
||||
// 0x50DE04
|
||||
static const char* off_50DE04 = "";
|
||||
|
@ -476,7 +476,7 @@ static int soundEffectsCacheFileReadCompressed(int handle, void* buf, unsigned i
|
|||
int channels;
|
||||
int sampleRate;
|
||||
int sampleCount;
|
||||
SoundDecoder* soundDecoder = soundDecoderInit(_sfxc_ad_reader, handle, &channels, &sampleRate, &sampleCount);
|
||||
SoundDecoder* soundDecoder = soundDecoderInit(soundEffectsCacheSoundDecoderReadHandler, &handle, &channels, &sampleRate, &sampleCount);
|
||||
|
||||
if (soundEffect->position != 0) {
|
||||
void* temp = internal_malloc(soundEffect->position);
|
||||
|
@ -505,12 +505,13 @@ static int soundEffectsCacheFileReadCompressed(int handle, void* buf, unsigned i
|
|||
}
|
||||
|
||||
// 0x4A9774
|
||||
static int _sfxc_ad_reader(int handle, void* buf, unsigned int size)
|
||||
static int soundEffectsCacheSoundDecoderReadHandler(void* data, void* buf, unsigned int size)
|
||||
{
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle = *reinterpret_cast<int*>(data);
|
||||
SoundEffect* soundEffect = &(gSoundEffects[handle]);
|
||||
|
||||
unsigned int bytesToRead = soundEffect->fileSize - soundEffect->dataPosition;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include "debug.h"
|
||||
#include "memory.h"
|
||||
#include "platform_compat.h"
|
||||
#include "pointer_registry.h"
|
||||
#include "sound_decoder.h"
|
||||
|
||||
namespace fallout {
|
||||
|
@ -28,7 +27,7 @@ static int soundEffectsListCopyFileNames(char** fileNameList);
|
|||
static int soundEffectsListPopulateFileSizes();
|
||||
static int soundEffectsListSort();
|
||||
static int soundEffectsListCompareByName(const void* a1, const void* a2);
|
||||
static int _sfxl_ad_reader(int fileHandle, void* buf, unsigned int size);
|
||||
static int soundEffectsListSoundDecoderReadHandler(void* data, void* buf, unsigned int size);
|
||||
|
||||
// 0x51C8F8
|
||||
static bool gSoundEffectsListInitialized = false;
|
||||
|
@ -424,16 +423,13 @@ static int soundEffectsListPopulateFileSizes()
|
|||
return 1;
|
||||
}
|
||||
|
||||
int fileHandle = ptrToInt((void*)stream);
|
||||
|
||||
int channels;
|
||||
int sampleRate;
|
||||
int sampleCount;
|
||||
SoundDecoder* soundDecoder = soundDecoderInit(_sfxl_ad_reader, fileHandle, &channels, &sampleRate, &sampleCount);
|
||||
SoundDecoder* soundDecoder = soundDecoderInit(soundEffectsListSoundDecoderReadHandler, stream, &channels, &sampleRate, &sampleCount);
|
||||
entry->dataSize = 2 * sampleCount;
|
||||
soundDecoderFree(soundDecoder);
|
||||
fileClose(stream);
|
||||
intToPtr(fileHandle, true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -468,9 +464,9 @@ static int soundEffectsListCompareByName(const void* a1, const void* a2)
|
|||
}
|
||||
|
||||
// read via xfile
|
||||
static int _sfxl_ad_reader(int fileHandle, void* buf, unsigned int size)
|
||||
static int soundEffectsListSoundDecoderReadHandler(void* data, void* buf, unsigned int size)
|
||||
{
|
||||
return fileRead(buf, 1, size, (File*)intToPtr(fileHandle));
|
||||
return fileRead(buf, 1, size, reinterpret_cast<File*>(data));
|
||||
}
|
||||
|
||||
} // namespace fallout
|
||||
|
|
Loading…
Reference in New Issue