Created
March 31, 2023 08:32
-
-
Save vananasun/cc19eb8204d1f716d1303af604a1fd03 to your computer and use it in GitHub Desktop.
Aliens vs Predator Atari Jaguar ROM audio extractor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wave | |
import struct | |
# Load audio bytes from ROM | |
rom_bytes = bytearray() | |
with open("Alien vs Predator (1994).jag", "rb") as rom_file: | |
rom_file.seek(1488614, 0) | |
rom_bytes += bytearray(rom_file.read(1596322)) | |
# Convert samples | |
samples = bytearray(len(rom_bytes) * 2) | |
for i, value in enumerate(rom_bytes): | |
if value < 128: | |
value *= value | |
else: | |
value -= 128 | |
value *= -value | |
struct.pack_into('<h', samples, 2*i, value) | |
# Save the output WAV file | |
with wave.open("output.wav", "wb") as wav_file: | |
wav_file.setsampwidth(2) | |
wav_file.setnchannels(1) | |
wav_file.setframerate(8000) | |
wav_file.setnframes(len(samples)) | |
wav_file.writeframes(samples) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment