Skip to content

Commit

Permalink
Fix AIFC files without loops
Browse files Browse the repository at this point in the history
  • Loading branch information
rrealmuto committed Dec 27, 2024
1 parent d94b55f commit 7f86f64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ASM/c/sfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ void Player_PlaySfxWithVolume(z64_link_t* this, uint16_t sfxId) {
float* ageVolume = &CFG_ADULT_VOLUME;
ageVolume += z64_game.link_age;
Audio_PlaySfxGeneral(sfxId, &this->common.projectedPos, 4, &z64_SfxDefaultFreqAndVolScale, ageVolume, &z64_SfxDefaultReverb);
}
}
26 changes: 15 additions & 11 deletions Voices.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ def process_aifc_file(f: BinaryIO) -> tuple[bytes, int, int]:
done = False
chunks = {}
chkID = "FORM"
chunks["APPL"] = []
while chkID != '':
chkID = str(f.read(4), encoding='utf-8')
size = int.from_bytes(f.read(4), 'big')
Expand Down Expand Up @@ -762,21 +763,24 @@ def process_aifc_file(f: BinaryIO) -> tuple[bytes, int, int]:
tableBytes += bookPoint.to_bytes(2, 'big', signed = True)

# Pull out the loop crap from the other appl chunk
appl = chunks['APPL'][1]['data']
# stoc + 0x0B + VADPCMLOOPS
appl = appl[0x14:]
loop_start = int.from_bytes(appl[0:4], 'big')
loop_end = int.from_bytes(appl[4:8], 'big')
loop_count = int.from_bytes(appl[8:12], 'big')
loop_state = []
for i in range(0, 16):
index = 12 + 2*i
loop_state.append(int.from_bytes(appl[index:index+2], 'big'))
loop = None
if len(chunks['APPL']) > 1:
appl = chunks['APPL'][1]['data']
# stoc + 0x0B + VADPCMLOOPS
appl = appl[0x14:]
loop_start = int.from_bytes(appl[0:4], 'big')
loop_end = int.from_bytes(appl[4:8], 'big')
loop_count = int.from_bytes(appl[8:12], 'big')
loop_state = []
for i in range(0, 16):
index = 12 + 2*i
loop_state.append(int.from_bytes(appl[index:index+2], 'big'))
loop = AdpcmLoop(loop_start, loop_end, loop_count, 0, loop_state)
if ssndOffset != 0 or ssndBlockSize != 0:
raise Exception("Unsupported SSND offset/block size")
# Read the sample data. it's numSampleFrames * 9 / 8 / 2
dataLen = int(ceil(numSampleFrames * 9 / 8 / 2))
soundData = data[8:8 + dataLen]
return soundData, numSampleFrames, sampleRate, AdpcmBook(order, nEntries, tableBytes), AdpcmLoop(loop_start, loop_end, loop_count, 0, loop_state)
return soundData, numSampleFrames, sampleRate, AdpcmBook(order, nEntries, tableBytes), loop


0 comments on commit 7f86f64

Please sign in to comment.