DEVTOOLS: Handle empty AUD file in Blade Runner

French localization has an empty AUD file. Only the header is present and seems corrupted

This is DCLER_0030_00041ECE in TLK0A. It is an unused audio file ("boop" in ENG localization), but skipping it would cause issues with the translation excel, ie. one row missing. The fix is to create a placeholder empty wav file in order to not ignore this empty quote. The bug affected the spreasheet creator tool.
This commit is contained in:
Thanasis Antoniou 2019-01-21 16:27:26 +02:00
parent 535a15f25a
commit 43a3eed2b2
4 changed files with 51 additions and 27 deletions

View file

@ -25,8 +25,8 @@ if (not ctypesLibFound) \
from struct import *
my_module_version = "0.60"
my_module_name = "audFileDecode"
MY_MODULE_VERSION = "0.60"
MY_MODULE_NAME = "audFileDecode"
aud_ima_index_adjust_table = [-1, -1, -1, -1, 2, 4, 6, 8]
@ -225,11 +225,12 @@ class audFileDecode:
if __name__ == '__main__':
# main()
print "[Debug] Running %s as main module" % (my_module_name)
decodeInstance = audFileDecode()
if decodeInstance.m_traceModeEnabled:
print "[Debug] Running %s (%s) as main module" % (MY_MODULE_NAME, MY_MODULE_VERSION)
else:
#debug
#print "[Debug] Running %s imported from another module" % (my_module_name)
#print "[Debug] Running %s (%s) imported from another module" % (MY_MODULE_NAME, MY_MODULE_VERSION)
pass

View file

@ -62,8 +62,8 @@ if (not osLibFound) \
from struct import *
from audFileDecode import *
my_module_version = "0.80"
my_module_name = "audFileLib"
MY_MODULE_VERSION = "0.80"
MY_MODULE_NAME = "audFileLib"
#constants
aud_chunk_id = 0x0000deaf
@ -129,9 +129,11 @@ class audFile:
cbinaryDataOutLst.append(tmpTupleH[0])
cvirtualBinaryD = struct.pack('B'*len(cbinaryDataOutLst), *cbinaryDataOutLst)
if (not cvirtualBinaryD):
print "[Error] audio file could not be exported properly (0 data read): " + filename
if (not cvirtualBinaryD and (len(audBytesBuff) - SIZE_OF_AUD_HEADER_IN_BYTES) > 0):
print "[Error] audio file could not be exported properly (0 data read): %s" % (filename)
return 1
elif (len(audBytesBuff) - SIZE_OF_AUD_HEADER_IN_BYTES) == 0:
print "[Warning] Creating empty wav file: %s" % (filename)
cb_sample = self.get_cb_sample()
cs_remaining = self.get_c_samples()
@ -188,8 +190,18 @@ class audFile:
print "[Debug] Sample rate: %d\tsizeIn: %d\tsizeOut: %d\tflags: %d\tcompression: %d" % (self.get_samplerate(), self.header().m_size_in, self.header().m_size_out, self.header().m_flags, self.header().m_compression)
if self.get_samplerate() < 8000 or self.get_samplerate() > 48000 or self.header().m_size_in > (maxLength - SIZE_OF_AUD_HEADER_IN_BYTES ):
print "[Error] Bad AUD Header size in file %s" % (self.m_simpleAudioFileName)
return False
print "[Warning] Bad AUD Header info in file %s, size_in: %d, maxLen: %d" % (self.m_simpleAudioFileName, self.header().m_size_in, (maxLength - SIZE_OF_AUD_HEADER_IN_BYTES))
if self.header().m_size_in == 0:
# handle special case where only the header of the AUD file is present and the size_in is 0.
# fill the header with "valid" info for an empty wav file
self.header().m_size_out = 0
self.header().m_samplerate = 22050
self.header().m_compression = 0
self.header().m_flags = 2
self.header().m_populated = True
return True
else:
return False
else:
if self.header().m_compression == 1:
if (self.header().m_flags != 0):
@ -360,16 +372,16 @@ class audFile:
#
if __name__ == '__main__':
# main()
print "[Debug] Running %s as main module" % (my_module_name)
# assumes a file of name 000000.AUD in same directory
# (by default) assumes a file of name 000000.AUD in same directory
# otherwise tries to use the first command line argument as input file
inAUDFile = None
inAUDFileName = '00000000.AUD'
if len(sys.argv[1:]) > 0 \
and os.path.isfile(os.path.join('.', sys.argv[1])) \
and len (sys.argv[1]) > 5 \
and len(sys.argv[1]) > 5 \
and sys.argv[1][-3:] == 'AUD':
inAUDFileName = sys.argv[1]
print "[Debug] Using %s as input AUD file..." % (inAUDFileName)
print "[Info] Using %s as input AUD file..." % (inAUDFileName)
errorFound = False
try:
@ -381,10 +393,12 @@ if __name__ == '__main__':
if not errorFound:
allOfAudFileInBuffer = inAUDFile.read()
audFileInstance = audFile(True)
if audFileInstance.m_traceModeEnabled:
print "[Debug] Running %s (%s) as main module" % (MY_MODULE_NAME, MY_MODULE_VERSION)
audFileInstance.loadAudFile(allOfAudFileInBuffer, len(allOfAudFileInBuffer), inAUDFileName)
audFileInstance.export_as_wav(allOfAudFileInBuffer, './tmp.wav')
inAUDFile.close()
else:
#debug
#print "[Debug] Running %s imported from another module" % (my_module_name)
#print "[Debug] Running %s (%s) imported from another module" % (MY_MODULE_NAME, MY_MODULE_VERSION)
pass

View file

@ -394,6 +394,11 @@ def inputTLKsExport(inputTLKpath, outputWAVpath, pExportWavFilesMode, pExtractDe
if(offsetOfAUDEntry + sizeOfAUDEntry > allTlkFileSize):
print "[Error] audio file (AUD) file size mismatch with reported size in entry header!"
else:
targetSimpleWavFileName = targetSimpleAudFileName[:-4] + '.WAV' # remove the .AUD before adding the .WAV
if not fileIsMIX: # TLK file
(actorID, actorSName, localQuoteId) = getActorShortNameAndLocalQuoteIdByAUDHashID(idOfAUDEntry)
targetSimpleWavFileName = actorSName + '_' + str(localQuoteId).zfill(4) + '_' + ''.join('{:08X}'.format(idOfAUDEntry)).upper()+'.WAV'
audFileBuffer = inTLKorMIXFile.read(sizeOfAUDEntry)
if (len(audFileBuffer) == sizeOfAUDEntry):
# load audio file (AUD) file
@ -401,12 +406,6 @@ def inputTLKsExport(inputTLKpath, outputWAVpath, pExportWavFilesMode, pExtractDe
if (thisAudFile.loadAudFile(audFileBuffer, allTlkFileSize, targetSimpleAudFileName)):
if gTraceModeEnabled:
print "[Debug] Audio file (AUD) file %s was loaded successfully!" % (targetSimpleAudFileName)
# find
# print "[Debug] Emulating Wav write to appropriate folder..."
targetSimpleWavFileName = targetSimpleAudFileName[:-4] + '.WAV' # remove the .AUD before adding the .WAV
if not fileIsMIX: # TLK file
(actorID, actorSName, localQuoteId) = getActorShortNameAndLocalQuoteIdByAUDHashID(idOfAUDEntry)
targetSimpleWavFileName = actorSName + '_' + str(localQuoteId).zfill(4) + '_' + ''.join('{:08X}'.format(idOfAUDEntry)).upper()+'.WAV'
#print os.path.join(outputWAVpath, tmpTLKorMIXFileTuple[1], targetSimpleWavFileName)
# tmpTLKorMIXFileTuple[1] is the subfolder where the AUD -> WAV files for this archive are written
if not os.path.isfile(os.path.join(outputWAVpath, tmpTLKorMIXFileTuple[1], targetSimpleWavFileName) ):
@ -415,7 +414,7 @@ def inputTLKsExport(inputTLKpath, outputWAVpath, pExportWavFilesMode, pExtractDe
if gTraceModeEnabled:
print "[Info] Output file %s already exists. Skipping..." % (os.path.join(outputWAVpath, tmpTLKorMIXFileTuple[1], targetSimpleWavFileName))
else:
print "[Error] while loading audio file (AUD) %s!" % (targetSimpleAudFileName)
print "[Warning] Failed to load a proper audio file (AUD) %s (to export it to %s)! Size of input is: %d" % (targetSimpleAudFileName, targetSimpleWavFileName, sizeOfAUDEntry)
else:
print "[Error] while reading audio file (AUD) file %s into mem buffer" % (targetSimpleAudFileName)
#print "[Error] while reading audio file (AUD) file %s into mem buffer" % (''.join('{:08X}'.format(idOfMIXEntry)))

View file

@ -43,8 +43,8 @@ if (not osLibFound) \
from struct import *
my_module_version = "0.50"
my_module_name = "treFileLib"
MY_MODULE_VERSION = "0.50"
MY_MODULE_NAME = "treFileLib"
class TreHeader:
@ -129,10 +129,17 @@ class treFile:
#
if __name__ == '__main__':
# main()
print "[Debug] Running %s as main module" % (my_module_name)
# assumes a file of name ACTORS.TRE in same directory
# (by default) assumes a file of name ACTORS.TRE in same directory
# otherwise tries to use the first command line argument as input file
inTREFile = None
inTREFileName = 'ACTORS.TRE'
if len(sys.argv[1:]) > 0 \
and os.path.isfile(os.path.join('.', sys.argv[1])) \
and len(sys.argv[1]) > 5 \
and sys.argv[1][-3:] == 'TRE':
inTREFileName = sys.argv[1]
print "[Info] Using %s as input TRE file..." % (inTREFileName)
errorFound = False
@ -146,6 +153,9 @@ if __name__ == '__main__':
if not errorFound:
allOfTreFileInBuffer = inTREFile.read()
treFileInstance = treFile(True)
if treFileInstance.m_traceModeEnabled:
print "[Debug] Running %s (%s) as main module" % (MY_MODULE_NAME, MY_MODULE_VERSION)
if (treFileInstance.loadTreFile(allOfTreFileInBuffer, len(allOfTreFileInBuffer, inTREFileName))):
print "[Info] Text Resource file loaded successfully!"
else:
@ -153,5 +163,5 @@ if __name__ == '__main__':
inTREFile.close()
else:
#debug
#print "[Debug] Running %s imported from another module" % (my_module_name)
#print "[Debug] Running %s (%s) imported from another module" % (MY_MODULE_NAME, MY_MODULE_VERSION)
pass