Skip to content

Commit 1b1070d

Browse files
authored
Seperate baserom segments dir from output dir (#2498)
1 parent 7416f41 commit 1b1070d

File tree

3 files changed

+37
-36
lines changed

3 files changed

+37
-36
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ setup: venv
796796
$(PYTHON) tools/extract_incbins.py $(EXTRACTED_DIR)/baserom $(EXTRACTED_DIR)/incbin -v $(VERSION)
797797
$(PYTHON) tools/extract_text.py $(EXTRACTED_DIR)/baserom $(EXTRACTED_DIR)/text -v $(VERSION)
798798
$(PYTHON) tools/extract_assets.py $(EXTRACTED_DIR)/baserom $(EXTRACTED_DIR)/assets -v $(VERSION) -j$(N_THREADS)
799-
$(PYTHON) tools/extract_audio.py -o $(EXTRACTED_DIR) -v $(VERSION) --read-xml
799+
$(PYTHON) tools/extract_audio.py -b $(EXTRACTED_DIR)/baserom -o $(EXTRACTED_DIR) -v $(VERSION) --read-xml
800800

801801
disasm:
802802
$(RM) -r $(EXPECTED_DIR)

tools/audio/extraction/audio_extract.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GameVersionInfo:
4949
# Run
5050
# ======================================================================================================================
5151

52-
def collect_sample_banks(audiotable_seg : memoryview, extracted_dir : str, version_info : GameVersionInfo,
52+
def collect_sample_banks(audiotable_seg : memoryview, output_dir : str, version_info : GameVersionInfo,
5353
table : AudioCodeTable, samplebank_descs : Dict[int, SampleBankExtractionDescription]):
5454
sample_banks : List[Union[AudioTableFile, int]] = []
5555

@@ -76,7 +76,7 @@ def collect_sample_banks(audiotable_seg : memoryview, extracted_dir : str, versi
7676
extraction_desc=samplebank_descs.get(i, None))
7777

7878
if BASEROM_DEBUG:
79-
bank.dump_bin(f"{extracted_dir}/baserom_audiotest/audiotable_files/{bank.file_name}.bin")
79+
bank.dump_bin(f"{output_dir}/baserom_audiotest/audiotable_files/{bank.file_name}.bin")
8080

8181
sample_banks.append(bank)
8282

@@ -90,7 +90,7 @@ def bank_data_lookup(sample_banks : List[Union[AudioTableFile, int]], e : Union[
9090
else:
9191
return e
9292

93-
def collect_soundfonts(audiobank_seg : memoryview, extracted_dir : str, version_info : GameVersionInfo,
93+
def collect_soundfonts(audiobank_seg : memoryview, output_dir : str, version_info : GameVersionInfo,
9494
sound_font_table : AudioCodeTable, soundfont_descs : Dict[int, SoundFontExtractionDescription],
9595
sample_banks : List[Union[AudioTableFile, int]]):
9696
soundfonts = []
@@ -110,7 +110,7 @@ def collect_soundfonts(audiobank_seg : memoryview, extracted_dir : str, version_
110110

111111
if BASEROM_DEBUG:
112112
# Write the individual file for debugging and comparison
113-
soundfont.dump_bin(f"{extracted_dir}/baserom_audiotest/audiobank_files/{soundfont.file_name}.bin")
113+
soundfont.dump_bin(f"{output_dir}/baserom_audiotest/audiobank_files/{soundfont.file_name}.bin")
114114

115115
return soundfonts
116116

@@ -133,17 +133,17 @@ def aifc_extract_one_bin(base_path : str, sample : AudioTableData):
133133
else:
134134
sample.to_file(f"{base_path}/{sample.filename}")
135135

136-
def extract_samplebank(pool : ThreadPool, extracted_dir : str, sample_banks : List[Union[AudioTableFile, int]],
136+
def extract_samplebank(pool : ThreadPool, output_dir : str, sample_banks : List[Union[AudioTableFile, int]],
137137
bank : AudioTableFile, write_xml : bool):
138138
# deal with remaining gaps, have to blob them unless we can find an exact match in another bank
139139
bank.finalize_coverage(sample_banks)
140140
# assign names
141141
bank.assign_names()
142142

143-
base_path = f"{extracted_dir}/assets/audio/samples/{bank.name}"
143+
base_path = f"{output_dir}/assets/audio/samples/{bank.name}"
144144

145145
# write xml
146-
with open(f"{extracted_dir}/assets/audio/samplebanks/{bank.file_name}.xml", "w") as outfile:
146+
with open(f"{output_dir}/assets/audio/samplebanks/{bank.file_name}.xml", "w") as outfile:
147147
outfile.write(bank.to_xml(f"assets/audio/samples/{bank.name}"))
148148

149149
# write the extraction xml if specified
@@ -175,17 +175,17 @@ def extract_samplebank(pool : ThreadPool, extracted_dir : str, sample_banks : Li
175175
if not BASEROM_DEBUG:
176176
shutil.rmtree(f"{base_path}/aifc")
177177

178-
def disassemble_one_sequence(extracted_dir : str, version_info : GameVersionInfo, soundfonts : List[AudiobankFile],
178+
def disassemble_one_sequence(output_dir : str, version_info : GameVersionInfo, soundfonts : List[AudiobankFile],
179179
enum_names : List[str], id : int, data : bytes, name : str, filename : str,
180180
fonts : memoryview):
181-
out_filename = f"{extracted_dir}/assets/audio/sequences/{filename}.seq"
181+
out_filename = f"{output_dir}/assets/audio/sequences/{filename}.seq"
182182
disas = SequenceDisassembler(id, data, version_info.seq_disas_tables.get(id, None), CMD_SPEC,
183183
version_info.mml_version, out_filename, name,
184184
[soundfonts[i] for i in fonts], enum_names)
185185
disas.analyze()
186186
disas.emit()
187187

188-
def extract_sequences(audioseq_seg : memoryview, extracted_dir : str, version_info : GameVersionInfo, write_xml : bool,
188+
def extract_sequences(audioseq_seg : memoryview, output_dir : str, version_info : GameVersionInfo, write_xml : bool,
189189
sequence_table : AudioCodeTable, sequence_font_table : memoryview,
190190
sequence_descs : Dict[int, SequenceExtractionDescription], soundfonts : List[AudiobankFile]):
191191

@@ -198,9 +198,9 @@ def extract_sequences(audioseq_seg : memoryview, extracted_dir : str, version_in
198198
assert len(seq_enum_names) == len(sequence_table)
199199

200200
if BASEROM_DEBUG:
201-
os.makedirs(f"{extracted_dir}/baserom_audiotest/audioseq_files", exist_ok=True)
201+
os.makedirs(f"{output_dir}/baserom_audiotest/audioseq_files", exist_ok=True)
202202

203-
os.makedirs(f"{extracted_dir}/assets/audio/sequences", exist_ok=True)
203+
os.makedirs(f"{output_dir}/assets/audio/sequences", exist_ok=True)
204204
if write_xml:
205205
os.makedirs(f"assets/xml/audio/sequences", exist_ok=True)
206206

@@ -235,7 +235,7 @@ def extract_sequences(audioseq_seg : memoryview, extracted_dir : str, version_in
235235

236236
if BASEROM_DEBUG:
237237
# Extract original sequence binary for comparison
238-
with open(f"{extracted_dir}/baserom_audiotest/audioseq_files/seq_{i}{ext}.aseq", "wb") as outfile:
238+
with open(f"{output_dir}/baserom_audiotest/audioseq_files/seq_{i}{ext}.aseq", "wb") as outfile:
239239
outfile.write(seq_data)
240240

241241
extraction_desc = sequence_descs.get(i, None)
@@ -301,12 +301,12 @@ def extract_sequences(audioseq_seg : memoryview, extracted_dir : str, version_in
301301
# Disassemble to text
302302

303303
for job in disas_jobs:
304-
disassemble_one_sequence(extracted_dir, version_info, soundfonts, seq_enum_names, *job)
304+
disassemble_one_sequence(output_dir, version_info, soundfonts, seq_enum_names, *job)
305305

306306
dt = time.time() - t
307307
print(f"Sequences extraction took {dt:.3f}s")
308308

309-
def extract_audio_for_version(version_info : GameVersionInfo, extracted_dir : str, read_xml : bool, write_xml : bool):
309+
def extract_audio_for_version(version_info : GameVersionInfo, output_dir : str, baserom_segments_dir : str, read_xml : bool, write_xml : bool):
310310
print("Setting up...")
311311

312312
# Open baserom segments
@@ -316,16 +316,16 @@ def extract_audio_for_version(version_info : GameVersionInfo, extracted_dir : st
316316
audiobank_seg = None
317317
audioseq_seg = None
318318

319-
with open(f"{extracted_dir}/baserom/code", "rb") as infile:
319+
with open(f"{baserom_segments_dir}/code", "rb") as infile:
320320
code_seg = memoryview(infile.read())
321321

322-
with open(f"{extracted_dir}/baserom/Audiotable", "rb") as infile:
322+
with open(f"{baserom_segments_dir}/Audiotable", "rb") as infile:
323323
audiotable_seg = memoryview(infile.read())
324324

325-
with open(f"{extracted_dir}/baserom/Audiobank", "rb") as infile:
325+
with open(f"{baserom_segments_dir}/Audiobank", "rb") as infile:
326326
audiobank_seg = memoryview(infile.read())
327327

328-
with open(f"{extracted_dir}/baserom/Audioseq", "rb") as infile:
328+
with open(f"{baserom_segments_dir}/Audioseq", "rb") as infile:
329329
audioseq_seg = memoryview(infile.read())
330330

331331
# ==================================================================================================================
@@ -342,18 +342,18 @@ def extract_audio_for_version(version_info : GameVersionInfo, extracted_dir : st
342342
if BASEROM_DEBUG:
343343
# Extract Table Binaries
344344

345-
os.makedirs(f"{extracted_dir}/baserom_audiotest/audio_code_tables/", exist_ok=True)
345+
os.makedirs(f"{output_dir}/baserom_audiotest/audio_code_tables/", exist_ok=True)
346346

347-
with open(f"{extracted_dir}/baserom_audiotest/audio_code_tables/samplebank_table.bin", "wb") as outfile:
347+
with open(f"{output_dir}/baserom_audiotest/audio_code_tables/samplebank_table.bin", "wb") as outfile:
348348
outfile.write(sample_bank_table.data)
349349

350-
with open(f"{extracted_dir}/baserom_audiotest/audio_code_tables/soundfont_table.bin", "wb") as outfile:
350+
with open(f"{output_dir}/baserom_audiotest/audio_code_tables/soundfont_table.bin", "wb") as outfile:
351351
outfile.write(sound_font_table.data)
352352

353-
with open(f"{extracted_dir}/baserom_audiotest/audio_code_tables/sequence_table.bin", "wb") as outfile:
353+
with open(f"{output_dir}/baserom_audiotest/audio_code_tables/sequence_table.bin", "wb") as outfile:
354354
outfile.write(sequence_table.data)
355355

356-
with open(f"{extracted_dir}/baserom_audiotest/audio_code_tables/sequence_font_table.bin", "wb") as outfile:
356+
with open(f"{output_dir}/baserom_audiotest/audio_code_tables/sequence_font_table.bin", "wb") as outfile:
357357
outfile.write(sequence_font_table)
358358

359359
# ==================================================================================================================
@@ -384,16 +384,16 @@ def walk_xmls(T : type, out_dict : Dict[int, ExtractionDescription], path : str)
384384
# ==================================================================================================================
385385

386386
if BASEROM_DEBUG:
387-
os.makedirs(f"{extracted_dir}/baserom_audiotest/audiotable_files", exist_ok=True)
388-
sample_banks = collect_sample_banks(audiotable_seg, extracted_dir, version_info, sample_bank_table, samplebank_descs)
387+
os.makedirs(f"{output_dir}/baserom_audiotest/audiotable_files", exist_ok=True)
388+
sample_banks = collect_sample_banks(audiotable_seg, output_dir, version_info, sample_bank_table, samplebank_descs)
389389

390390
# ==================================================================================================================
391391
# Collect soundfonts
392392
# ==================================================================================================================
393393

394394
if BASEROM_DEBUG:
395-
os.makedirs(f"{extracted_dir}/baserom_audiotest/audiobank_files", exist_ok=True)
396-
soundfonts = collect_soundfonts(audiobank_seg, extracted_dir, version_info, sound_font_table, soundfont_descs,
395+
os.makedirs(f"{output_dir}/baserom_audiotest/audiobank_files", exist_ok=True)
396+
soundfonts = collect_soundfonts(audiobank_seg, output_dir, version_info, sound_font_table, soundfont_descs,
397397
sample_banks)
398398

399399
# ==================================================================================================================
@@ -413,22 +413,22 @@ def walk_xmls(T : type, out_dict : Dict[int, ExtractionDescription], path : str)
413413
# Check that the sampleconv binary is available
414414
assert os.path.isfile(SAMPLECONV_PATH) , "Compile sampleconv"
415415

416-
os.makedirs(f"{extracted_dir}/assets/audio/samplebanks", exist_ok=True)
416+
os.makedirs(f"{output_dir}/assets/audio/samplebanks", exist_ok=True)
417417
if write_xml:
418418
os.makedirs(f"assets/xml/audio/samplebanks", exist_ok=True)
419419

420420
with ThreadPool(processes=os.cpu_count()) as pool:
421421
for bank in sample_banks:
422422
if isinstance(bank, AudioTableFile):
423-
extract_samplebank(pool, extracted_dir, sample_banks, bank, write_xml)
423+
extract_samplebank(pool, output_dir, sample_banks, bank, write_xml)
424424

425425
# ==================================================================================================================
426426
# Extract soundfonts
427427
# ==================================================================================================================
428428

429429
print("Extracting soundfonts...")
430430

431-
os.makedirs(f"{extracted_dir}/assets/audio/soundfonts", exist_ok=True)
431+
os.makedirs(f"{output_dir}/assets/audio/soundfonts", exist_ok=True)
432432
if write_xml:
433433
os.makedirs(f"assets/xml/audio/soundfonts", exist_ok=True)
434434

@@ -441,7 +441,7 @@ def walk_xmls(T : type, out_dict : Dict[int, ExtractionDescription], path : str)
441441
sf.finalize()
442442

443443
# write the soundfont xml itself
444-
with open(f"{extracted_dir}/assets/audio/soundfonts/{sf.file_name}.xml", "w") as outfile:
444+
with open(f"{output_dir}/assets/audio/soundfonts/{sf.file_name}.xml", "w") as outfile:
445445
outfile.write(sf.to_xml(f"Soundfont_{i}", "assets/audio/samplebanks"))
446446

447447
# write the extraction xml if specified
@@ -454,5 +454,5 @@ def walk_xmls(T : type, out_dict : Dict[int, ExtractionDescription], path : str)
454454

455455
print("Extracting sequences...")
456456

457-
extract_sequences(audioseq_seg, extracted_dir, version_info, write_xml, sequence_table, sequence_font_table,
457+
extract_sequences(audioseq_seg, output_dir, version_info, write_xml, sequence_table, sequence_font_table,
458458
sequence_descs, soundfonts)

tools/extract_audio.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
if __name__ == '__main__':
1616
parser = argparse.ArgumentParser(description="baserom audio asset extractor")
17-
parser.add_argument("-o", "--extracted-dir", required=True, help="path to extracted directory")
17+
parser.add_argument("-b", "--baserom-segments-dir", required=True, help="Directory of uncompressed ROM segments")
18+
parser.add_argument("-o", "--output-dir", required=True, help="path to output directory")
1819
parser.add_argument("-v", "--version", required=True, help="version name")
1920
parser.add_argument("--read-xml", required=False, action="store_true", help="Read extraction xml files")
2021
parser.add_argument("--write-xml", required=False, action="store_true", help="Write extraction xml files")
@@ -196,4 +197,4 @@
196197
audiotable_buffer_bugs,
197198
seq_disas_tables)
198199

199-
extract_audio_for_version(version_info, args.extracted_dir, args.read_xml, args.write_xml)
200+
extract_audio_for_version(version_info, args.output_dir, args.baserom_segments_dir, args.read_xml, args.write_xml)

0 commit comments

Comments
 (0)