Skip to content

Instantly share code, notes, and snippets.

@vananasun
Created March 31, 2023 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vananasun/cc19eb8204d1f716d1303af604a1fd03 to your computer and use it in GitHub Desktop.
Save vananasun/cc19eb8204d1f716d1303af604a1fd03 to your computer and use it in GitHub Desktop.
Aliens vs Predator Atari Jaguar ROM audio extractor
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