Created
March 24, 2024 19:47
-
-
Save SuperSonicHub1/3c725c08215e3eb27aeb2f7651d78aac to your computer and use it in GitHub Desktop.
Sample extraction script for Roland SPD-SX PRO factory reset data
This file contains hidden or 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
""" | |
Sample extraction script for Roland SPD-SX PRO factory reset data | |
Resources: | |
- Factory Reset Data: https://www.roland.com/us/support/by_product/spd-sx_pro/updates_drivers/fe09f0e5-87a8-42e7-b1b8-24cf6280e93b/ | |
- Spec sheet: https://www.roland.com/us/products/spd-sx_pro/specifications/ | |
This code is public domain under the Unlicense: https://unlicense.org | |
""" | |
import re | |
from pathlib import Path | |
import subprocess | |
with open("wavePrm.bin", 'rb') as f: | |
# File stops having relevant info after this many bytes | |
NUM_BYTES = 0x3E330 | |
database_bytes = f.read(NUM_BYTES) | |
# Extract sample names, idents from database | |
# First group captures the sample name with a bit of whitespace, | |
# the second the ID number | |
PATTERN = rb"((?:\w|\s|[!?+-.])+)PRELOAD (\d{5})" | |
samples = dict( | |
(id_num.decode('ascii'), samp_name.decode('ascii').strip()) | |
for samp_name, id_num | |
in re.findall(PATTERN, database_bytes) | |
) | |
# Process samples | |
# SMP files are raw PCM. Roland specs told me that we're looking | |
# at 16-bit signed, 48k samples. I guessed that it was little endian | |
# and mono. | |
base = Path.cwd() / "Roland SPD-SX Pro Samples" | |
base.mkdir(exist_ok=True) | |
for d_num in range(16): | |
d_folder = base / ("D" + str(d_num).rjust(3, '0')) | |
d_folder.mkdir(exist_ok=True) | |
data_folder = Path.cwd() / 'DATA' | |
for (id_num, d_folder) in ((s.stem[1:], s.parent.stem) for s in data_folder.glob('**/*.SMP')): | |
subprocess.run( | |
[ | |
'ffmpeg', | |
'-f', | |
's16le', | |
'-ar', | |
'48k', | |
'-ac', | |
'1', | |
'-i', | |
str(data_folder / d_folder / f'W{id_num}.SMP'), | |
str(base / d_folder / f'{samples[id_num]} (W{id_num}).flac'), | |
], | |
check=True | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment