SLOOP 2.2: new drum engine, 68 sounds by kind, grand piano, stereo effects

This commit is contained in:
isod89 committed 2026-10-04 23:18:48 -04:00
1 parent e421e4362e
commit f2b44c219b
73 files changed
+2087 -545

No files matched your search

+578
View File
@@ -0,0 +1,578 @@
{
"808": {
"KICK": 2.0,
"SNARE": -1.25,
"CLAP": 12.25,
"CHH": 19.5,
"OHH": 14.0,
"TOMLO": -0.25,
"TOMHI": -0.75,
"CRASH": -0.25,
"RIDE": 4.5,
"SHAKER": 1.75,
"CONGA": -0.25,
"RIM": 7.25,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.5,
"SNARE2": 5.25
},
"909": {
"KICK": 0.0,
"SNARE": 1.75,
"CLAP": 10.75,
"CHH": 11.5,
"OHH": 4.75,
"TOMLO": 0.25,
"TOMHI": 0.0,
"CRASH": -0.5,
"RIDE": 3.5,
"SHAKER": 1.5,
"CONGA": -0.25,
"RIM": 5.0,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.25,
"SNARE2": 4.75
},
"606": {
"KICK": 2.25,
"SNARE": 3.0,
"CLAP": 13.0,
"CHH": 20.5,
"OHH": 17.0,
"TOMLO": 2.25,
"TOMHI": 2.0,
"CRASH": 7.25,
"RIDE": 4.5,
"SHAKER": 1.75,
"CONGA": -0.25,
"RIM": 6.0,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": 1.75,
"SNARE2": 4.75
},
"80S": {
"KICK": 1.75,
"SNARE": -1.0,
"CLAP": 9.5,
"CHH": 12.5,
"OHH": 6.0,
"TOMLO": -1.5,
"TOMHI": -1.75,
"CRASH": -0.25,
"RIDE": 4.5,
"SHAKER": 2.25,
"CONGA": -0.25,
"RIM": 6.25,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": 0.5,
"SNARE2": 4.25
},
"VINTAGE": {
"KICK": 2.0,
"SNARE": 4.25,
"CLAP": 15.75,
"CHH": 20.25,
"OHH": 18.25,
"TOMLO": 2.5,
"TOMHI": 2.5,
"CRASH": -0.75,
"RIDE": 4.0,
"SHAKER": 4.0,
"CONGA": 1.5,
"RIM": 1.25,
"COWBELL": 5.75,
"CLAVE": 1.25,
"KICK2": 2.0,
"SNARE2": 4.75
},
"TRAP": {
"KICK": 0.0,
"SNARE": 1.75,
"CLAP": 10.75,
"CHH": 20.0,
"OHH": 14.75,
"TOMLO": -0.25,
"TOMHI": -0.75,
"CRASH": 0.0,
"RIDE": 4.5,
"SHAKER": 2.0,
"CONGA": -0.25,
"RIM": 7.25,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -1.5,
"SNARE2": 4.25
},
"DRILL": {
"KICK": 1.25,
"SNARE": 1.75,
"CLAP": 9.5,
"CHH": 18.75,
"OHH": 14.0,
"TOMLO": -0.25,
"TOMHI": -0.75,
"CRASH": -0.25,
"RIDE": 4.5,
"SHAKER": 1.75,
"CONGA": -0.25,
"RIM": 4.5,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -1.75,
"SNARE2": 5.75
},
"BOOMBAP": {
"KICK": -0.75,
"SNARE": 0.5,
"CLAP": 11.5,
"CHH": 16.25,
"OHH": 9.5,
"TOMLO": 0.25,
"TOMHI": 0.0,
"CRASH": 0.0,
"RIDE": 3.75,
"SHAKER": 2.0,
"CONGA": -0.25,
"RIM": 5.75,
"COWBELL": 5.5,
"CLAVE": 1.75,
"KICK2": -1.25,
"SNARE2": 1.75
},
"LO-FI": {
"KICK": 0.75,
"SNARE": 1.25,
"CLAP": 13.0,
"CHH": 18.75,
"OHH": 13.0,
"TOMLO": -0.25,
"TOMHI": -0.75,
"CRASH": 6.5,
"RIDE": 7.5,
"SHAKER": 2.5,
"CONGA": -0.25,
"RIM": 7.25,
"COWBELL": 5.5,
"CLAVE": 1.75,
"KICK2": 0.25,
"SNARE2": 4.75
},
"PHONK": {
"KICK": -1.75,
"SNARE": -0.75,
"CLAP": 14.0,
"CHH": 20.25,
"OHH": 15.0,
"TOMLO": -0.25,
"TOMHI": -0.75,
"CRASH": -0.25,
"RIDE": 4.5,
"SHAKER": 2.0,
"CONGA": -0.25,
"RIM": 6.75,
"COWBELL": -6.5,
"CLAVE": 1.75,
"KICK2": -2.0,
"SNARE2": 5.0
},
"HOUSE": {
"KICK": 0.0,
"SNARE": 1.75,
"CLAP": 10.25,
"CHH": 11.75,
"OHH": 5.5,
"TOMLO": 0.25,
"TOMHI": 0.0,
"CRASH": -0.25,
"RIDE": 3.5,
"SHAKER": 1.5,
"CONGA": -0.25,
"RIM": 6.25,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.25,
"SNARE2": 4.75
},
"D.HOUSE": {
"KICK": 0.75,
"SNARE": 2.25,
"CLAP": 13.25,
"CHH": 16.25,
"OHH": 9.5,
"TOMLO": 0.25,
"TOMHI": 0.0,
"CRASH": -0.25,
"RIDE": 3.5,
"SHAKER": 1.25,
"CONGA": -0.25,
"RIM": 4.5,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.25,
"SNARE2": 5.0
},
"TECHNO": {
"KICK": -1.75,
"SNARE": 1.75,
"CLAP": 8.5,
"CHH": 14.75,
"OHH": 6.0,
"TOMLO": 0.25,
"TOMHI": 0.0,
"CRASH": -0.25,
"RIDE": 5.5,
"SHAKER": 1.75,
"CONGA": -0.25,
"RIM": 1.75,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -2.0,
"SNARE2": 3.75
},
"MINIMAL": {
"KICK": 2.0,
"SNARE": 2.75,
"CLAP": 12.5,
"CHH": 16.5,
"OHH": 16.0,
"TOMLO": -0.25,
"TOMHI": -0.75,
"CRASH": 0.0,
"RIDE": 4.5,
"SHAKER": 1.75,
"CONGA": 0.25,
"RIM": 7.5,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": 1.75,
"SNARE2": 4.75
},
"ELECTRO": {
"KICK": -0.25,
"SNARE": -1.5,
"CLAP": 13.5,
"CHH": 20.25,
"OHH": 17.0,
"TOMLO": 0.5,
"TOMHI": -0.25,
"CRASH": 0.0,
"RIDE": 4.5,
"SHAKER": 1.75,
"CONGA": -0.25,
"RIM": 6.75,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.5,
"SNARE2": 4.5
},
"DISCO": {
"KICK": 1.75,
"SNARE": 1.75,
"CLAP": 11.25,
"CHH": 11.75,
"OHH": 4.5,
"TOMLO": -1.75,
"TOMHI": -2.0,
"CRASH": 0.0,
"RIDE": 3.5,
"SHAKER": 2.0,
"CONGA": -0.25,
"RIM": 5.25,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.25,
"SNARE2": 4.0
},
"GARAGE": {
"KICK": 0.75,
"SNARE": 1.75,
"CLAP": 9.0,
"CHH": 13.25,
"OHH": 5.0,
"TOMLO": 0.25,
"TOMHI": 0.0,
"CRASH": -0.25,
"RIDE": 3.5,
"SHAKER": 1.25,
"CONGA": -0.25,
"RIM": 5.0,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.25,
"SNARE2": 4.0
},
"JUNGLE": {
"KICK": 1.25,
"SNARE": -0.25,
"CLAP": 10.75,
"CHH": 12.5,
"OHH": 4.75,
"TOMLO": 0.25,
"TOMHI": 0.0,
"CRASH": -0.25,
"RIDE": 4.25,
"SHAKER": 1.75,
"CONGA": -0.25,
"RIM": 5.75,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.25,
"SNARE2": 1.75
},
"DUBSTEP": {
"KICK": -1.0,
"SNARE": -6.25,
"CLAP": 10.5,
"CHH": 11.0,
"OHH": 5.75,
"TOMLO": 0.25,
"TOMHI": 0.0,
"CRASH": -0.25,
"RIDE": 3.75,
"SHAKER": 1.75,
"CONGA": -0.25,
"RIM": 6.5,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.25,
"SNARE2": 4.5
},
"DEMBOW": {
"KICK": 1.0,
"SNARE": 1.75,
"CLAP": 11.25,
"CHH": 20.5,
"OHH": 14.0,
"TOMLO": -0.25,
"TOMHI": -0.75,
"CRASH": 0.0,
"RIDE": 4.5,
"SHAKER": 1.25,
"CONGA": -0.25,
"RIM": 5.5,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.5,
"SNARE2": 5.0
},
"AMAPIANO": {
"KICK": 1.75,
"SNARE": -0.5,
"CLAP": 10.75,
"CHH": 19.75,
"OHH": 14.0,
"TOMLO": -0.25,
"TOMHI": -0.75,
"CRASH": 0.0,
"RIDE": 4.5,
"SHAKER": -0.5,
"CONGA": -0.5,
"RIM": 6.75,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -2.25,
"SNARE2": 4.75
},
"AFRO": {
"KICK": 2.0,
"SNARE": 4.75,
"CLAP": 10.25,
"CHH": 20.5,
"OHH": 14.0,
"TOMLO": 1.5,
"TOMHI": 1.5,
"CRASH": 0.0,
"RIDE": 4.5,
"SHAKER": 0.75,
"CONGA": -0.5,
"RIM": 6.0,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.5,
"SNARE2": 6.0
},
"LATIN": {
"KICK": 2.25,
"SNARE": 4.25,
"CLAP": 16.5,
"CHH": 20.25,
"OHH": 18.25,
"TOMLO": 0.75,
"TOMHI": 0.75,
"CRASH": -0.5,
"RIDE": 4.0,
"SHAKER": 3.75,
"CONGA": -0.5,
"RIM": 1.75,
"COWBELL": 6.25,
"CLAVE": 0.75,
"KICK2": 2.0,
"SNARE2": 4.25
},
"TRIBAL": {
"KICK": 1.75,
"SNARE": 0.5,
"CLAP": 11.0,
"CHH": 14.75,
"OHH": 9.75,
"TOMLO": -0.75,
"TOMHI": -1.75,
"CRASH": 0.0,
"RIDE": 4.5,
"SHAKER": 2.0,
"CONGA": -1.25,
"RIM": 6.25,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.5,
"SNARE2": 5.0
},
"SYNTHWV": {
"KICK": 1.75,
"SNARE": -3.75,
"CLAP": 11.0,
"CHH": 13.25,
"OHH": 6.0,
"TOMLO": -1.75,
"TOMHI": -2.5,
"CRASH": -0.25,
"RIDE": 4.5,
"SHAKER": 1.5,
"CONGA": -0.25,
"RIM": 6.5,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": 0.5,
"SNARE2": 3.25
},
"CHIP": {
"KICK": 6.0,
"SNARE": 3.0,
"CLAP": 2.5,
"CHH": -1.5,
"OHH": -8.25,
"TOMLO": 4.0,
"TOMHI": 3.75,
"CRASH": -10.75,
"RIDE": -6.5,
"SHAKER": -4.0,
"CONGA": 2.75,
"RIM": 7.25,
"COWBELL": 1.0,
"CLAVE": 4.5,
"KICK2": 2.25,
"SNARE2": 4.0
},
"ARCADE": {
"KICK": 0.75,
"SNARE": 3.25,
"CLAP": 11.75,
"CHH": -1.5,
"OHH": -5.25,
"TOMLO": 1.0,
"TOMHI": 0.25,
"CRASH": -5.5,
"RIDE": -8.75,
"SHAKER": 4.75,
"CONGA": 0.5,
"RIM": 3.0,
"COWBELL": -0.5,
"CLAVE": 3.5,
"KICK2": -2.0,
"SNARE2": 2.25
},
"GLITCH": {
"KICK": 1.75,
"SNARE": 7.0,
"CLAP": 11.75,
"CHH": -0.25,
"OHH": -3.0,
"TOMLO": 2.75,
"TOMHI": 2.5,
"CRASH": -5.25,
"RIDE": -8.75,
"SHAKER": 4.75,
"CONGA": 0.5,
"RIM": 3.5,
"COWBELL": -0.5,
"CLAVE": 3.5,
"KICK2": -2.0,
"SNARE2": 1.25
},
"INDUSTR": {
"KICK": -2.0,
"SNARE": -4.25,
"CLAP": 10.75,
"CHH": 17.25,
"OHH": 12.0,
"TOMLO": -7.0,
"TOMHI": -7.75,
"CRASH": 4.5,
"RIDE": 3.75,
"SHAKER": 1.75,
"CONGA": -0.25,
"RIM": 5.25,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.25,
"SNARE2": 4.25
},
"HYPER": {
"KICK": -2.0,
"SNARE": -2.75,
"CLAP": 9.25,
"CHH": 13.5,
"OHH": 5.25,
"TOMLO": 0.25,
"TOMHI": 0.0,
"CRASH": -0.5,
"RIDE": 3.75,
"SHAKER": 1.75,
"CONGA": -0.25,
"RIM": 5.75,
"COWBELL": 5.25,
"CLAVE": 1.75,
"KICK2": -0.25,
"SNARE2": 4.5
},
"AMBIENT": {
"KICK": 3.25,
"SNARE": 5.75,
"CLAP": 15.75,
"CHH": 21.25,
"OHH": 15.0,
"TOMLO": -1.75,
"TOMHI": -2.25,
"CRASH": 0.25,
"RIDE": 8.0,
"SHAKER": 0.0,
"CONGA": -1.75,
"RIM": 6.5,
"COWBELL": 5.0,
"CLAVE": 0.25,
"KICK2": -2.0,
"SNARE2": 4.5
},
"JAZZ": {
"KICK": 3.5,
"SNARE": 10.25,
"CLAP": 10.75,
"CHH": 14.75,
"OHH": 9.0,
"TOMLO": -0.25,
"TOMHI": -0.5,
"CRASH": -1.5,
"RIDE": 3.5,
"SHAKER": 0.0,
"CONGA": -1.75,
"RIM": 6.0,
"COWBELL": 5.0,
"CLAVE": 0.25,
"KICK2": 4.0,
"SNARE2": 5.75
}
}
+12
View File
@@ -30,6 +30,18 @@ PICK = {
("Membranophones/Struck Membranophones/Conga", r"Conga_HitN_v2_rr1"),
("Idiophones/Struck Idiophones/Claves", r"Claves1_Hit_v2"),
("Idiophones/Struck Idiophones/Woodblock", r"wood_click_mp"),
# the acoustic kit (gen_samples.py names them by role and cuts them; ATTRIBUTION.txt lists each)
("Membranophones/Struck Membranophones/Bass Drum 1", r"BDrumNew_hit_v5_rr1"),
("Membranophones/Struck Membranophones/Snare Drum, Modern 1", r"Snare2_HitSN_v7_rr1"),
("Membranophones/Struck Membranophones/Legacy Snares/OldSnare", r"snare_rim"),
("Idiophones/Struck Idiophones/Claps", r"Clap_rr1"),
("Idiophones/Struck Idiophones/Hi-Hat Cymbal", r"HiHat_HitC_v3_rr1"),
("Idiophones/Struck Idiophones/Hi-Hat Cymbal", r"HiHat_HitO_rr1"),
("Membranophones/Struck Membranophones/Tom 2/Stick", r"TomL_HitS_v4_rr1"),
("Membranophones/Struck Membranophones/Tom 1/Stick", r"TomH_HitS_v4_rr1"),
("Idiophones/Struck Idiophones/Suspended Cymbal 2", r"susCymb2_hit_f1"),
("Idiophones/Struck Idiophones/Suspended Cymbal 2", r"susCymb2_hit_stick_mf1"),
("Idiophones/Struck Idiophones/Cowbells", r"Cowbell1_Normal_v3_rr1"),
]),
}
+51 -1
View File
@@ -378,7 +378,57 @@ def load_package(path, force):
if LOADER_MARK not in raw and not force:
raise InstallError("badpkg", f"{path}: no Felucca update loader in this package; "
"only Felucca's own packages are installed (--force overrides)")
return product, logical_image(raw)
image = logical_image(raw)
bad = package_damage(image)
if bad:
raise InstallError("badpkg", f"{path}: damaged package ({bad}); nothing was written. "
"Download it again.")
return product, image
def _crc16(data, crc=0):
"""CRC-16/XMODEM, as the package and the device use"""
for b in data:
crc ^= b << 8
for _ in range(8):
crc = ((crc << 1) ^ 0x1021) & 0xFFFF if crc & 0x8000 else (crc << 1) & 0xFFFF
return crc
def _dec(b):
"""JieLi ENC stream cipher (its own inverse)"""
out, key = bytearray(b), 0xFFFF
for i in range(len(out)):
out[i] ^= key & 0xFF
key = ((key << 1) ^ (0x1021 if key & 0x8000 else 0)) & 0xFFFF
return bytes(out)
def package_damage(image):
"""what is wrong with the update image (header, file list, each file's CRC), or None; the device
only checks the loader before it rewrites the firmware, so a damaged file is caught here"""
if len(image) < 0x40:
return "too short"
hdr = _dec(image[0:0x40])
if _crc16(hdr[2:0x40]) != int.from_bytes(hdr[0:2], "little"):
return "header CRC"
count = int.from_bytes(hdr[8:10], "little")
if not 1 <= count <= 8 or len(image) < 0x40 + 0x50 * count:
return "file list"
lst = image[0x40:0x40 + 0x50 * count]
if _crc16(lst) != int.from_bytes(hdr[2:4], "little"):
return "file list CRC"
for i in range(count):
e = _dec(lst[i * 0x50:(i + 1) * 0x50])
dcrc = int.from_bytes(e[4:6], "little")
off = int.from_bytes(e[8:12], "little")
size = int.from_bytes(e[12:16], "little")
name = e[0x40:0x50].split(b"\0")[0].decode("ascii", "replace")
if off + size > len(image):
return f"{name}: cut short"
if _crc16(image[off:off + size]) != dcrc:
return f"{name}: CRC"
return None
def not_found(up):
+2
View File
@@ -142,6 +142,8 @@ def flash_image(app, key):
cfg = entry(crc16(cfg_body), 0x20, 0x20 + len(cfg_body), 0x83, 0xFF, 1, "cfg") + cfg_body
region = bytearray(area + cfg)
sfc(region, 0, len(region), 0, key)
if 0x4000 + len(region) > FLASH_SIZE: # (the update loader writes up to FLASH_SIZE only)
raise SystemExit(f"app area too large: ends at 0x{0x4000 + len(region):x}, past 0x{FLASH_SIZE:x}")
f[0x4000:0x4000 + len(region)] = region
return bytes(f)
+9 -8
View File
@@ -5,8 +5,8 @@ the firmware, under assets/samples-cc0/<SET>/ (all CC0; CREDITS.txt next to them
python tools/gen_builtin_hiphop.py (numpy, scipy, soundfile; fetches the sources once)
Sets (gen_samples.py CC0_SETS gives their order and kind):
DUSTY a dusty upright piano (VCSL Upright Piano, Knight)
Sets (gen_samples.py CC0_SETS gives their order and kind; PIANO, the grand, is cut from VCSL as
ATTRIBUTION.txt lists):
BASS jazz upright bass, pizz (VSCO-2 CE Solo Contrabass) - two octaves under the keys
VIBES vibraphone, hard mallets (VCSL)
HORNS trumpet + trombone stabs (VSCO-2 CE)
@@ -27,7 +27,6 @@ CC0 = g.ROOT / "assets" / "samples-cc0"
# set: (zones [(MIDI root it sounds at, seconds)], builder, chain, transpose of the stored root)
SETS = {
"DUSTY": ([(48, 1.0), (57, 1.0), (66, 1.0), (75, 1.0)], g.UPR, dict(lp=9500, drive=1.3, warm=2.0, wow=0.0008), 0),
"BASS": ([(28, 0.9), (35, 0.9), (42, 0.9), (49, 0.85)], g.CB, dict(lp=4500, drive=1.8, warm=3.0, wow=0.0), 24),
"VIBES": ([(53, 1.0), (62, 1.0), (71, 1.0)], g.VIB, dict(lp=10000, drive=1.2, warm=1.0), 0),
"HORNS": ([(55, 0.6), (62, 0.6), (69, 0.6), (76, 0.6)],
@@ -39,7 +38,8 @@ SCRATCH = [("vinyl_scratch", 57, 0.8), ("vinyl_backspin", 65, 0.8), ("vinyl_rewi
CREDITS = """Samples in the SAMPLE engine's built-in sets. All CC0 1.0 (public domain).
DUSTY VCSL (Versilian Community Sample Library), Upright Piano (Knight)
PIANO VCSL (Versilian Community Sample Library), Grand Piano (Steinway B), sustain, close mics
(until 2.1 the piano was VCSL's Upright Piano (Knight), DUSTY; it is no longer in the tree)
VIBES VCSL, Vibraphone (hard mallets) https://github.com/sgossner/VCSL
BASS VSCO-2 Community Edition, Solo Contrabass pizzicato
HORNS VSCO-2 Community Edition, Trumpet + Tenor Trombone staccato
@@ -48,7 +48,8 @@ FLUTE VSCO-2 Community Edition, Flute (susvib) https://github.com/sgo
SCRCH Sonic Pi sample set (freesound.org CC0 recordings): vinyl_scratch (hello_flowers),
vinyl_backspin (il112), vinyl_rewind (TasmanianPower)
https://github.com/sonic-pi-net/sonic-pi/tree/main/etc/samples
KIT VCSL hand percussion (tambourine, shaker, conga, claves, woodblock) for the GM kit
KIT VCSL: the acoustic drum kit of the GM map (bass drum, snare, side stick, claps, hi-hat, toms,
suspended cymbal, cowbell) and hand percussion (tambourine, shaker, conga, claves, woodblock)
Thanks to Versilian Studios / Sam Gossner and to the Sonic Pi project.
Retuned, cut and coloured by tools/gen_builtin_hiphop.py (gen_hiphop_pack.py's chain).
@@ -75,7 +76,7 @@ def main():
return real(url, nominal, target)
g.source = source
att = []
for old in ("PIANO", "TRANH", "SAX"): # (TRANH and SAX are gone; PIANO is new)
for old in ("DUSTY", "TRANH", "SAX"): # (sets of earlier releases; PIANO is kept)
shutil.rmtree(CC0 / old, ignore_errors=True)
total = 0
for name, (zones, make, chain, tr) in SETS.items():
@@ -101,9 +102,9 @@ def main():
total += len(x)
(CC0 / "CREDITS.txt").write_text(CREDITS, encoding="utf-8")
keep = [ln for ln in (CC0 / "ATTRIBUTION.txt").read_text(encoding="utf-8").splitlines()
if ln.startswith(("FLUTE/", "KIT/"))] if (CC0 / "ATTRIBUTION.txt").exists() else []
if ln.startswith(("FLUTE/", "KIT/", "PIANO/"))] if (CC0 / "ATTRIBUTION.txt").exists() else []
(CC0 / "ATTRIBUTION.txt").write_text(ATT_HEAD + "\n".join(att + keep) + "\n", encoding="utf-8")
print(f"built-in sets: {total / g.RATE:.1f} s written (FLUTE and KIT kept)")
print(f"built-in sets: {total / g.RATE:.1f} s written (FLUTE, KIT and PIANO kept)")
if __name__ == "__main__":
+281 -180
View File
@@ -2,21 +2,33 @@
# SPDX-License-Identifier: GPL-3.0-only
"""Synthesised drum kits for firmware/src/drum_synth.c -> felucca_drumkits.h
Each kit has 14 sounds (lanes): KICK SNARE CLAP CHH OHH TOMLO TOMHI CRASH RIDE SHAKER
CONGA RIM COWBELL CLAVE. A sound is written in musical units (Hz, ms) and converted to
the table indices the firmware uses (MIDI note, DECAY_K and CUTOFF_HZ indices).
Each kit has 16 sounds (lanes), one per white key of the drum track:
KICK SNARE CLAP CHH OHH TOMLO TOMHI CRASH RIDE SHAKER CONGA RIM COWBELL CLAVE KICK2 SNARE2.
A sound is written in musical units (Hz, ms, octaves, dB) and converted to the table indices
the firmware uses (MIDI note + 1/16, DECAY_K and CUTOFF_HZ indices). The level of every sound
(LEVELS, tools/drumkit_levels.json) is measured, not guessed: tests/drum_level.c renders each
sound, and every kit comes out as loud as the others, each lane at its place in the mix.
tools/gen_drumkits.py OUT.h
"""
import copy
import json
import math
import sys
from pathlib import Path
LANES = ["KICK", "SNARE", "CLAP", "CHH", "OHH", "TOMLO", "TOMHI", "CRASH", "RIDE", "SHAKER",
"CONGA", "RIM", "COWBELL", "CLAVE"]
"CONGA", "RIM", "COWBELL", "CLAVE", "KICK2", "SNARE2"]
WAVE = {None: 0, "sine": 1, "tri": 2, "square": 3, "fm": 4, "bell": 5}
SRC = {None: 0, "white": 1, "metal": 2, "cym": 3, "chip": 4, "clap": 0x11}
FMODE = {None: 0, "lp": 1, "bp": 2, "hp": 3}
LEVELS_FILE = Path(__file__).with_name("drumkit_levels.json")
def note16(hz): # MIDI note and 1/16 semitones
n = 69 + 12 * math.log2(hz / 440.0)
n16 = max(0, min(127 * 16 + 15, int(round(n * 16))))
return n16 >> 4, n16 & 15
def note(hz):
@@ -33,19 +45,37 @@ def cut(hz): # CUTOFF_HZ: 30 Hz .. 16 kHz
return int(round(127 * math.log(hz / 30.0) / math.log(16000 / 30)))
def S(wave=None, hz=100, bend=0, bt=20, decay=100, tlev=110, src=None, nlev=0, ndec=50,
lpf=None, hpf=None, drive=0, chip=None):
return dict(wave=wave, hz=hz, bend=bend, bt=bt, decay=decay, tlev=tlev, src=src, nlev=nlev,
ndec=ndec, lpf=lpf, hpf=hpf, drive=drive, chip=chip)
STEPS_PER_OCT = 127 / math.log2(16000 / 30)
def enc(s):
lpf = 127 if s["lpf"] is None else cut(s["lpf"])
if s["src"] == "chip":
lpf = s["chip"] if s["chip"] is not None else 100 # CHIP: clock note
return [WAVE[s["wave"]], SRC[s["src"]], note(s["hz"]), int(s["bend"]), dec(s["bt"]), dec(s["decay"]),
int(s["tlev"]) if s["wave"] else 0, int(s["nlev"]) if s["src"] else 0, dec(s["ndec"]), lpf,
0 if s["hpf"] is None else cut(s["hpf"]), int(s["drive"])]
def S(wave=None, hz=100, bend=0, bt=20, hold=0, decay=100, tlev=110, t2=0.0, t2lev=0, click=0,
src=None, nlev=0, nhold=0, ndec=50, filt=None, fenv=0.0, hpf=None, chip=None, drive=0, level=0.0):
"""wave/hz: the tone; bend semitones falling over bt ms; hold ms at full, then decay;
t2: the second partial's ratio (0 = none) and level; click: the attack burst 0..127;
src: the noise, its level, hold and decay; filt: (mode, Hz, resonance 0..1[, "all"]) on the
noise (or everything); fenv: octaves the cutoff starts above it, falling with the pitch;
hpf: Hz of the noise high-pass; chip: Hz of the CHIP noise clock; drive 0..127; level dB"""
return dict(wave=wave, hz=hz, bend=bend, bt=bt, hold=hold, decay=decay, tlev=tlev, t2=t2,
t2lev=t2lev, click=click, src=src, nlev=nlev, nhold=nhold, ndec=ndec, filt=filt,
fenv=fenv, hpf=hpf, chip=chip, drive=drive, level=level)
def enc(s, trim=0.0):
p, f = note16(s["hz"])
flt, fcut = 0, 127
if s["filt"]:
mode, hz, res = s["filt"][:3]
flt = FMODE[mode] | (4 if "all" in s["filt"][3:] else 0) | (int(round(res * 31)) << 3)
fcut = cut(hz)
lev = int(round(128 + 4 * (s["level"] + trim)))
v = [WAVE[s["wave"]], SRC[s["src"]], p, f, int(s["bend"]), dec(s["bt"]),
min(255, int(round(s["hold"] / 2))), dec(s["decay"]), int(s["tlev"]) if s["wave"] else 0,
int(round(s["t2"] * 32)) if s["t2"] else 0, int(s["t2lev"]), int(s["click"]),
int(s["nlev"]) if s["src"] else 0, min(255, int(round(s["nhold"] / 2))), dec(s["ndec"]),
flt, fcut, int(round(s["fenv"] * STEPS_PER_OCT)),
0 if s["hpf"] is None else cut(s["hpf"]), note(s["chip"]) if s["chip"] else 0,
int(s["drive"]), max(0, min(255, lev))]
return v
def kit(base, **mods):
@@ -60,223 +90,294 @@ def kit(base, **mods):
# ---- base kits ---------------------------------------------------------------------------
K808 = dict(
KICK=S("sine", 49, 26, 45, 750, 122, "white", 22, 4, 3000),
SNARE=S("tri", 180, 4, 20, 110, 80, "white", 92, 170, 9000, 1500),
CLAP=S(None, src="clap", nlev=122, ndec=210, lpf=2400, hpf=800),
CHH=S(None, 205, src="metal", nlev=118, ndec=45, hpf=7000),
OHH=S(None, 205, src="metal", nlev=112, ndec=380, hpf=6500),
TOMLO=S("sine", 98, 5, 60, 380, 115, "white", 14, 25, 2000),
TOMHI=S("sine", 147, 5, 60, 320, 112, "white", 14, 25, 2500),
CRASH=S(None, 205, src="cym", nlev=104, ndec=1700, hpf=4500),
RIDE=S(None, 260, src="metal", nlev=112, ndec=1100, lpf=12000, hpf=3500),
SHAKER=S(None, src="white", nlev=84, ndec=55, hpf=6000),
CONGA=S("sine", 310, 3, 25, 200, 112),
RIM=S("tri", 1700, 0, 5, 22, 92, "white", 50, 5, None, 2500),
COWBELL=S("bell", 540, 0, 5, 280, 104, lpf=4000, hpf=500),
CLAVE=S("sine", 2500, 0, 5, 45, 104),
KICK=S("sine", 50, 12, 32, 8, 820, 124, click=26, drive=8),
KICK2=S("sine", 42, 7, 60, 70, 1700, 124, click=14, drive=34), # the long boom
SNARE=S("sine", 185, 3, 14, 0, 120, 96, 1.78, 92, 22, "white", 100, 0, 170, ("hp", 1700, .12)),
SNARE2=S("tri", 250, 4, 10, 0, 70, 84, 1.5, 60, 30, "white", 96, 0, 120, ("bp", 5200, .3)),
CLAP=S(None, src="clap", nlev=122, ndec=230, filt=("bp", 1150, .38), hpf=600),
CHH=S(None, 205, src="metal", nlev=118, ndec=42, filt=("bp", 9200, .42), hpf=6500, click=10),
OHH=S(None, 205, src="metal", nlev=114, nhold=20, ndec=380, filt=("bp", 9000, .4), hpf=6200),
TOMLO=S("sine", 98, 6, 60, 10, 420, 118, 1.5, 40, 16, "white", 18, 0, 30, ("lp", 2000, .1)),
TOMHI=S("sine", 147, 6, 60, 10, 360, 116, 1.5, 40, 16, "white", 18, 0, 30, ("lp", 2600, .1)),
CRASH=S(None, 205, src="cym", nlev=108, nhold=10, ndec=1800, filt=("hp", 4600, .22)),
RIDE=S(None, 262, src="metal", nlev=104, ndec=1300, filt=("bp", 5200, .6), hpf=3000, click=12),
SHAKER=S(None, src="white", nlev=96, nhold=12, ndec=55, filt=("bp", 7200, .3)),
CONGA=S("sine", 310, 3, 25, 4, 230, 116, 1.5, 30, 24),
RIM=S("tri", 1700, 0, 5, 0, 22, 92, 1.47, 70, 40, "white", 40, 0, 6, ("bp", 2600, .4, "all")),
COWBELL=S("bell", 540, 0, 5, 6, 290, 108, filt=("bp", 2600, .5, "all")),
CLAVE=S("sine", 2500, 0, 5, 0, 48, 108, click=12),
)
K909 = kit(K808,
KICK=S("sine", 55, 36, 28, 320, 122, "white", 70, 7, 6000, None, 40),
SNARE=S("sine", 190, 7, 15, 110, 88, "white", 115, 230, 12000, 1000, 20),
CLAP=dict(nlev=124, ndec=260, lpf=2600, hpf=900),
CHH=S(None, 230, src="cym", nlev=112, ndec=55, hpf=8000),
OHH=S(None, 230, src="cym", nlev=108, ndec=420, hpf=7500),
TOMLO=S("sine", 110, 10, 40, 300, 115, "white", 26, 30, 3000),
TOMHI=S("sine", 165, 10, 40, 260, 112, "white", 26, 30, 3500),
CRASH=S(None, 250, src="cym", nlev=106, ndec=1900, hpf=5000),
RIDE=S(None, 300, src="cym", nlev=110, ndec=1400, lpf=13000, hpf=4000),
RIM=S("tri", 1900, 2, 4, 18, 96, "white", 70, 6, None, 3000),
KICK=S("sine", 52, 30, 24, 14, 340, 124, click=64, drive=36, src="white", nlev=40, ndec=6,
filt=("lp", 5000, .1)),
KICK2=S("sine", 57, 36, 18, 8, 220, 124, click=84, drive=72),
SNARE=S("tri", 190, 7, 15, 0, 110, 92, 1.6, 70, 30, "white", 116, 0, 220, ("hp", 1000, .1),
drive=22),
SNARE2=S("tri", 230, 6, 10, 0, 70, 86, 1.6, 60, 40, "white", 110, 0, 140, ("bp", 6200, .3)),
CLAP=dict(nlev=124, ndec=290, filt=("bp", 1300, .42), hpf=700),
CHH=S(None, 230, src="cym", nlev=114, ndec=55, filt=("hp", 8200, .25), hpf=7000, click=12),
OHH=S(None, 230, src="cym", nlev=110, nhold=20, ndec=460, filt=("hp", 7800, .25), hpf=6800),
TOMLO=S("sine", 110, 10, 40, 10, 320, 118, 1.5, 36, 22, "white", 26, 0, 30, ("lp", 3000, .1)),
TOMHI=S("sine", 165, 10, 40, 10, 280, 116, 1.5, 36, 22, "white", 26, 0, 30, ("lp", 3600, .1)),
CRASH=S(None, 250, src="cym", nlev=110, nhold=10, ndec=1900, filt=("hp", 5000, .2)),
RIDE=S(None, 300, src="cym", nlev=108, ndec=1500, filt=("bp", 6200, .45), hpf=4000, click=14),
RIM=S("tri", 1900, 2, 4, 0, 18, 96, 1.47, 60, 48, "white", 60, 0, 6, ("bp", 3000, .4, "all")),
)
K606 = kit(K808,
KICK=S("sine", 60, 18, 30, 190, 122, "white", 30, 4, 4000),
SNARE=S("tri", 220, 3, 10, 70, 70, "white", 102, 120, 10000, 2500),
CHH=S(None, 260, src="metal", nlev=114, ndec=30, hpf=9000),
OHH=S(None, 260, src="metal", nlev=108, ndec=200, hpf=8500),
TOMLO=S("sine", 150, 4, 30, 180, 112),
TOMHI=S("sine", 220, 4, 30, 160, 110),
CRASH=S(None, 300, src="metal", nlev=100, ndec=900, hpf=6000),
KICK=S("sine", 60, 18, 26, 6, 200, 124, click=34, drive=10),
KICK2=S("sine", 52, 14, 30, 10, 320, 124, click=24, drive=20),
SNARE=S("tri", 220, 3, 10, 0, 70, 80, 1.7, 50, 24, "white", 104, 0, 120, ("hp", 2500, .15)),
CHH=S(None, 260, src="metal", nlev=116, ndec=30, filt=("bp", 10000, .45), hpf=8500, click=8),
OHH=S(None, 260, src="metal", nlev=110, nhold=10, ndec=210, filt=("bp", 9800, .45), hpf=8000),
TOMLO=S("sine", 150, 4, 30, 6, 190, 114, click=12),
TOMHI=S("sine", 220, 4, 30, 6, 170, 112, click=12),
CRASH=S(None, 300, src="metal", nlev=104, ndec=900, filt=("hp", 6000, .3)),
)
KCR78 = kit(K808,
KICK=S("sine", 65, 8, 20, 160, 118, lpf=2000),
SNARE=S("sine", 240, 2, 10, 60, 70, "white", 72, 90, 6000, 2000),
CLAP=S(None, src="white", nlev=90, ndec=140, lpf=8000, hpf=4000), # tambourine-ish
CHH=S(None, 280, src="metal", nlev=106, ndec=25, hpf=9000),
OHH=S(None, 280, src="metal", nlev=100, ndec=160, hpf=8500),
TOMLO=S("sine", 180, 2, 20, 160, 110),
TOMHI=S("sine", 260, 2, 20, 140, 108),
SHAKER=S(None, src="white", nlev=90, ndec=30, hpf=7000),
CONGA=S("sine", 400, 2, 15, 120, 110),
RIM=S("sine", 1600, 0, 5, 30, 100),
COWBELL=S("bell", 800, 0, 5, 160, 100, lpf=5000, hpf=800),
KICK=S("sine", 65, 8, 20, 4, 170, 120, click=10, filt=("lp", 1800, .2, "all")),
KICK2=S("sine", 58, 6, 20, 4, 240, 120, click=8, filt=("lp", 1400, .2, "all")),
SNARE=S("sine", 240, 2, 10, 0, 60, 74, 1.6, 50, 10, "white", 76, 0, 95, ("bp", 3200, .3)),
SNARE2=S("sine", 300, 2, 8, 0, 40, 70, 1.5, 40, 12, "white", 70, 0, 60, ("bp", 4200, .3)),
CLAP=S(None, src="white", nlev=92, nhold=8, ndec=140, filt=("bp", 6200, .35), hpf=4000), # tambourine
CHH=S(None, 280, src="metal", nlev=106, ndec=25, filt=("bp", 10500, .5), hpf=9000),
OHH=S(None, 280, src="metal", nlev=100, nhold=6, ndec=160, filt=("bp", 10000, .5), hpf=8500),
TOMLO=S("sine", 180, 2, 20, 4, 170, 112, click=8),
TOMHI=S("sine", 260, 2, 20, 4, 150, 110, click=8),
SHAKER=S(None, src="white", nlev=92, nhold=6, ndec=30, filt=("bp", 8000, .35)),
CONGA=S("sine", 400, 2, 15, 4, 130, 112, click=14),
RIM=S("sine", 1600, 0, 5, 0, 30, 100, 1.5, 50, 30),
COWBELL=S("bell", 800, 0, 5, 4, 160, 104, filt=("bp", 3000, .5, "all")),
)
KLINN = kit(K808,
KICK=S("sine", 58, 20, 22, 240, 122, "white", 60, 6, 5000, None, 20),
SNARE=S("tri", 200, 6, 15, 120, 86, "white", 112, 260, 10000, 900, 30),
CLAP=dict(nlev=124, ndec=300, lpf=2800),
CHH=S(None, 240, src="cym", nlev=104, ndec=40, hpf=8000),
OHH=S(None, 240, src="cym", nlev=100, ndec=300, hpf=7500),
TOMLO=S("sine", 90, 12, 80, 500, 118, "white", 20, 40, 2500),
TOMHI=S("sine", 140, 12, 80, 420, 115, "white", 20, 40, 3000),
K707 = kit(K808, # the 80s machines
KICK=S("sine", 58, 20, 22, 10, 260, 124, click=56, drive=22, src="white", nlev=40, ndec=6,
filt=("lp", 4500, .1)),
KICK2=S("sine", 50, 16, 26, 14, 380, 124, click=40, drive=30),
SNARE=S("tri", 200, 6, 15, 6, 130, 88, 1.62, 70, 36, "white", 112, 10, 270, ("hp", 900, .15),
drive=30),
SNARE2=S("tri", 220, 6, 12, 0, 90, 84, 1.62, 60, 40, "white", 112, 0, 200, ("bp", 4800, .3)),
CLAP=dict(nlev=124, ndec=320, filt=("bp", 1400, .45)),
CHH=S(None, 240, src="cym", nlev=106, ndec=40, filt=("hp", 8000, .3), hpf=7000, click=10),
OHH=S(None, 240, src="cym", nlev=102, nhold=20, ndec=320, filt=("hp", 7500, .3), hpf=6800),
TOMLO=S("sine", 90, 12, 80, 14, 520, 120, 1.5, 40, 24, "white", 22, 0, 40, ("lp", 2500, .1)),
TOMHI=S("sine", 140, 12, 80, 14, 440, 118, 1.5, 40, 24, "white", 22, 0, 40, ("lp", 3000, .1)),
)
KCHIP = dict(
KICK=S("square", 70, 30, 40, 120, 104),
SNARE=S("square", 220, 12, 20, 40, 60, "chip", 106, 130, chip=100),
CLAP=S(None, src="chip", nlev=108, ndec=110, chip=108),
CHH=S(None, src="chip", nlev=96, ndec=30, chip=124),
OHH=S(None, src="chip", nlev=92, ndec=220, chip=122),
TOMLO=S("square", 110, 14, 80, 160, 100),
TOMHI=S("square", 165, 14, 80, 140, 100),
CRASH=S(None, src="chip", nlev=96, ndec=900, chip=112),
RIDE=S("square", 1500, 0, 5, 300, 50, "chip", 60, 200, chip=126),
SHAKER=S(None, src="chip", nlev=84, ndec=45, chip=127),
CONGA=S("tri", 330, 5, 30, 120, 110),
RIM=S("square", 1200, 0, 5, 25, 90),
COWBELL=S("square", 700, 0, 5, 150, 90),
CLAVE=S("square", 2000, 0, 5, 35, 90),
KICK=S("square", 70, 30, 40, 4, 130, 104),
KICK2=S("tri", 60, 36, 50, 10, 220, 116),
SNARE=S("square", 220, 12, 20, 0, 40, 60, src="chip", nlev=106, nhold=6, ndec=130, chip=1700),
SNARE2=S(None, src="chip", nlev=108, nhold=4, ndec=90, chip=3500),
CLAP=S(None, src="chip", nlev=108, nhold=10, ndec=110, chip=2800),
CHH=S(None, src="chip", nlev=96, ndec=30, chip=11000),
OHH=S(None, src="chip", nlev=92, nhold=10, ndec=220, chip=10000),
TOMLO=S("square", 110, 14, 80, 4, 160, 100),
TOMHI=S("square", 165, 14, 80, 4, 140, 100),
CRASH=S(None, src="chip", nlev=96, nhold=20, ndec=900, chip=4200),
RIDE=S("square", 1500, 0, 5, 0, 300, 50, src="chip", nlev=60, ndec=200, chip=12500),
SHAKER=S(None, src="chip", nlev=84, ndec=45, chip=13000),
CONGA=S("tri", 330, 5, 30, 4, 120, 110),
RIM=S("square", 1200, 0, 5, 0, 25, 90),
COWBELL=S("square", 700, 0, 5, 4, 150, 90),
CLAVE=S("square", 2000, 0, 5, 0, 35, 90),
)
KFM = dict(
KICK=S("fm", 55, 40, 30, 220, 120, drive=30),
SNARE=S("fm", 200, 18, 20, 90, 90, "white", 90, 140, 9000, 1500),
CLAP=S(None, src="clap", nlev=118, ndec=180, lpf=3000, hpf=1000),
CHH=S("fm", 4200, 0, 5, 30, 70, "white", 70, 30, None, 8000),
OHH=S("fm", 4200, 0, 5, 220, 64, "white", 64, 220, None, 7000),
TOMLO=S("fm", 120, 30, 120, 260, 110),
TOMHI=S("fm", 200, 30, 120, 220, 108),
CRASH=S("fm", 900, 0, 5, 1200, 50, "cym", 90, 1300, None, 4000),
RIDE=S("fm", 1300, 0, 5, 900, 60, "metal", 50, 700, 9000, 5000),
SHAKER=S(None, src="white", nlev=80, ndec=50, hpf=6000),
CONGA=S("fm", 330, 12, 40, 160, 108),
RIM=S("fm", 1500, 4, 5, 25, 96),
COWBELL=S("fm", 600, 0, 5, 200, 96),
CLAVE=S("fm", 2300, 0, 5, 40, 100),
KICK=S("fm", 55, 40, 30, 8, 220, 120, click=30, drive=30),
KICK2=S("fm", 48, 30, 40, 20, 420, 120, drive=50),
SNARE=S("fm", 200, 18, 20, 0, 90, 90, src="white", nlev=90, ndec=140, filt=("bp", 4000, .3)),
SNARE2=S("fm", 330, 12, 10, 0, 60, 90, src="white", nlev=80, ndec=90, filt=("hp", 3000, .3)),
CLAP=S(None, src="clap", nlev=118, ndec=180, filt=("bp", 1500, .4), hpf=1000),
CHH=S("fm", 4200, 0, 5, 0, 30, 70, src="white", nlev=70, ndec=30, filt=("hp", 8000, .2)),
OHH=S("fm", 4200, 0, 5, 0, 220, 64, src="white", nlev=64, ndec=220, filt=("hp", 7000, .2)),
TOMLO=S("fm", 120, 30, 120, 6, 260, 110),
TOMHI=S("fm", 200, 30, 120, 6, 220, 108),
CRASH=S("fm", 900, 0, 5, 0, 1200, 50, src="cym", nlev=90, ndec=1300, filt=("hp", 4000, .2)),
RIDE=S("fm", 1300, 0, 5, 0, 900, 60, src="metal", nlev=50, ndec=700, filt=("bp", 6000, .5)),
SHAKER=S(None, src="white", nlev=80, nhold=8, ndec=50, filt=("bp", 7000, .3)),
CONGA=S("fm", 330, 12, 40, 4, 160, 108),
RIM=S("fm", 1500, 4, 5, 0, 25, 96, click=30),
COWBELL=S("fm", 600, 0, 5, 4, 200, 96),
CLAVE=S("fm", 2300, 0, 5, 0, 40, 100),
)
KITS = [
# -- the machines
("808", "HIP HOP", 0, K808),
("909", "HOUSE", 0, K909),
("606", "ACID", 0, K606),
("80S", "80S POP", 0, K707),
("VINTAGE", "RHYTHM BOX", 0, KCR78),
("80S", "80S POP", 0, KLINN),
# -- hip-hop
("TRAP", "TRAP", 0, kit(K808,
KICK=dict(hz=46, bend=30, bt=60, decay=1300, drive=34),
SNARE=S("tri", 200, 5, 10, 90, 70, "white", 110, 150, 12000, 2200, 20),
CLAP=dict(nlev=126, ndec=170, lpf=3000, hpf=1100),
CHH=dict(ndec=24, hpf=9000), OHH=dict(ndec=260))),
KICK=S("sine", 52, 18, 26, 10, 520, 124, click=50, drive=30),
KICK2=S("sine", 46, 12, 40, 80, 1900, 124, click=20, drive=48), # the 808, distorted
SNARE=S("tri", 210, 6, 10, 0, 90, 80, 1.7, 60, 40, "white", 116, 6, 150, ("hp", 2300, .2), drive=26),
CLAP=dict(nlev=126, ndec=170, filt=("bp", 1500, .4), hpf=1100),
CHH=dict(ndec=26, filt=("bp", 10500, .45), hpf=9000),
OHH=dict(ndec=260))),
("DRILL", "UK DRILL", 0, kit(K808,
KICK=dict(hz=44, bend=12, bt=200, decay=1600, drive=40),
SNARE=S("tri", 270, 8, 8, 60, 84, "white", 104, 110, 12000, 2500, 30),
CHH=dict(ndec=28, hpf=8500), RIM=dict(hz=2000, decay=30, tlev=104))),
KICK=S("sine", 50, 14, 30, 8, 380, 124, click=44, drive=26),
KICK2=S("sine", 44, 12, 220, 40, 1900, 124, click=16, drive=44), # the sliding 808
SNARE=S("tri", 270, 8, 8, 0, 60, 84, 1.6, 60, 46, "white", 108, 4, 110, ("hp", 2600, .25), drive=30),
SNARE2=S("tri", 330, 6, 6, 0, 40, 80, 1.5, 50, 50, "white", 100, 0, 80, ("bp", 5500, .4)),
CHH=dict(ndec=28, filt=("bp", 9800, .5), hpf=8500),
RIM=dict(hz=2000, decay=30, tlev=104))),
("BOOMBAP", "HIP HOP", 0x13, kit(K909,
KICK=dict(decay=260, drive=70, nlev=80),
SNARE=S("tri", 175, 5, 15, 130, 92, "white", 110, 200, 5000, 700, 50),
CHH=dict(ndec=40, hpf=6000), OHH=dict(ndec=260, hpf=5500))),
KICK=S("sine", 56, 14, 22, 12, 280, 124, click=40, drive=70, src="white", nlev=70, ndec=10,
filt=("lp", 3000, .15)),
KICK2=S("sine", 50, 10, 26, 16, 360, 124, click=30, drive=80, filt=("lp", 1800, .1, "all")),
SNARE=S("tri", 175, 5, 15, 8, 140, 96, 1.7, 70, 34, "white", 112, 10, 200, ("bp", 3200, .25),
drive=50),
SNARE2=S("tri", 200, 5, 12, 0, 90, 90, 1.7, 60, 30, "white", 104, 0, 140, ("bp", 2600, .3), drive=40),
CHH=dict(ndec=40, filt=("bp", 7000, .35), hpf=6000),
OHH=dict(ndec=260, filt=("bp", 6800, .35), hpf=5500))),
("LO-FI", "LO-FI", 0x34, kit(K808,
KICK=dict(decay=420, lpf=1500, tlev=114),
SNARE=dict(lpf=4500, hpf=900, ndec=150),
CLAP=dict(lpf=1800, hpf=600),
CHH=dict(hpf=4000, nlev=90), OHH=dict(hpf=3800, nlev=86),
CRASH=dict(hpf=3000, nlev=80), RIDE=dict(lpf=6000, hpf=3000, nlev=70))),
KICK=S("sine", 54, 10, 30, 10, 420, 120, click=18, drive=24, filt=("lp", 1300, .15, "all")),
KICK2=S("sine", 48, 8, 30, 14, 560, 120, click=10, drive=30, filt=("lp", 900, .15, "all")),
SNARE=dict(filt=("bp", 2400, .25), ndec=160, click=10),
SNARE2=dict(filt=("bp", 1800, .3), ndec=120),
CLAP=dict(filt=("bp", 1000, .3)),
CHH=dict(filt=("bp", 5200, .3), hpf=3800, nlev=96), OHH=dict(filt=("bp", 5000, .3), hpf=3600, nlev=92),
CRASH=dict(filt=("bp", 4000, .2), nlev=88), RIDE=dict(filt=("bp", 4200, .5), hpf=2800, nlev=80))),
("PHONK", "PHONK", 0x02, kit(K808,
KICK=S("sine", 52, 20, 24, 10, 480, 124, click=60, drive=90),
KICK2=S("sine", 45, 12, 50, 60, 1600, 124, click=30, drive=110), # blown-out 808
SNARE=S("tri", 230, 8, 10, 0, 80, 84, 1.6, 60, 44, "white", 116, 6, 140, ("hp", 2000, .25), drive=60),
CLAP=dict(nlev=126, ndec=150, hpf=1200),
CHH=dict(ndec=30), OHH=dict(ndec=220),
COWBELL=S("bell", 560, 0, 5, 30, 520, 116, filt=("bp", 2400, .55, "all"), drive=40))), # the melodic cowbell
# -- dance
("HOUSE", "HOUSE", 0, kit(K909,
KICK=dict(decay=360, drive=30), OHH=dict(ndec=300, nlev=112),
CLAP=dict(nlev=126, ndec=320), SHAKER=dict(ndec=70, nlev=90))),
KICK=dict(decay=380, drive=30, hold=18),
OHH=dict(ndec=320, nlev=112), CLAP=dict(nlev=126, ndec=340),
SHAKER=dict(ndec=70, nlev=98))),
("D.HOUSE", "DEEP HOUSE", 0, kit(K909,
KICK=S("sine", 50, 22, 26, 20, 460, 124, click=36, drive=18, filt=("lp", 3000, .1, "all")),
SNARE=dict(ndec=180, filt=("bp", 2200, .3), click=16, tlev=80),
CLAP=dict(nlev=118, ndec=420, filt=("bp", 1100, .4)),
CHH=dict(ndec=48, filt=("bp", 7500, .45), hpf=6200, nlev=100),
OHH=dict(ndec=300, filt=("bp", 7200, .45), hpf=6000, nlev=100),
SHAKER=dict(ndec=80, nlev=100, filt=("bp", 6000, .3)),
RIM=dict(filt=("bp", 2200, .5, "all")))),
("TECHNO", "TECHNO", 0, kit(K909,
KICK=dict(hz=50, bend=30, bt=24, decay=420, drive=95),
CHH=dict(ndec=35, hpf=9500), OHH=dict(ndec=280, hpf=9000),
RIDE=dict(nlev=96, ndec=900), RIM=dict(drive=40),
CLAP=dict(ndec=200, lpf=2200))),
KICK=S("sine", 50, 28, 22, 18, 420, 124, click=70, drive=96, src="white", nlev=50, ndec=8,
filt=("lp", 4000, .2)),
KICK2=S("sine", 46, 18, 30, 30, 900, 124, click=40, drive=110, filt=("lp", 900, .3, "all")), # rumble
CHH=dict(ndec=34, filt=("hp", 9500, .3), hpf=9000), OHH=dict(ndec=280, filt=("hp", 9000, .3)),
RIDE=dict(nlev=100, ndec=900), RIM=dict(drive=40),
CLAP=dict(ndec=210, filt=("bp", 1900, .45)))),
("MINIMAL", "MINIMAL", 0, kit(K808,
KICK=S("sine", 60, 20, 10, 150, 122, "white", 50, 3, 7000),
SNARE=S("tri", 1100, 0, 5, 18, 90, "white", 60, 25, None, 3000),
CLAP=dict(ndec=90), CHH=dict(ndec=18, hpf=10000), OHH=dict(ndec=120),
KICK=S("sine", 58, 18, 12, 6, 160, 124, click=44, drive=12),
KICK2=S("sine", 52, 10, 14, 8, 240, 124, click=30),
SNARE=S("tri", 1100, 0, 5, 0, 18, 90, 1.5, 50, 40, "white", 60, 0, 25, ("hp", 3000, .3)),
CLAP=dict(ndec=90), CHH=dict(ndec=18, filt=("hp", 10000, .3), hpf=9500), OHH=dict(ndec=120),
CONGA=dict(decay=90, hz=420), RIM=dict(decay=12))),
("ELECTRO", "ELECTRO", 0, kit(K808,
KICK=dict(bend=40, bt=70, decay=500),
SNARE=dict(ndec=120, hpf=2000),
TOMLO=S("fm", 130, 30, 120, 240, 110), TOMHI=S("fm", 220, 30, 120, 200, 108),
KICK=S("sine", 52, 24, 70, 10, 520, 124, click=40, drive=24),
SNARE=dict(ndec=120, filt=("hp", 2000, .2), click=36),
TOMLO=S("fm", 130, 30, 120, 8, 240, 112), TOMHI=S("fm", 220, 30, 120, 8, 200, 110),
CHH=K606["CHH"], OHH=K606["OHH"])),
("JUNGLE", "DRUM & BASS", 0, kit(K909,
KICK=dict(decay=200, drive=50),
SNARE=S("tri", 260, 9, 10, 90, 92, "white", 112, 160, 12000, 1500, 40),
CHH=dict(ndec=30), RIDE=dict(nlev=92))),
("DUBSTEP", "BASS MUSIC", 0, kit(K909,
KICK=dict(hz=48, decay=420, drive=60),
SNARE=S("tri", 170, 8, 20, 160, 96, "white", 120, 420, 9000, 600, 60),
CLAP=dict(ndec=380), OHH=dict(ndec=300))),
("DEMBOW", "REGGAETON", 0, kit(K808,
KICK=dict(decay=520, drive=20),
SNARE=S("tri", 230, 5, 10, 80, 84, "white", 100, 130, 11000, 1800, 20),
CLAP=dict(ndec=160), RIM=dict(tlev=104), SHAKER=dict(ndec=70, nlev=96))),
("AFRO", "AFROBEAT", 0, kit(K808,
KICK=S("sine", 60, 10, 30, 260, 118, lpf=2000),
SNARE=S("tri", 330, 3, 10, 60, 92, "white", 70, 60, 9000, 2500),
CONGA=dict(decay=260, bend=2), TOMLO=S("sine", 160, 2, 20, 260, 112),
TOMHI=S("sine", 230, 2, 20, 220, 110), SHAKER=dict(ndec=80, nlev=100),
COWBELL=dict(hz=900, decay=180))),
("LATIN", "LATIN", 0, kit(KCR78,
KICK=S("sine", 62, 6, 20, 220, 114, lpf=1800),
TOMLO=S("sine", 200, 3, 15, 200, 112, "white", 20, 15, 4000), # timbales
TOMHI=S("sine", 300, 3, 15, 180, 112, "white", 20, 15, 4500),
CONGA=dict(hz=330, decay=240), COWBELL=dict(hz=650, decay=240),
CLAVE=dict(hz=2400, decay=55))),
("DISCO", "DISCO", 0, kit(K909,
KICK=dict(decay=260, drive=20),
OHH=dict(ndec=520, nlev=114),
TOMLO=S("sine", 120, 24, 300, 600, 116), TOMHI=S("sine", 180, 24, 300, 520, 114))),
("SYNTHWV", "SYNTHWAVE", 0, kit(KLINN,
SNARE=dict(ndec=340, drive=50, nlev=118),
TOMLO=S("sine", 85, 18, 160, 600, 118, "white", 24, 50, 2500),
TOMHI=S("sine", 130, 18, 160, 520, 116, "white", 24, 50, 3000))),
TOMLO=S("sine", 120, 24, 300, 10, 600, 118, 1.5, 30), TOMHI=S("sine", 180, 24, 300, 10, 520, 116, 1.5, 30))),
("GARAGE", "UK GARAGE", 0, kit(K909,
KICK=S("sine", 54, 26, 20, 10, 260, 124, click=60, drive=40),
SNARE=S("tri", 240, 8, 10, 0, 80, 88, 1.6, 60, 50, "white", 112, 4, 120, ("hp", 2200, .25), drive=24),
SNARE2=S("tri", 280, 6, 8, 0, 50, 84, 1.5, 50, 50, "white", 100, 0, 80, ("bp", 6000, .4)),
CHH=dict(ndec=36, filt=("hp", 9500, .3)), SHAKER=dict(ndec=60, nlev=100),
RIM=dict(hz=2100, decay=24))),
("JUNGLE", "DRUM & BASS", 0, kit(K909,
KICK=S("sine", 58, 16, 18, 6, 200, 124, click=56, drive=50),
SNARE=S("tri", 260, 9, 10, 4, 100, 94, 1.6, 70, 50, "white", 114, 6, 170, ("hp", 1500, .25), drive=40),
SNARE2=S("tri", 300, 7, 8, 0, 60, 90, 1.6, 60, 50, "white", 106, 0, 110, ("bp", 5000, .35), drive=30),
CHH=dict(ndec=30), RIDE=dict(nlev=100))),
("DUBSTEP", "BASS MUSIC", 0, kit(K909,
KICK=S("sine", 48, 26, 24, 16, 420, 124, click=70, drive=64),
SNARE=S("tri", 170, 8, 20, 10, 170, 98, 1.7, 70, 50, "white", 122, 30, 420, ("hp", 600, .2), drive=64),
CLAP=dict(ndec=380), OHH=dict(ndec=300))),
# -- the world
("DEMBOW", "REGGAETON", 0, kit(K808,
KICK=dict(decay=520, drive=20, click=40),
SNARE=S("tri", 230, 5, 10, 0, 80, 84, 1.7, 60, 36, "white", 100, 4, 130, ("hp", 1800, .2), drive=20),
CLAP=dict(ndec=160), RIM=dict(tlev=104), SHAKER=dict(ndec=70, nlev=98))),
("AMAPIANO", "AMAPIANO", 0, kit(K808,
KICK=S("sine", 54, 14, 20, 8, 300, 124, click=40, drive=16),
KICK2=S("sine", 55, 24, 120, 20, 700, 124, 2.0, 50, 30, drive=56, # the log drum
filt=("lp", 1400, .5, "all"), fenv=1.5),
SHAKER=S(None, src="white", nlev=104, nhold=16, ndec=70, filt=("bp", 6500, .35)),
CLAP=dict(ndec=260), CONGA=dict(decay=260),
COWBELL=dict(hz=900, decay=160))),
("AFRO", "AFROBEAT", 0, kit(K808,
KICK=S("sine", 60, 10, 30, 6, 260, 120, click=20, filt=("lp", 2000, .1, "all")),
SNARE=S("tri", 330, 3, 10, 0, 60, 92, 1.5, 50, 30, "white", 70, 0, 60, ("bp", 5000, .3)),
CONGA=dict(decay=260, bend=2), TOMLO=S("sine", 160, 2, 20, 6, 260, 114, click=20),
TOMHI=S("sine", 230, 2, 20, 6, 220, 112, click=20), SHAKER=dict(ndec=80, nlev=100),
COWBELL=dict(hz=900, decay=180))),
("LATIN", "LATIN", 0, kit(KCR78,
KICK=S("sine", 62, 6, 20, 6, 230, 116, click=16, filt=("lp", 1800, .1, "all")),
TOMLO=S("sine", 200, 3, 15, 4, 200, 114, 1.6, 40, 40, "white", 26, 0, 15, ("bp", 4000, .3)), # timbales
TOMHI=S("sine", 300, 3, 15, 4, 180, 114, 1.6, 40, 40, "white", 26, 0, 15, ("bp", 4500, .3)),
CONGA=dict(hz=330, decay=240, click=30), COWBELL=dict(hz=650, decay=240),
CLAVE=dict(hz=2400, decay=55))),
("TRIBAL", "TRIBAL", 0, kit(K808,
KICK=S("sine", 52, 14, 60, 10, 600, 124, click=30, src="white", nlev=30, ndec=10, filt=("lp", 1500, .2)),
SNARE=S("sine", 160, 6, 30, 6, 260, 112, 1.6, 50, 30, "white", 40, 0, 60, ("lp", 3000, .2)),
TOMLO=S("sine", 75, 8, 90, 10, 600, 120, 1.5, 40, 30, "white", 26, 0, 30, ("lp", 1500, .2)),
TOMHI=S("sine", 115, 8, 90, 10, 520, 118, 1.5, 40, 30, "white", 26, 0, 30, ("lp", 2000, .2)),
CHH=S(None, src="white", nlev=90, ndec=40, filt=("bp", 6000, .3), hpf=5000),
OHH=S(None, src="white", nlev=92, nhold=10, ndec=160, filt=("bp", 5000, .3), hpf=4000),
CONGA=dict(decay=320))),
# -- synths and games
("SYNTHWV", "SYNTHWAVE", 0, kit(K707,
SNARE=dict(ndec=360, drive=50, nlev=120, hold=10),
TOMLO=S("sine", 85, 18, 160, 14, 600, 120, 1.5, 40, 24, "white", 24, 0, 50, ("lp", 2500, .1)),
TOMHI=S("sine", 130, 18, 160, 14, 520, 118, 1.5, 40, 24, "white", 24, 0, 50, ("lp", 3000, .1)))),
("CHIP", "CHIPTUNE", 0x04, KCHIP),
("8BIT", "HANDHELD", 0x26, kit(KCHIP, KICK=dict(decay=160), SNARE=dict(ndec=160))),
("ARCADE", "VIDEO GAME", 0x02, KFM),
("GLITCH", "GLITCH", 0x25, kit(KFM,
KICK=dict(decay=120, bt=12), SNARE=S(None, src="chip", nlev=112, ndec=70, chip=96),
CHH=S(None, src="chip", nlev=100, ndec=15, chip=127), OHH=S(None, src="chip", nlev=96, ndec=90, chip=125),
KICK=dict(decay=120, bt=12), SNARE=S(None, src="chip", nlev=112, ndec=70, chip=1300),
CHH=S(None, src="chip", nlev=100, ndec=15, chip=13000), OHH=S(None, src="chip", nlev=96, ndec=90, chip=11500),
CLAP=dict(ndec=80), TOMLO=dict(bt=40, decay=120), TOMHI=dict(bt=40, decay=100))),
("INDUSTR", "INDUSTRIAL", 0x02, kit(K909,
KICK=dict(drive=127, decay=380), SNARE=dict(drive=110, ndec=260),
KICK=dict(drive=127, decay=380, click=90), SNARE=dict(drive=110, ndec=260),
CLAP=dict(nlev=127, ndec=280), CHH=dict(src="metal", ndec=60), OHH=dict(src="metal", ndec=500),
TOMLO=S("fm", 90, 24, 200, 400, 118, drive=100), TOMHI=S("fm", 140, 24, 200, 340, 116, drive=100),
TOMLO=S("fm", 90, 24, 200, 10, 400, 118, drive=100), TOMHI=S("fm", 140, 24, 200, 10, 340, 116, drive=100),
CRASH=dict(src="metal", ndec=2200, nlev=118))),
("TRIBAL", "TRIBAL", 0, kit(K808,
KICK=S("sine", 52, 14, 60, 600, 122, "white", 30, 10, 1500),
SNARE=S("sine", 160, 6, 30, 260, 110, "white", 40, 60, 3000),
TOMLO=S("sine", 75, 8, 90, 600, 120, "white", 26, 30, 1500),
TOMHI=S("sine", 115, 8, 90, 520, 118, "white", 26, 30, 2000),
CHH=S(None, src="white", nlev=86, ndec=40, hpf=5000),
OHH=S(None, src="white", nlev=90, ndec=160, hpf=4000),
CONGA=dict(decay=320))),
("HYPER", "HYPERPOP", 0, kit(K909,
KICK=dict(drive=110, decay=380, bend=44),
SNARE=S("tri", 300, 10, 10, 90, 100, "white", 120, 180, 14000, 2000, 80),
KICK=S("sine", 54, 40, 20, 10, 380, 124, click=90, drive=110),
SNARE=S("tri", 300, 10, 10, 0, 90, 100, 1.6, 60, 60, "white", 122, 6, 180, ("hp", 2000, .3), drive=80),
CLAP=dict(nlev=127, ndec=240, hpf=1300),
CHH=dict(hpf=10000, ndec=30), OHH=dict(hpf=9500))),
CHH=dict(filt=("hp", 10000, .3), ndec=30), OHH=dict(filt=("hp", 9500, .3)))),
("AMBIENT", "AMBIENT", 0, kit(K808,
KICK=dict(tlev=100, decay=900, nlev=0, lpf=800),
SNARE=dict(lpf=3500, ndec=420, nlev=70, tlev=60),
CLAP=dict(lpf=1500, ndec=500, nlev=90),
CHH=dict(nlev=70, ndec=70, hpf=6000), OHH=dict(nlev=70, ndec=900),
CRASH=dict(nlev=80, ndec=3500), RIDE=dict(nlev=60, ndec=2500, lpf=7000))),
KICK=S("sine", 48, 8, 40, 10, 900, 104, filt=("lp", 700, .1, "all")),
SNARE=dict(filt=("lp", 3500, .2), ndec=420, nlev=70, tlev=60, click=0),
CLAP=dict(filt=("bp", 900, .3), ndec=500, nlev=90),
CHH=dict(nlev=72, ndec=70, filt=("bp", 7000, .3), hpf=6000), OHH=dict(nlev=72, ndec=900),
CRASH=dict(nlev=84, ndec=3500), RIDE=dict(nlev=64, ndec=2500, filt=("bp", 6000, .5)))),
("JAZZ", "JAZZ", 0, kit(K808,
KICK=S("sine", 62, 8, 20, 220, 96, "white", 30, 8, 1200),
SNARE=S("tri", 210, 2, 10, 60, 40, "white", 90, 320, 5000, 1500), # brushes
CHH=S(None, 300, src="cym", nlev=80, ndec=60, lpf=9000, hpf=5000),
OHH=S(None, 300, src="cym", nlev=80, ndec=500, lpf=9000, hpf=4500),
RIDE=S(None, 320, src="cym", nlev=86, ndec=2400, lpf=8000, hpf=3500),
TOMLO=S("sine", 110, 3, 30, 400, 104, "white", 16, 40, 2000),
TOMHI=S("sine", 160, 3, 30, 340, 102, "white", 16, 40, 2500))),
KICK=S("sine", 62, 8, 20, 4, 230, 100, click=24, src="white", nlev=30, ndec=8, filt=("lp", 1200, .1)),
KICK2=S("sine", 70, 6, 16, 4, 160, 96, click=30, src="white", nlev=30, ndec=6, filt=("lp", 1400, .1)),
SNARE=S("tri", 210, 2, 10, 0, 60, 40, src="white", nlev=92, nhold=30, ndec=320, # brushes
filt=("bp", 3500, .2)),
SNARE2=S("tri", 220, 3, 10, 0, 90, 80, 1.6, 50, 40, "white", 100, 0, 150, ("bp", 2800, .25)),
CHH=S(None, 300, src="cym", nlev=82, ndec=60, filt=("bp", 8000, .3), hpf=5000),
OHH=S(None, 300, src="cym", nlev=82, nhold=10, ndec=500, filt=("bp", 7500, .3), hpf=4500),
RIDE=S(None, 320, src="cym", nlev=90, ndec=2400, filt=("bp", 6500, .35), hpf=3500, click=16),
TOMLO=S("sine", 110, 3, 30, 6, 400, 106, 1.5, 40, 20, "white", 16, 0, 40, ("lp", 2000, .1)),
TOMHI=S("sine", 160, 3, 30, 6, 340, 104, 1.5, 40, 20, "white", 16, 0, 40, ("lp", 2500, .1)))),
]
def main(path):
levels = json.loads(LEVELS_FILE.read_text()) if LEVELS_FILE.exists() else {}
L = ["/* generated by tools/gen_drumkits.py */", "#pragma once",
f"#define DS_NKITS {len(KITS)}u", "static const dkit_t DS_KITS[DS_NKITS] = {"]
for name, style, crush, k in KITS:
assert len(name) <= 8 and len(style) <= 12, name
L.append(f' {{"{name}", "{style}", 0x{crush:02X}, {{')
for lane in LANES:
v = enc(k[lane])
assert all(0 <= x <= 127 for x in v[2:]) and len(v) == 12, (name, lane, v)
v = enc(k[lane], levels.get(name, {}).get(lane, 0.0))
assert len(v) == 22 and all(0 <= x <= 255 for x in v), (name, lane, v)
assert -128 <= v[17] <= 127, (name, lane)
L.append(" {" + ", ".join(str(x) for x in v) + f"}}, /* {lane} */")
L.append(" }},")
L.append("};")
+74 -28
View File
@@ -8,10 +8,11 @@ from the WAV 'smpl' chunk; the ADPCM state at the loop start is stored so loops
restart exactly.
Sources:
assets/samples-cc0/ CC0 samples (CREDITS.txt there): DUSTY, BASS, VIBES, HORNS, STRGS, FLUTE,
assets/samples-cc0/ CC0 samples (CREDITS.txt there): PIANO (a grand), BASS, VIBES, HORNS, STRGS, FLUTE,
SCRCH (tools/gen_builtin_hiphop.py makes them; FLUTE and the KIT:
tools/fetch_cc0.py), and hand percussion for the GM kit
gen_waves.py Felucca's own drum sounds (the Hügelton Sample Pack)
tools/fetch_cc0.py), and the acoustic drum kit of the GM map (KIT)
gen_waves.py Felucca's own drum sounds (the Hügelton Sample Pack): only SLICE's BREAK, or a
GM kit role the CC0 kit lacks
One SAMPLE preset is written per set (SET_PRESETS: its name and sound), plus EXTRA_PRESETS.
A file named ..._m<n>.wav has its root given (MIDI note n); else it comes from the note in the name.
@@ -23,6 +24,7 @@ slices) is written with it: SLC_BREAK_INIT.
The header is cached in build/gen_samples.cache under a hash of every input.
"""
import hashlib
import math
import os
import re
import subprocess
@@ -39,16 +41,17 @@ CACHE = SRC / "build" / "gen_samples.cache"
CC0 = SRC / "assets" / "samples-cc0"
TR = 22050 # stored sample rate
# set -> kind ("oneshot" decaying, "sus" looped sustain, "kit" one sample per key).
# set -> kind ("oneshot" decaying, "sus" looped sustain, "piano" its attack then a steady loop that the
# envelope fades, "kit" one sample per key).
# The other slots are user sets loaded from the web editor.
CC0_SETS = [("DUSTY", "oneshot"), ("BASS", "oneshot"), ("VIBES", "oneshot"), ("HORNS", "oneshot"),
CC0_SETS = [("PIANO", "piano"), ("BASS", "oneshot"), ("VIBES", "oneshot"), ("HORNS", "oneshot"),
("STRGS", "oneshot"), ("FLUTE", "sus"), ("SCRCH", "oneshot"), ("KIT", "kit")]
MEASURED_TUNING = () # sets recorded off A440 (measured near the named note)
# the preset of each set: name, {SET (filled in), TUNE, BITS, LOOP (filled in), CUT, -, DRV, -}, env, mono,
# sends (DIST, CHORUS, DELAY, REVERB), more (track parameter, value) pairs (preset_t.x)
SET_PRESETS = {
"DUSTY": ("DUSTY PNO", [0, 0, 20, 0, 104, 0, 14, 0], (0, 127, 127, 52), 0, (0, 8, 10, 22), ()),
"PIANO": ("GRAND PNO", [0, 0, 0, 0, 127, 0, 0, 0], (0, 110, 0, 58), 0, (0, 6, 8, 24), ()),
"BASS": ("UP BASS", [0, 0, 0, 0, 118, 0, 12, 0], (0, 127, 127, 26), 1, (0, 0, 0, 4), ()),
"VIBES": ("VIBES", [0, 0, 0, 0, 127, 0, 0, 0], (0, 127, 127, 72), 0, (0, 24, 22, 30), ("P_LD_AMP", 18, "P_LRATE", 86)),
"HORNS": ("HORN STAB", [0, 0, 0, 0, 120, 0, 20, 0], (0, 127, 127, 22), 0, (8, 0, 14, 18), ()),
@@ -59,7 +62,8 @@ SET_PRESETS = {
}
# more presets on a set: (set, name, E[], env, mono, sends, more)
EXTRA_PRESETS = [
("DUSTY", "LOFI KEYS", [0, 0, 45, 0, 78, 0, 30, 0], (0, 127, 110, 60), 0, (0, 30, 18, 34), ("P_LD_PIT", 1, "P_LRATE", 38)),
("PIANO", "DUSTY PNO", [0, 0, 34, 0, 96, 0, 24, 0], (0, 98, 0, 52), 0, (0, 8, 10, 22), ()),
("PIANO", "LOFI KEYS", [0, 0, 45, 0, 78, 0, 30, 0], (0, 108, 0, 60), 0, (0, 30, 18, 34), ("P_LD_PIT", 1, "P_LRATE", 38)),
("BASS", "DEEP BASS", [0, -12, 0, 0, 90, 0, 40, 0], (0, 127, 127, 30), 1, (0, 0, 0, 0), ()),
]
@@ -72,18 +76,28 @@ NOTE = {"C": 0, "C#": 1, "D": 2, "D#": 3, "E": 4, "F": 5, "F#": 6, "G": 7, "G#":
GM_KIT = {
"kick": [(35, 36, 36)], "rim": [(37, 37, 37)], "snare": [(38, 38, 38), (40, 40, 40)],
"clap": [(39, 39, 39)], "chh": [(42, 42, 42), (44, 44, 44)], "ohh": [(46, 46, 46)],
"tomlo": [(41, 45, 43)], "tomhi": [(47, 50, 48)], "tom": [(41, 50, 47)],
# (the toms skip the hi-hats' 42, 44, 46: a zone over them would win, the hats would play a tom)
"tomlo": [(41, 41, 43), (43, 43, 43), (45, 45, 43)], "tomhi": [(47, 48, 48), (50, 50, 48)],
"tom": [(41, 41, 47), (43, 43, 47), (45, 45, 47), (47, 48, 47), (50, 50, 47)],
"crash": [(49, 49, 49), (52, 52, 52), (55, 55, 55), (57, 57, 57)],
"ride": [(51, 51, 51), (53, 53, 53), (59, 59, 59)],
"tamb": [(54, 54, 54)], "cowbell": [(56, 56, 56)], "conga": [(62, 64, 63)],
"shaker": [(69, 70, 70), (82, 82, 82)], "claves": [(75, 75, 75)], "wood": [(76, 77, 76)],
}
GM_ROLE_WORDS = [("bassdrum", "kick"), ("kick", "kick"), ("snare", "snare"), ("hihat", "chh"), ("chat", "chh"),
("ohat", "ohh"), ("clap", "clap"), ("tom lo", "tomlo"), ("tom hi", "tomhi"), ("tom", "tom"),
("ohat", "ohh"), ("clap", "clap"), ("tom lo", "tomlo"), ("tom hi", "tomhi"), ("tomlo", "tomlo"),
("tomhi", "tomhi"), ("tom", "tom"),
("rim", "rim"), ("cowbell", "cowbell"), ("tamb", "tamb"), ("shaker", "shaker"),
("conga", "conga"), ("claves", "claves"), ("wood", "wood"), ("crash", "crash"), ("ride", "ride")]
GM_KEEP = {"crash": 0.8, "ride": 0.8, "ohh": 0.5}
GM_CC0_ROLES = ("tamb", "shaker", "conga", "claves", "wood") # the CC0 set is orchestral: hand percussion only
GM_KEEP = {"crash": 1.0, "ride": 1.0, "ohh": 0.6}
GM_RATE = {"chh": 32000, "ohh": 32000, "crash": 32000, "ride": 32000} # the metal keeps its top (else TR)
# an acoustic kit from the CC0 recordings (assets/samples-cc0/KIT: VCSL): the concert bass drum and the toms
# get a shorter body (a kit's tuned-up, damped heads): their level falls as exp(-t / tau) after a hold
GM_SHAPE = {"kick": (0.03, 0.13), "tomlo": (0.04, 0.22), "tomhi": (0.04, 0.2)}
# the balance of the kit (dB under full scale): the kick and the snare up front, the metal and the hand
# percussion further back, as the synthesised kits (tools/level_drumkits.py); the click's wood block stays
GM_GAIN = {"chh": -9, "ohh": -9, "crash": -8, "ride": -9, "shaker": -8, "tamb": -6, "conga": -4, "cowbell": -4,
"claves": -4}
# SLICE's BREAK: (step, GM role, gain) on a bar of 16ths; the open hat is choked by the next hat
BREAK_BPM, BREAK_STEPS = 120, 16
@@ -147,10 +161,21 @@ def cc0_entries(setname, kind):
else:
root = hz_to_midi(detect_hz(x, sr))
x = resample(x, sr, TR)
keep = {"oneshot": 1.0, "sus": 0.95, "kit": 0.6}[kind]
keep = {"oneshot": 1.0, "sus": 0.95, "kit": 0.6, "piano": 1.0}[kind]
x = x[:int(keep * TR)]
n = len(x)
if kind == "sus": # crossfaded sustain loop in the steady part
if kind == "piano": # the attack, then a steady tone the envelope (DEC) fades:
ls, le, xf, a0 = int(0.55 * TR), n - 1, int(0.08 * TR), int(0.30 * TR) # long notes in 1 s
w = int(0.02 * TR)
env = [max(1e-6, (sum(v * v for v in x[max(0, i - w):i + w]) / (2 * w)) ** 0.5) for i in range(0, n, w)]
ref = env[a0 // w]
x = [v * (ref / env[min(len(env) - 1, i // w)] if i >= a0 else 1.0) for i, v in enumerate(x)]
ls = best_loop_start(x, le, xf, int(0.45 * TR), int(0.65 * TR)) # (the tone in phase: no dip)
for i in range(xf):
a = i / xf
x[le - xf + i] = x[le - xf + i] * (1 - a) + x[ls - xf + i] * a
loop = (ls, le)
elif kind == "sus": # crossfaded sustain loop in the steady part
ls, le, xf = int(0.40 * TR), n - 1, int(0.06 * TR)
for i in range(xf):
a = i / xf
@@ -166,42 +191,62 @@ def cc0_entries(setname, kind):
return out
def best_loop_start(x, le, xf, lo, hi):
"""the loop start in [lo, hi) whose last xf samples look most like the loop end's (correlation, on
every 4th sample, every 2nd start: plain Python, no numpy): the crossfade then joins two copies of the
same wave, not two phases that cancel"""
tail = x[le - xf:le:4]
tn = sum(v * v for v in tail) ** 0.5 + 1e-9
best, bl = -2.0, (lo + hi) // 2
for ls in range(lo, hi, 2):
seg = x[ls - xf:ls:4]
c = sum(a * b for a, b in zip(seg, tail)) / ((sum(v * v for v in seg) ** 0.5 + 1e-9) * tn)
if c > best:
best, bl = c, ls
return bl
def gm_role(name):
n = name.lower()
return next((r for w, r in GM_ROLE_WORDS if w in n), None)
def gm_kit_sources(have_cc0):
"""role -> wav path: Felucca's own synthesized drum kit (generated by
gen_waves.py), plus CC0 hand percussion for the roles it does not make"""
"""role -> wav path: the CC0 acoustic kit (assets/samples-cc0/KIT); without it (and for SLICE's BREAK)
Felucca's own synthesized drums (gen_waves.py) for the roles it lacks"""
src = {}
if have_cc0 and (CC0 / "KIT").exists():
for p in sorted((CC0 / "KIT").glob("*.wav")):
r = gm_role(p.name)
if r and r not in src:
src[r] = p
for p in sorted(GENDIR.glob("D *.wav")):
r = gm_role(p.stem)
if r and r not in src:
src[r] = p
if have_cc0 and (CC0 / "KIT").exists():
for p in sorted((CC0 / "KIT").glob("*.wav")):
r = gm_role(p.name)
if r in GM_CC0_ROLES and r not in src:
src[r] = p
if "tomlo" in src or "tomhi" in src:
src.pop("tom", None)
return src
def gm_kit_entry(role, path):
def gm_kit_entry(role, path, rate=TR):
sr, x = wav(path)
x = resample(x[max(0, onset(x) - 16):], sr, TR)
x = x[:int(GM_KEEP.get(role, 0.45) * TR)]
x = resample(x[max(0, onset(x) - 16):], sr, rate)
x = x[:int(GM_KEEP.get(role, 0.45) * rate)]
if role in GM_SHAPE:
hold, tau = GM_SHAPE[role]
h = int(hold * rate)
x = [v * (1.0 if i < h else math.exp(-(i - h) / (tau * rate))) for i, v in enumerate(x)]
pk = peak(x)
end = len(x) # drop the silent tail
while end > 64 and abs(x[end - 1]) < 0.004 * pk:
end -= 1
x = x[:end]
fade = min(len(x) // 4, int(0.03 * TR))
fade = min(len(x) // 4, int(0.03 * rate))
for i in range(fade):
x[len(x) - fade + i] *= 1 - i / fade
return [int(v * 30000 / pk) for v in x]
g = 30000 / pk * 10 ** (GM_GAIN.get(role, 0) / 20) if path.parent.name == "KIT" else 30000 / pk
return [int(v * g) for v in x]
def ima_states(data, positions):
@@ -284,13 +329,14 @@ class Builder:
self.kinds[name] = kind
def gm_kit(self, have_cc0):
"""one GM-mapped kit: generated drums + CC0 hand percussion"""
"""one GM-mapped kit: the CC0 acoustic kit"""
z0 = len(self.zones)
for role, path in gm_kit_sources(have_cc0).items():
smp = gm_kit_entry(role, path)
rate = GM_RATE.get(role, TR) if path.parent.name == "KIT" else TR
smp = gm_kit_entry(role, path, rate)
off, st = self.add(smp, len(smp))
for lo, hi, root in GM_KIT[role]:
self.zones.append(dict(off=off, n=len(smp), ls=len(smp), le=len(smp), looped=False, sr=TR,
self.zones.append(dict(off=off, n=len(smp), ls=len(smp), le=len(smp), looped=False, sr=rate,
root16=root * 16, pred=st[0], idx=st[1], lo=lo, hi=hi))
self.sets.append(("PERC", z0, len(self.zones) - z0))
self.kinds["PERC"] = "kit"
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
"""Measures every synthesised drum sound and writes tools/drumkit_levels.json (the trims, dB, that
gen_drumkits.py adds to each sound's level). Loudness: the loudest 100 ms (ITU-R BS.1770 weighting),
so a kit's kick, snare and hats land at the same place in every kit; no sound peaks above -4 dBFS.
cc -O2 -Ibuild/gen -Ifirmware/src -Ifirmware/hal tests/drum_level.c -lm -o build/host/drum_level
build/host/drum_level build/host/hits.raw && tools/level_drumkits.py build/host/hits.raw
(then rebuild: the header is generated from the new trims; run it twice after big changes)
Needs numpy and scipy."""
import json
import re
import sys
from pathlib import Path
import numpy as np
from scipy.signal import lfilter
FS = 44100
N = FS * 2 // 32 * 32
HERE = Path(__file__).parent
LANES = "KICK SNARE CLAP CHH OHH TOMLO TOMHI CRASH RIDE SHAKER CONGA RIM COWBELL CLAVE KICK2 SNARE2".split()
KICK = -12.0 # the kick's loudness, LUFS-like (100 ms window)
REL = dict(KICK=0, KICK2=0, SNARE=-1, SNARE2=-2.5, CLAP=-2, CHH=-15, OHH=-12, TOMLO=-3, TOMHI=-3.5,
CRASH=-10, RIDE=-13, SHAKER=-17, CONGA=-5, RIM=-6, COWBELL=-6, CLAVE=-7)
KIT = {"AMBIENT": -1.5, "JAZZ": -1.5, "VINTAGE": -0.5, "LATIN": -0.5}
PEAK = -4.0
def loudness(x):
b1 = [1.53512485958697, -2.69169618940638, 1.19839281085285]
a1 = [1, -1.69065929318241, 0.73248077421585]
b2, a2 = [1, -2, 1], [1, -1.99004745483398, 0.99007225036621]
k = lfilter(b2, a2, lfilter(b1, a1, x)) ** 2
w = int(0.1 * FS)
c = np.concatenate([[0], np.cumsum(k)])
return 10 * np.log10(((c[w:] - c[:-w]) / w).max() + 1e-12) - 0.691
def main(raw):
names = re.findall(r'\("([^"]+)", "[^"]*", 0x?[0-9A-F]*,', (HERE / "gen_drumkits.py").read_text())
d = np.fromfile(raw, np.int32).astype(float) / 32768.0
assert len(d) == len(names) * 16 * N, "the hits do not match gen_drumkits.py (rebuild first)"
path = HERE / "drumkit_levels.json"
old = json.loads(path.read_text()) if path.exists() else {}
out = {}
for ki, n in enumerate(names):
out[n] = {}
for li, lane in enumerate(LANES):
x = d[(ki * 16 + li) * N:(ki * 16 + li + 1) * N]
want = KICK + REL[lane] + KIT.get(n, 0.0)
adj = min(want - loudness(x), PEAK - 20 * np.log10(np.abs(x).max() + 1e-9))
t = old.get(n, {}).get(lane, 0.0) + adj
out[n][lane] = round(max(-31.75, min(31.75, t)) * 4) / 4
path.write_text(json.dumps(out, indent=1) + "\n")
print(f"{len(names)} kits levelled -> {path}")
if __name__ == "__main__":
main(sys.argv[1])
+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
"""Measures every factory preset and writes firmware/src/preset_trim.h: a level trim per preset
(1/2 dB, the steps of LEVEL), so every sound comes out as loud as the others at the same LEVEL.
Loudness: ITU-R BS.1770 integrated (gated) over a phrase that fits the sound (tests/preset_level.c:
a bass line, held chords, comping or a melody).
cc -O2 -Ibuild/gen -Ifirmware/src -Ifirmware/hal tests/preset_level.c -lm -o build/host/preset_level
build/host/preset_level build/host/presets.wav build/host/presets.txt build/host/presets.raw
tools/level_presets.py build/host/presets.raw build/host/presets.txt
(rebuild and run it again until nothing moves: the trims add to the ones in preset_trim.h)
Needs numpy and scipy."""
import re
import sys
from pathlib import Path
import numpy as np
from scipy.signal import lfilter
FS, CTL = 44100, 32
SEG = (FS * 9 // 2) // CTL * CTL + (FS // 4) // CTL * CTL
OUT = Path(__file__).resolve().parent.parent / "firmware/src/preset_trim.h"
TARGET = -15.0 # LUFS (integrated), at the default LEVEL
ROLE = {0: 0.0, 1: -1.0, 2: 0.0, 3: 0.0, 4: 0.0} # bass, chords held (pads, organs), comping, melody, one-key chords
SKIP = {"GM KIT"} # (the drum map on a synth track: as it is)
def lufs(x):
b1 = [1.53512485958697, -2.69169618940638, 1.19839281085285]
a1 = [1, -1.69065929318241, 0.73248077421585]
b2, a2 = [1, -2, 1], [1, -1.99004745483398, 0.99007225036621]
k = lfilter(b2, a2, lfilter(b1, a1, x)) ** 2
w, h = int(0.4 * FS), int(0.1 * FS)
bl = np.array([k[i:i + w].mean() for i in range(0, len(k) - w, h)])
bl = bl[bl > 1e-7]
if not len(bl):
return None
g = bl[10 * np.log10(bl) - 0.691 > -70]
rel = 10 * np.log10(g.mean()) - 0.691 - 10
g = g[10 * np.log10(g) - 0.691 > rel]
return 10 * np.log10(g.mean()) - 0.691
def main(raw, rep):
rows = [l.split(None, 3) for l in Path(rep).read_text().splitlines()]
d = np.fromfile(raw, np.int32).astype(float) / 32768.0
old = {}
if OUT.exists():
for e, name, v in re.findall(r"/\* (\d+)\.\d+ (.*?) \*/ (-?\d+)", OUT.read_text()):
old[(int(e), name)] = int(v) # (by name: presets may move in their table)
neng = max(int(r[0]) for r in rows) + 1
pmax = 16
tab = [[0] * pmax for _ in range(neng)]
names = [[""] * pmax for _ in range(neng)]
for i, (e, p, role, name) in enumerate(rows):
e, p, role = int(e), int(p), int(role)
assert p < pmax, name
names[e][p] = name
L = lufs(d[i * SEG:(i + 1) * SEG])
t = old.get((e, name), 0)
if L is not None and name not in SKIP:
t += int(round((TARGET + ROLE[role] - L) * 2))
tab[e][p] = max(-40, min(23, t)) # (LEVEL 104 + 23 = 127: the top of the table)
lines = ["/* generated by tools/level_presets.py: the level trim of each factory preset, 1/2 dB */",
"#pragma once", f"#define PT_ENGINES {neng}u", f"#define PT_MAX {pmax}u",
"static const int8_t PRESET_TRIM[PT_ENGINES][PT_MAX] = {"]
for e in range(neng):
cells = [f"/* {e}.{p} {names[e][p] or '-'} */ {tab[e][p]}" for p in range(pmax) if names[e][p]]
lines.append(" {" + ", ".join(cells) + "},")
lines.append("};")
OUT.write_text("\n".join(lines) + "\n")
print(f"{len(rows)} presets levelled -> {OUT}")
if __name__ == "__main__":
main(sys.argv[1], sys.argv[2])