Sunvox Sampler Demo
Last active
May 28, 2023 00:57
-
-
Save jhw/fec48c23c5d6c3efeb84352faa95a40c to your computer and use it in GitHub Desktop.
Sunvox Sampler Demo
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
bin | |
include | |
lib | |
local | |
share | |
*.pyc | |
data | |
tmp | |
patch-decompiler-output | |
*.sunvox | |
.sunvox* |
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 rv.api import Project as RVProject | |
from rv.modules.sampler import Sampler | |
from scipy.io import wavfile | |
import warnings | |
warnings.simplefilter("ignore", wavfile.WavFileWarning) | |
class Modules(list): | |
def arrange(self, dx=128): | |
offset=len(self) | |
for i, mod in enumerate(reversed(self)): | |
mod.x=(offset-(i+1))*dx | |
def attach(self, proj): | |
for i, mod in enumerate(reversed(self)): | |
proj.attach_module(mod) | |
proj.connect(proj.modules[i+1], | |
proj.modules[i]) | |
""" | |
https://github.com/metrasynth/gallery/blob/master/wicked.mmckpy#L497-L526 | |
""" | |
def load_wav_to_sampler_slot(path, sampler, slot, **kwargs): | |
sample = sampler.Sample() | |
freq, snd = wavfile.read(str(path)) | |
if snd.dtype.name == 'int16': | |
sample.format = sampler.Format.int16 | |
elif snd.dtype.name == 'float32': | |
sample.format = sampler.Format.float32 | |
else: | |
raise RuntimeError("dtype %s Not supported" % snd.dtype.name) | |
if len(snd.shape) == 1: | |
size, = snd.shape | |
channels = 1 | |
else: | |
size, channels = snd.shape | |
sample.rate = freq | |
sample.channels = { | |
1: Sampler.Channels.mono, | |
2: Sampler.Channels.stereo, | |
}[channels] | |
sample.data = snd.data.tobytes() | |
for key, value in kwargs.items(): | |
setattr(sample, key, value) | |
sampler.samples[slot] = sample | |
return sample | |
""" | |
- multiple samples might not be a good idea due to pitch shifting | |
- any way to turn it off ? | |
- if not then if you have (eg) n samples it becomes very hard to maintain all n samples at the original pitch | |
- so might be simpler to have separate instruments | |
""" | |
Samples=["01. 7007 BD.wav", | |
"30. 9009 HC.wav"] | |
Samples=["30. 9009 HC.wav"] | |
if __name__=="__main__": | |
try: | |
sampler=Sampler() | |
for i, sample in enumerate(Samples): | |
load_wav_to_sampler_slot(sample, sampler, i) | |
for i, key in enumerate(sampler.note_samples): | |
sampler.note_samples[key] = i % len(Samples) # hack | |
modules=Modules([sampler]) | |
modules.arrange() | |
proj=RVProject() | |
proj.initial_bpm=120 | |
modules.attach(proj) | |
with open("hello_sampler.sunvox", 'wb') as f: | |
proj.write_to(f) | |
except RuntimeError as error: | |
print ("Error: %s" % str(error)) |
- virtualenv -p /usr/bin/python3.6 .
- source bin/activate
- pip install -r requirements.txt
- {...}
- deactivate
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
attrs==19.1.0 # https://stackoverflow.com/questions/58189683/typeerror-attrib-got-an-unexpected-keyword-argument-convert | |
git+https://github.com//metrasynth/radiant-voices@jhw-fix-reader | |
scipy |
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
#!/bin/sh | |
~/packages/sunvox/sunvox/linux_x86_64/sunvox |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment