Cleanup sound_decoder.h

See #42
This commit is contained in:
Alexander Batalov 2022-06-19 08:23:12 +03:00
parent ef24593371
commit ed33eee731
2 changed files with 55 additions and 65 deletions

View File

@ -11,17 +11,43 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define SOUND_DECODER_IN_BUFFER_SIZE (512)
typedef int (*DECODINGPROC)(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 inline void soundDecoderRequireBits(SoundDecoder* soundDecoder, int bits); static inline void soundDecoderRequireBits(SoundDecoder* soundDecoder, int bits);
static inline void soundDecoderDropBits(SoundDecoder* soundDecoder, int bits); static inline void soundDecoderDropBits(SoundDecoder* soundDecoder, int bits);
// 0x51E328 // 0x51E328
int gSoundDecodersCount = 0; static int gSoundDecodersCount = 0;
// 0x51E32C // 0x51E32C
bool _inited_ = false; static bool _inited_ = false;
// 0x51E330 // 0x51E330
DECODINGPROC _ReadBand_tbl[32] = { static DECODINGPROC _ReadBand_tbl[32] = {
_ReadBand_Fmt0_, _ReadBand_Fmt0_,
_ReadBand_Fail_, _ReadBand_Fail_,
_ReadBand_Fail_, _ReadBand_Fail_,
@ -57,22 +83,22 @@ DECODINGPROC _ReadBand_tbl[32] = {
}; };
// 0x6AD960 // 0x6AD960
unsigned char _pack11_2[128]; static unsigned char _pack11_2[128];
// 0x6AD9E0 // 0x6AD9E0
unsigned char _pack3_3[32]; static unsigned char _pack3_3[32];
// 0x6ADA00 // 0x6ADA00
unsigned short word_6ADA00[128]; static unsigned short word_6ADA00[128];
// 0x6ADB00 // 0x6ADB00
unsigned char* _AudioDecoder_scale0; static unsigned char* _AudioDecoder_scale0;
// 0x6ADB04 // 0x6ADB04
unsigned char* _AudioDecoder_scale_tbl; static unsigned char* _AudioDecoder_scale_tbl;
// 0x4D3BB0 // 0x4D3BB0
bool soundDecoderPrepare(SoundDecoder* soundDecoder, SoundDecoderReadProc* readProc, int fileHandle) static bool soundDecoderPrepare(SoundDecoder* soundDecoder, SoundDecoderReadProc* readProc, int fileHandle)
{ {
soundDecoder->readProc = readProc; soundDecoder->readProc = readProc;
soundDecoder->fd = fileHandle; soundDecoder->fd = fileHandle;
@ -89,7 +115,7 @@ bool soundDecoderPrepare(SoundDecoder* soundDecoder, SoundDecoderReadProc* readP
} }
// 0x4D3BE0 // 0x4D3BE0
unsigned char soundDecoderReadNextChunk(SoundDecoder* soundDecoder) static unsigned char soundDecoderReadNextChunk(SoundDecoder* soundDecoder)
{ {
soundDecoder->remainingInSize = soundDecoder->readProc(soundDecoder->fd, soundDecoder->bufferIn, soundDecoder->bufferInSize); soundDecoder->remainingInSize = soundDecoder->readProc(soundDecoder->fd, soundDecoder->bufferIn, soundDecoder->bufferInSize);
if (soundDecoder->remainingInSize == 0) { if (soundDecoder->remainingInSize == 0) {
@ -103,7 +129,7 @@ unsigned char soundDecoderReadNextChunk(SoundDecoder* soundDecoder)
} }
// 0x4D3C78 // 0x4D3C78
void _init_pack_tables() static void _init_pack_tables()
{ {
int i; int i;
int j; int j;
@ -139,13 +165,13 @@ void _init_pack_tables()
} }
// 0x4D3D9C // 0x4D3D9C
int _ReadBand_Fail_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fail_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
return 0; return 0;
} }
// 0x4D3DA0 // 0x4D3DA0
int _ReadBand_Fmt0_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt0_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
int* p = (int*)soundDecoder->field_34; int* p = (int*)soundDecoder->field_34;
p += offset; p += offset;
@ -161,7 +187,7 @@ int _ReadBand_Fmt0_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D3DC8 // 0x4D3DC8
int _ReadBand_Fmt3_16_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt3_16_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
int value; int value;
int v14; int v14;
@ -190,7 +216,7 @@ int _ReadBand_Fmt3_16_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D3E90 // 0x4D3E90
int _ReadBand_Fmt17_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt17_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
short* base = (short*)_AudioDecoder_scale0; short* base = (short*)_AudioDecoder_scale0;
@ -244,7 +270,7 @@ int _ReadBand_Fmt17_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D3F98 // 0x4D3F98
int _ReadBand_Fmt18_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt18_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
short* base = (short*)_AudioDecoder_scale0; short* base = (short*)_AudioDecoder_scale0;
@ -282,7 +308,7 @@ int _ReadBand_Fmt18_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D4068 // 0x4D4068
int _ReadBand_Fmt19_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt19_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
short* base = (short*)_AudioDecoder_scale0; short* base = (short*)_AudioDecoder_scale0;
base -= 1; base -= 1;
@ -320,7 +346,7 @@ int _ReadBand_Fmt19_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D4158 // 0x4D4158
int _ReadBand_Fmt20_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt20_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
short* base = (short*)_AudioDecoder_scale0; short* base = (short*)_AudioDecoder_scale0;
@ -383,7 +409,7 @@ int _ReadBand_Fmt20_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D4254 // 0x4D4254
int _ReadBand_Fmt21_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt21_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
short* base = (short*)_AudioDecoder_scale0; short* base = (short*)_AudioDecoder_scale0;
@ -430,7 +456,7 @@ int _ReadBand_Fmt21_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D4338 // 0x4D4338
int _ReadBand_Fmt22_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt22_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
short* base = (short*)_AudioDecoder_scale0; short* base = (short*)_AudioDecoder_scale0;
base -= 2; base -= 2;
@ -472,7 +498,7 @@ int _ReadBand_Fmt22_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D4434 // 0x4D4434
int _ReadBand_Fmt23_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt23_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
short* base = (short*)_AudioDecoder_scale0; short* base = (short*)_AudioDecoder_scale0;
@ -541,7 +567,7 @@ int _ReadBand_Fmt23_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D4584 // 0x4D4584
int _ReadBand_Fmt24_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt24_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
short* base = (short*)_AudioDecoder_scale0; short* base = (short*)_AudioDecoder_scale0;
@ -595,7 +621,7 @@ int _ReadBand_Fmt24_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D4698 // 0x4D4698
int _ReadBand_Fmt26_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt26_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
short* base = (short*)_AudioDecoder_scale0; short* base = (short*)_AudioDecoder_scale0;
@ -651,7 +677,7 @@ int _ReadBand_Fmt26_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D47A4 // 0x4D47A4
int _ReadBand_Fmt27_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt27_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
short* base = (short*)_AudioDecoder_scale0; short* base = (short*)_AudioDecoder_scale0;
@ -691,7 +717,7 @@ int _ReadBand_Fmt27_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D4870 // 0x4D4870
int _ReadBand_Fmt29_(SoundDecoder* soundDecoder, int offset, int bits) static int _ReadBand_Fmt29_(SoundDecoder* soundDecoder, int offset, int bits)
{ {
short* base = (short*)_AudioDecoder_scale0; short* base = (short*)_AudioDecoder_scale0;
@ -723,7 +749,7 @@ int _ReadBand_Fmt29_(SoundDecoder* soundDecoder, int offset, int bits)
} }
// 0x4D493C // 0x4D493C
int _ReadBands_(SoundDecoder* soundDecoder) static int _ReadBands_(SoundDecoder* soundDecoder)
{ {
int v9; int v9;
int v15; int v15;
@ -776,7 +802,7 @@ int _ReadBands_(SoundDecoder* soundDecoder)
} }
// 0x4D4ADC // 0x4D4ADC
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; short* p;
@ -874,7 +900,7 @@ void _untransform_subband0(unsigned char* a1, unsigned char* a2, int a3, int a4)
} }
// 0x4D4D1C // 0x4D4D1C
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 v13;
int* v14; int* v14;
@ -965,7 +991,7 @@ void _untransform_subband(unsigned char* a1, unsigned char* a2, int a3, int a4)
} }
// 0x4D4E80 // 0x4D4E80
void _untransform_all(SoundDecoder* soundDecoder) static void _untransform_all(SoundDecoder* soundDecoder)
{ {
int v8; int v8;
unsigned char* ptr; unsigned char* ptr;

View File

@ -3,8 +3,6 @@
#include <stddef.h> #include <stddef.h>
#define SOUND_DECODER_IN_BUFFER_SIZE (512)
typedef int(SoundDecoderReadProc)(int fileHandle, void* buffer, unsigned int size); typedef int(SoundDecoderReadProc)(int fileHandle, void* buffer, unsigned int size);
typedef struct SoundDecoder { typedef struct SoundDecoder {
@ -39,40 +37,6 @@ typedef struct SoundDecoder {
int field_50; int field_50;
} SoundDecoder; } SoundDecoder;
typedef int (*DECODINGPROC)(SoundDecoder* soundDecoder, int offset, int bits);
extern int gSoundDecodersCount;
extern bool _inited_;
extern DECODINGPROC _ReadBand_tbl[32];
extern unsigned char _pack11_2[128];
extern unsigned char _pack3_3[32];
extern unsigned short word_6ADA00[128];
extern unsigned char* _AudioDecoder_scale0;
extern unsigned char* _AudioDecoder_scale_tbl;
bool soundDecoderPrepare(SoundDecoder* a1, SoundDecoderReadProc* readProc, int fileHandle);
unsigned char soundDecoderReadNextChunk(SoundDecoder* a1);
void _init_pack_tables();
int _ReadBand_Fail_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt0_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt3_16_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt17_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt18_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt19_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt20_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt21_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt22_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt23_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt24_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt26_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt27_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBand_Fmt29_(SoundDecoder* soundDecoder, int offset, int bits);
int _ReadBands_(SoundDecoder* ptr);
void _untransform_subband0(unsigned char* a1, unsigned char* a2, int a3, int a4);
void _untransform_subband(unsigned char* a1, unsigned char* a2, int a3, int a4);
void _untransform_all(SoundDecoder* a1);
size_t soundDecoderDecode(SoundDecoder* soundDecoder, void* buffer, size_t size); size_t soundDecoderDecode(SoundDecoder* soundDecoder, void* buffer, size_t size);
void soundDecoderFree(SoundDecoder* soundDecoder); void soundDecoderFree(SoundDecoder* soundDecoder);
SoundDecoder* soundDecoderInit(SoundDecoderReadProc* readProc, int fileHandle, int* out_a3, int* out_a4, int* out_a5); SoundDecoder* soundDecoderInit(SoundDecoderReadProc* readProc, int fileHandle, int* out_a3, int* out_a4, int* out_a5);