Created
December 16, 2024 17:39
-
-
Save matthewryanscott/aa5f71fda8501e0062817fb542c1952f to your computer and use it in GitHub Desktop.
Function to append a Serum-compatible comment to a WAV file so you don't have to enter 2048 every time you load a wavetable
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
from pathlib import Path | |
from struct import pack | |
def add_serum_chunk(wav_path: Path): | |
# Existing WAV file must be in a 2048-samples-per-frame format. | |
# See https://www.kvraudio.com/forum/viewtopic.php?t=517146 | |
comment = "<!>2048 00000000 wavetable (www.xferrecords.com)" | |
encoded = comment.encode("utf8") | |
chunk_id = b"clm " | |
chunk_size = len(encoded) | |
chunk_size_bytes = pack("<I", chunk_size) | |
clm_chunk = chunk_id + chunk_size_bytes + encoded | |
with wav_path.open("ab") as f: | |
f.write(clm_chunk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment