forked from Ports/perfect_dark
portx64: pd-extract audio: check for repeated pointers before converting
This commit is contained in:
1 parent
c1c71ea21d
commit
9e34f80a2c
3 files changed
+37
-30
No files matched your search
@@ -1,13 +1,13 @@
|
||||
#include "common.h"
|
||||
#include "system.h"
|
||||
|
||||
struct ptrmarker m_PtrMarkers[2048];
|
||||
struct ptrmarker m_PtrMarkers[1024*8];
|
||||
int m_NumPtrMarkers;
|
||||
|
||||
void add_marker(u32 ptr_src, uintptr_t ptr_host)
|
||||
{
|
||||
if (m_NumPtrMarkers >= ARRAYCOUNT(m_PtrMarkers)) {
|
||||
sysLogPrintf(LOG_ERROR, "[BG] Marker limit exceeded");
|
||||
sysLogPrintf(LOG_ERROR, "Marker limit exceeded");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
+12
-8
@@ -66,17 +66,21 @@
|
||||
#define srctodst64(value) htodst64(srctoh64(value))
|
||||
|
||||
#ifdef FORCE_BE32
|
||||
#define uintptr_t uint32_t
|
||||
#define uintptr_t u32
|
||||
#endif
|
||||
|
||||
void gbi_reset(void);
|
||||
void gbi_set_segment(int segment, uint32_t offset);
|
||||
void gbi_set_vtx(uint32_t src_offset, uint32_t dst_offset);
|
||||
uint32_t gbi_convert_gdl(uint8_t *dst, uint32_t dstpos, uint8_t *src, uint32_t srcpos, int segment_cmds);
|
||||
void gbi_convert_vtx(uint8_t* dst, uint32_t dstpos, int count);
|
||||
void gbi_gdl_rewrite_addrs(uint8_t* dst, uint32_t offset);
|
||||
void gbi_add_tex_addr(uint32_t src_offset, uint32_t dst_offset);
|
||||
#define ALIGN(val, size) ((val + (size - 1)) & ~(size - 1))
|
||||
|
||||
// gbi related functions
|
||||
void gbi_reset(void);
|
||||
void gbi_set_segment(int segment, u32 offset);
|
||||
void gbi_set_vtx(u32 src_offset, u32 dst_offset);
|
||||
u32 gbi_convert_gdl(u8 *dst, u32 dstpos, u8 *src, u32 srcpos, int segment_cmds);
|
||||
void gbi_convert_vtx(u8* dst, u32 dstpos, int count);
|
||||
void gbi_gdl_rewrite_addrs(u8* dst, u32 offset);
|
||||
void gbi_add_tex_addr(u32 src_offset, u32 dst_offset);
|
||||
|
||||
// ptr marker functions
|
||||
struct ptrmarker {
|
||||
u32 ptr_src;
|
||||
uintptr_t ptr_host;
|
||||
|
||||
+23
-20
@@ -170,6 +170,17 @@ struct host_bankfile {
|
||||
uintptr_t bankArray[1]; // ptr to struct host_bank
|
||||
};
|
||||
|
||||
// only proceeds to convert the next item if it's not already converted
|
||||
#define AL_NEXT_ITEM(field, func) { \
|
||||
struct ptrmarker *marker = find_ptr_marker(srcpos); \
|
||||
if (marker == NULL) { \
|
||||
field = htodst32(dstpos); \
|
||||
add_marker(srcpos, field); \
|
||||
dstpos = func(dst, dstpos, src, srcpos); \
|
||||
} else { \
|
||||
field = marker->ptr_host; } \
|
||||
}
|
||||
|
||||
static int convert_audio_envelope(u8 *dst, int dstpos, u8 *src, int srcpos)
|
||||
{
|
||||
struct generic_envelope *n64_envelope = (struct generic_envelope *) &src[srcpos];
|
||||
@@ -266,25 +277,22 @@ static int convert_audio_wavetable(u8 *dst, int dstpos, u8 *src, int srcpos)
|
||||
|
||||
if (host_wavetable->type == AL_ADPCM_WAVE) {
|
||||
if (n64_wavetable->waveInfo.adpcmWave.loop) {
|
||||
host_wavetable->waveInfo.adpcmWave.loop = htodst32(dstpos);
|
||||
srcpos = srctoh32(n64_wavetable->waveInfo.adpcmWave.loop);
|
||||
dstpos = convert_audio_adpcm_loop(dst, dstpos, src, srcpos);
|
||||
AL_NEXT_ITEM(host_wavetable->waveInfo.adpcmWave.loop, convert_audio_adpcm_loop);
|
||||
} else {
|
||||
host_wavetable->waveInfo.adpcmWave.loop = 0;
|
||||
}
|
||||
|
||||
if (n64_wavetable->waveInfo.adpcmWave.book) {
|
||||
host_wavetable->waveInfo.adpcmWave.book = htodst32(dstpos);
|
||||
srcpos = srctoh32(n64_wavetable->waveInfo.adpcmWave.book);
|
||||
dstpos = convert_audio_adpcm_book(dst, dstpos, src, srcpos);
|
||||
AL_NEXT_ITEM(host_wavetable->waveInfo.adpcmWave.book, convert_audio_adpcm_book);
|
||||
} else {
|
||||
host_wavetable->waveInfo.adpcmWave.book = 0;
|
||||
}
|
||||
} else if (host_wavetable->type == AL_RAW16_WAVE) {
|
||||
if (n64_wavetable->waveInfo.rawWave.loop) {
|
||||
host_wavetable->waveInfo.rawWave.loop = htodst32(dstpos);
|
||||
srcpos = srctoh32(n64_wavetable->waveInfo.rawWave.loop);
|
||||
dstpos = convert_audio_raw_loop(dst, dstpos, src, srcpos);
|
||||
AL_NEXT_ITEM(host_wavetable->waveInfo.rawWave.loop, convert_audio_raw_loop);
|
||||
} else {
|
||||
host_wavetable->waveInfo.rawWave.loop = 0;
|
||||
}
|
||||
@@ -301,25 +309,22 @@ static int convert_audio_sound(u8 *dst, int dstpos, u8 *src, int srcpos)
|
||||
dstpos += sizeof(struct host_sound);
|
||||
|
||||
if (n64_sound->envelope) {
|
||||
host_sound->envelope = htodst32(dstpos);
|
||||
srcpos = srctoh32(n64_sound->envelope);
|
||||
dstpos = convert_audio_envelope(dst, dstpos, src, srcpos);
|
||||
AL_NEXT_ITEM(host_sound->envelope, convert_audio_envelope);
|
||||
} else {
|
||||
host_sound->envelope = 0;
|
||||
}
|
||||
|
||||
if (n64_sound->keyMap) {
|
||||
host_sound->keyMap = htodst32(dstpos);
|
||||
srcpos = srctoh32(n64_sound->keyMap);
|
||||
dstpos = convert_audio_keymap(dst, dstpos, src, srcpos);
|
||||
AL_NEXT_ITEM(host_sound->keyMap, convert_audio_keymap);
|
||||
} else {
|
||||
host_sound->keyMap = 0;
|
||||
}
|
||||
|
||||
if (n64_sound->wavetable) {
|
||||
host_sound->wavetable = htodst32(dstpos);
|
||||
srcpos = srctoh32(n64_sound->wavetable);
|
||||
dstpos = convert_audio_wavetable(dst, dstpos, src, srcpos);
|
||||
AL_NEXT_ITEM(host_sound->wavetable, convert_audio_wavetable);
|
||||
} else {
|
||||
host_sound->wavetable = 0;
|
||||
}
|
||||
@@ -355,9 +360,8 @@ static int convert_audio_instrument(u8 *dst, int dstpos, u8 *src, int srcpos)
|
||||
dstpos = dstpos + sizeof(struct host_instrument) + sizeof(uintptr_t) * (soundCount - 1);
|
||||
|
||||
for (int i = 0; i < soundCount; i++) {
|
||||
host_instrument->soundArray[i] = htodst32(dstpos);
|
||||
srcpos = srctoh32(n64_instrument->soundArray[i]);
|
||||
dstpos = convert_audio_sound(dst, dstpos, src, srcpos);
|
||||
AL_NEXT_ITEM(host_instrument->soundArray[i], convert_audio_sound);
|
||||
}
|
||||
|
||||
return dstpos;
|
||||
@@ -377,17 +381,15 @@ static int convert_audio_bank(u8 *dst, int dstpos, u8 *src, int srcpos)
|
||||
dstpos = dstpos + sizeof(struct host_bank) + sizeof(uintptr_t) * (instCount - 1);
|
||||
|
||||
if (n64_bank->percussion) {
|
||||
host_bank->percussion = htodst32(dstpos);
|
||||
srcpos = srctoh32(n64_bank->percussion);
|
||||
dstpos = convert_audio_instrument(dst, dstpos, src, srcpos);
|
||||
AL_NEXT_ITEM(host_bank->percussion, convert_audio_instrument);
|
||||
} else {
|
||||
host_bank->percussion = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < instCount; i++) {
|
||||
host_bank->instArray[i] = htodst32(dstpos);
|
||||
srcpos = srctoh32(n64_bank->instArray[i]);
|
||||
dstpos = convert_audio_instrument(dst, dstpos, src, srcpos);
|
||||
AL_NEXT_ITEM(host_bank->instArray[i], convert_audio_instrument);
|
||||
}
|
||||
|
||||
return dstpos;
|
||||
@@ -416,8 +418,9 @@ static int convert_audio_bankfile(u8 *dst, u8 *src)
|
||||
|
||||
u8 *preprocessALBankFile_x64(u8 *src, u32 size, u32 *outSize)
|
||||
{
|
||||
u32 dstlen = size * 4;
|
||||
u8* dst = sysMemZeroAlloc(dstlen);
|
||||
reset_markers();
|
||||
u32 dstlen = size * 3;
|
||||
u8 *dst = sysMemZeroAlloc(dstlen);
|
||||
|
||||
*outSize = convert_audio_bankfile(dst, src);
|
||||
*outSize = ALIGN16(*outSize);
|
||||
|
||||
Reference in new issue
Block a user