def decode_at3(input, sample_rate, channels): data = bytearray(open(input, "rb").read()) wav_header = bytearray() wav_header += bytearray("RIFF", "ascii") wav_header += int.to_bytes(len(data) + 0x3c, length=4, byteorder="little") wav_header += bytearray("WAVE", "ascii") wav_header += bytearray("fmt ", "ascii") wav_header += int.to_bytes(0x20, length=4, byteorder="little") format_id = 0x270 byte_rate = 0x4099 block_align = 0x180 bits_per_sample = 0 wav_header += int.to_bytes(format_id, length=2, byteorder="little") wav_header += int.to_bytes(channels, length=2, byteorder="little") wav_header += int.to_bytes(sample_rate, length=4, byteorder="little") wav_header += int.to_bytes(byte_rate, length=4, byteorder="little") wav_header += int.to_bytes(block_align, length=2, byteorder="little") wav_header += int.to_bytes(bits_per_sample, length=2, byteorder="little") wav_header += int.to_bytes(0x0e, length=2, byteorder="little") wav_header += int.to_bytes(0x01, length=2, byteorder="little") wav_header += int.to_bytes(0x1000, length=2, byteorder="little") wav_header += int.to_bytes(0x00, length=2, byteorder="little") wav_header += int.to_bytes(0x00, length=4, byteorder="little") wav_header += int.to_bytes(0x01, length=4, byteorder="little") wav_header += bytearray("data", "ascii") wav_header += int.to_bytes(len(data), length=4, byteorder="little") wav_header += data tmp_filename = tmpfile.mkstemp(suffix=".at3") with open(tmp_filename, "wb") as outfile: outfile.write(wav_header) sound = audio.get_audio_file(tmp_filename) tmpfile.tmpcleanup() return sound
bgms = [x for x in filenames_bgm if x.endswith("d__k.bin")] if len(bgms) == 0: bgms = [x for x in filenames_bgm if x.endswith("d_bk.bin")] drum_bgm = bgms[0] if len(bgms) > 0 else None drum_bgm_out = drum_bgm.replace(".bin", ".wav") if len(bgms) > 0 else None # Get guitar+bass BGM bgms = [x for x in filenames_bgm if x.endswith("_gbk.bin")] guitar_bgm = bgms[0] if len(bgms) > 0 else None guitar_bgm_out = guitar_bgm.replace(".bin", ".wav") if len(bgms) > 0 else None if args.mix_phase and not base_bgm: print("Couldn't find base BGM") tmpfile.tmpcleanup() exit(1) if not drum_bgm: print("Couldn't find drum BGM") tmpfile.tmpcleanup() exit(1) if not guitar_bgm: print("Couldn't find guitar BGM") tmpfile.tmpcleanup() exit(1) tmpfile.add_temp_file(drum_bgm_out) tmpfile.add_temp_file(guitar_bgm_out)