From 0ddc36d58f886d55db2081b95a014e64f412bbcf Mon Sep 17 00:00:00 2001 From: UnitedAirforce Date: Thu, 30 Jan 2025 08:13:06 +0800 Subject: [PATCH] added shot/bgm convert script --- .../8.py | 32 +++++++++++++++++++ .../readme.txt | 4 +++ 2 files changed, 36 insertions(+) create mode 100644 various-tools/4max & pc BGM + SHOT to 2OS BGM & SHOT/8.py create mode 100644 various-tools/4max & pc BGM + SHOT to 2OS BGM & SHOT/readme.txt diff --git a/various-tools/4max & pc BGM + SHOT to 2OS BGM & SHOT/8.py b/various-tools/4max & pc BGM + SHOT to 2OS BGM & SHOT/8.py new file mode 100644 index 0000000..adf568b --- /dev/null +++ b/various-tools/4max & pc BGM + SHOT to 2OS BGM & SHOT/8.py @@ -0,0 +1,32 @@ +import numpy as np +import scipy.io.wavfile as wav +import os + +file1 = input("Enter the first WAV file (music track): ").strip() +file2 = input("Enter the second WAV file (SFX track): ").strip() + +rate1, data1 = wav.read(file1) +rate2, data2 = wav.read(file2) + +if rate1 != rate2: + raise ValueError("Sample rate mismatch!") + +if data1.ndim != data2.ndim: + raise ValueError("Channel count mismatch!") + +# Convert to int32, addition (not normalization), then cap values. +data1 = data1.astype(np.int32) +data2 = data2.astype(np.int32) + +mixed = data1 + data2 + +mixed = np.clip(mixed, -32768, 32767) + +mixed = mixed.astype(np.int16) + +dir_name, base_name = os.path.split(file2) +output_file = os.path.join(dir_name, "1_" + base_name) + +wav.write(output_file, rate1, mixed) + +print(f"Mixing complete! Saved as {output_file}") \ No newline at end of file diff --git a/various-tools/4max & pc BGM + SHOT to 2OS BGM & SHOT/readme.txt b/various-tools/4max & pc BGM + SHOT to 2OS BGM & SHOT/readme.txt new file mode 100644 index 0000000..535caff --- /dev/null +++ b/various-tools/4max & pc BGM + SHOT to 2OS BGM & SHOT/readme.txt @@ -0,0 +1,4 @@ +The 2 platform uses BGM + SHOT, but mobile uses BGM or SHOT. +This requires reprocessing the SHOT audio. +Layering the audios directly (in audition, for example) won't work because the volume won't be preserved due to potential overflow of int16. +This script preserves the volume by calculating things in int32 before capping everything back, ensuring that the audio volume stays consistent. \ No newline at end of file