josephernest / samplerbox Goto Github PK
View Code? Open in Web Editor NEWSamplerBox is a sampler musical instrument based on RaspberryPi.
Home Page: https://www.samplerbox.org
SamplerBox is a sampler musical instrument based on RaspberryPi.
Home Page: https://www.samplerbox.org
Pavel posted Feb 2, 05:18:
http://www.samplerbox.org/forum/23
I have implemented %%velocitysensitivity option for patches to change volume depending on velocity
https://github.com/paul-at/SamplerBox/tree/velocity-sensitive
git clone https://github.com/paul-at/SamplerBox/tree/velocity-sensitive
cd SamplerBox; make
Add %%velocitysensitivity=1 to definition.txt in patch directory. If it does not exist already, create following:
%midinote.wav
%%velocitysensitivity=1
If you want to use sounddevice instead of pyaudio with nickyspride.nl version
replace pyaudio with sounddevice
import sounddevice
Change in AudioCallback
#########################################
# AUDIO CALLBACK
#########################################
def AudioCallback(outdata, frame_count, time_info, status):
global playingsounds, SampleLoading
global BackingRunning
global BackWav, BackIndex, ClickWav, ClickIndex
global globalvolume, backvolume, clickvolume
rmlist = []
# print "sounds: " +str(len(playingsounds)) + " notes: " + str(len(playingnotes)) + " sust: " + str(len(sustainplayingnotes))
playingsounds = playingsounds[-MAX_POLYPHONY:]
b = samplerbox_audio.mixaudiobuffers(playingsounds, rmlist, frame_count, FADEOUT, FADEOUTLENGTH, SPEED)
for e in rmlist:
try:
playingsounds.remove(e)
except:
pass
# b *= globalvolume
if USE_FREEVERB:
b_temp = b
freeverbprocess(b_temp.ctypes.data_as(c_float_p), b.ctypes.data_as(c_float_p), frame_count)
# IF USE_TONECONTOL
# b = numpy.array(chain.filter(bb))
# b=bb
if CHANNELS == 4: # 4 channel playback
# if backingtrack running: add in the audio
if BackingRunning:
BackData = BackWav[BackIndex:BackIndex+2*frame_count]
ClickData = ClickWav[ClickIndex:ClickIndex+2*frame_count]
BackIndex += 2*frame_count
ClickIndex += 2*frame_count
if len(b) != len(BackData) or len(b) != len(ClickData):
BackingRunning = False
BackData = None
BackIndex = 0
ClickData = None
ClickIndex = 0
if BackingRunning:
newdata = (backvolume * BackData + b * globalvolume)
Click = ClickData * clickvolume
else:
Click = numpy.zeros(frame_count*2, dtype=numpy.float32)
newdata = b * globalvolume
# putting streams in 4 channel audio by magic in numpy reshape
a1 = newdata.reshape(frame_count, 2)
a2 = Click.reshape(frame_count, 2)
ch4 = numpy.hstack((a1, a2)).reshape(1, frame_count*4)
# Mute while loading Sample or BackingTrack
# otherwise there could be dirty hick-ups
if SampleLoading or (BackLoadingPerc > 0 and BackLoadingPerc < 100):
ch4 *= 0
return (ch4.astype(numpy.int16).tostring(), pyaudio.paContinue)
else: # 2 Channel playback
# if backingtrack running: add in the audio
if BackingRunning:
BackData = BackWav[BackIndex:BackIndex+2*frame_count]
BackIndex += 2*frame_count
if len(b) != len(BackData):
BackingRunning = False
BackData = None
BackIndex = 0
if BackingRunning:
newdata = (backvolume * BackData + b * globalvolume)
else:
newdata = b * globalvolume
outdata[:] = newdata.reshape(outdata.shape)
Change in MAIN CODE
try:
sd = sounddevice.OutputStream(device=AUDIO_DEVICE_ID, blocksize=512, samplerate=48000, channels=CHANNELS, dtype='int16', callback=AudioCallback)
sd.start()
# stream = p.open(format=pyaudio.paInt16, channels=CHANNELS, rate=48000, frames_per_buffer=BUFFERSIZE, output=True,
# output_device_index=AUDIO_DEVICE_ID, stream_callback=AudioCallback)
Sometimes, when i play default 0 saw files, it never ends. I need to restart my roland module.
It may happen as well that the sample lasts more than expected.
And some other times, it works fine.
my config: rpi3, jessie dist with manual installation of the paul's implmentation (i need to run another appli on it), usb/midi convertissor, roland td6 module
Any idea?
Cheers
ps: i have noticed a lot of midi messages sent by the module (maybe clock messages) regularly
Hello
I do not understand ,if i made 4 layers of Velocity record ( 10,40,70,127 )for example
If the midi message comes with Velocity value of (35) what sample will be played the 10 or 40 vel ?
thanks
@mojca I suggest we make a last Python2 ISO release to make sure everything works for people still using this good old version, and then we can move 100% to Python3 version. Todo:
python-pip
now included out-of-the-box on a RaspiOS Lite like 2021-05-07-raspios-buster-armhf-lite.img
?Then we can add features in python3
branch and after some time, make this branch the default one.
Hey there!
I went with Recommended install - written image on a microSD - as usual with Jessie
But somehow it wont auto start - all i can see after boot is
Raspbian Linux 8 samplerbox tty1
samplerbox login:
And thats it
What should i do?
Don't have keyboard now, and SSH won't work
My Raspberry Pi 2 B arrived yesterday, which I bought with the intention of using SamplerBox with it. I loaded a bunch of samples on it and was really stoked to hear the sounds coming out of a tiny computer running a python script! I commend you on your awesome work so far!
The issue: I found that playing three of more samples at once often results in a hard crackling sound that sounds like clipping. This makes it pretty much to play the sampler like a piano as I'm planning to (I have a Nord synth without piano sounds that I'm hoping to supplement with the SamplerBox).
I am using a cheap mini USB audio interface. I don't think it's quite as high-quality as the DAC you recommend, but I have used it for DJing with Traktor in the past without issue, so I don't think it's that.
I'm assuming this really is clipping. Any ideas how we can prevent this, presumably with a compressor / limiter setup? I will test this over the weekend by turning down the master volume. This isn't really a long-term solution though (it should be able to keep up with the Nord volume level to at least a reasonable degree).
I found a basic limiter written in C with Python bindings but beyond that there seems to be amazingly little available in the open source community. Am I missing something, I mean is this built into ALSA or JACK or something and I just don't know about it?
Hello,
First of all, thank you for this project. It is quite fun to use.
I'm looking into building the box, specially because my MIDI controller is a bit buggy regarding presets. Do you happen to have a GPIO mapping for the buttons? I saw the wiring, but I just want to double check.
Thank you !
When I put the .IMG file onto my sd card, then put it in my RPI 2, I plugged it in, but nothing happened. My keyboard didn't turn on when plugged in through USB, but my speaker had a faint static-like sound.
I am not using the full setup, just with my midi keyboard over USB.
Can you help with this?
Thanks, Samuel
Dorgangrinder posted Mar 24, 13:11:
http://www.samplerbox.org/forum/133
Hey all, further to my original post I decided to give it a shot myself. I can confirm the image doesn't work on rpi3, but installing it manually does.
There are various changes you'll need to make to the samplerbox.py in order to get it working though.
If anyone wants more info, please let me know.
But, I am always stuck without any sound produced due to some configuration error...
Hi,
With python 2 being officially deprecated, are there any plans to update this to Python 3? Python 3 should also give more speed and stability.
Thanks
It's written to install the python package
(This is mostly a reminder for me)
I needed some sustain for the piano but if I use sustain=True there was too much sustain.
You can however have more or less sustain by tweaking FADEOUTLENGTH.
Instead of the python audio error, it would be better to output a comprehensive error message with a list of audio devices
For example:
try:
stream = p.open(format = pyaudio.paInt16, channels = 2, rate = 44100, frames_per_buffer = 512, output = True, input = False, output_device_index = AUDIO_DEVICE_ID, stream_callback = AudioCallback)
print 'Opened audio: '+ p.get_device_info_by_index(AUDIO_DEVICE_ID)['name']
except:
print "Invalid Audio Device ID: " + str(AUDIO_DEVICE_ID)
print " "
print "Here is a list of audio devices:"
for i in range(p.get_device_count()):
dev = p.get_device_info_by_index(i)
# Remove input device (not really useful on a Raspberry Pi)
if dev['maxOutputChannels'] > 0:
print str(i) + " -- " + dev['name']
exit(1)
Trying to change program from keyboard or another usb entry.
¿It's steel possible?
Hi,
I'm using sampler box to trigger drum sounds from my electronic drum kit. The sample sets I am using (acoustic drum kits) have 3 hits for each drum / cymbal, each hit is the same velocity but varies in tone slightly and helps make the kit sound more natural and less like a drum machine.
Could there be a way to have 3 .wav files for the same note that randomise?
Thanks for the great software by the way.
Some of the sample files available for some of the better patches take up a lot of memory. How hard would it be to add support for ogg, flac, and/or mp3?
Required rtmidi-python
is a 2014 library.
Therefore, it's not working anymore with Python >= 3.9 (https://stackoverflow.com/questions/71410788/pip-failed-building-wheel-for-rtmidi-python-subprocess-exited-with-error-and-le).
Problem is current Python version is 3.12, and even Raspberry Pi OS legacy version (11 Bullseye) is bundled with Python 3.9.
Any idea to get around this?
How can i modify the code below, for using only one midi-channel instead of omni-mode (all channel) input...?
def MidiCallback(message, time_stamp):
global playingnotes, sustain, sustainplayingnotes
global preset
messagetype = message[0] >> 4
messagechannel = (message[0] & 15) + 1
note = message[1] if len(message) > 1 else None
midinote = note
velocity = message[2] if len(message) > 2 else None
Simon posted yesterday, 21:46:
http://www.samplerbox.org/forum/141
Is there a way to use a midi file as input ?
I was so entrained by this project that i bougth everything and assabled it without even thinking about the need of a midi device to give the box some input.
In about three weeks i'll have plenty midi devices to play with but i dont want to wait :)
Thanks in advance!
Hi,
Trying this line of code on jupyter notebook:
import sounddevice as sd
Getting the following error:
ModuleNotFoundError: No module named 'sounddevice'
Have tried:
pip install sounddevice
conda install -c conda-forge python-sounddevice
brew install portaudio
brew reinstall portaudio
pip install setuptools --user
pip install cffi --user
sudo pip install rtmidi-python pyaudio cffi sounddevice
pip install --upgrade pip
python3 -m pip install sounddevice
Does anyone know what might be wrong?
Thank you in advance!
I've downloaded SamplerBox to my Raspberry Pi 4. After running python samplerbox.py
, I get Invalid audio device #2
. How do I fix this?
I like to use samba to simplify the creation of samples, I can upload wav files directly and reload them without restarting my Raspberry Pi
As Samba won't work in a read-only filesystem, and since I need it only when i'm making samples.
i remove it from boot.
Here is the procedure
mount -o remount,rw /
apt-get update;apt-get upgrade
apt-get install samba
Create password for root
smbpasswd
Modify /etc/samba/smb.conf
======================= Global Settings =======================
[global]
dns proxy = no
workgroup = WORKGROUP
os level = 20
syslog = 0
panic action = /usr/share/samba/panic-action %d
max log size = 1000
#Unsecure mode
security = user
browseable = yes
writeable = yes
guest ok = yes
load printers = no
printing = bsd
printcap name = /dev/null
disable spoolss = yes
#======================= Name =========================
#Name of your Raspberry Pi
netbios name = synth
#======================= Shares =======================
[usb]
# Path / User
path = /media
force user = root
Restart samba
/etc/init.d/samba restart
Check if you have access to \synth\usb
Remove it from boot
update-rc.d -f smbd remove
update-rc.d -f nmbd remove
mount -o remount,rw /
/etc/init.d/samba start
User :root
Password: root
A great thing for amplerbox would be to add jack support.
This feature would open easy integration with any other jack supported applications, for instance, sooperlooper (to make some live loops)
An API exists: http://www.jackaudio.org/api/
Bravo for this project that definitely rocks ;-)
Hi, I'm using original soundcard with RPi 3 model B.
I have a huge ~150 ms latency, is it something expected with Samplerbox and my modest configuration?
Or is there something wrong on my side?
Thanks a lot
Hello,
I was trying to add a volume control from a fader on my piano. Looking at your code, I'm trying to set the globalvolume variable with this peace of code (that I placed in the "audio and midi callbacks" section) :
elif (messagetype == 11) and (note == 7): # Ctrl change
vol = velocity * 0.3545 - 48
globalvolume = 10 ** ( vol / 20)
print vol
Unfortunately, I can see that my fader acts but nothing changes on the audio volume.
Could you guide me in handling this ?
Thank you !
Cuki posted Jan 18, 22:02:
I confirm what was also observed by r.meurer (posted Nov 17, 16:53:) and jpg (posted Jan 8, 23:04:) on the samplerbox forum
I could make serial MIDI work with samplerbox_20150618.img on RPI 2B
I could NOT make serial MIDI work with samplerbox_20161228.img on RPI 2B or RPI 3
Using USB-Midi interface and Akai LPK25 works with samplerbox_20161228.img on RPI 2B and RPI 3.
note: RPI 3 problem is probably due to the fact that bluetooth takes the full serial port that was available in RPI2. For RPI2 problem I have no explanation.
Hey y'all,
I'm having some trouble getting SamplerBox to work on my Raspberry Pi 3, running Raspbian. I am using an Arturia MiniLab Mk II, connected to the Pi via USB. I did not build the circuit or the enclosure - I am just trying to use the software for the time being.
I followed the instructions from the README under the Install section by pasting each line into the terminal on my Pi.
After the line sudo pip install rtmidi-python pyaudio cffi sounddevice
, a couple .tar.gz files were successfully downloaded, but then it said "collecting cffi" and then in red listed lines and lines of exceptions. At the end of that output, it says, again in red TypeError: unsupported operand type(s) for -=: 'Retry' and 'int
The next command seemed to go successfully.
After entering python samplerbox.py
, I receive this output:
Traceback (most recent call last): File "samplerbox.py", line 35, in <module> import sounddevice ImportError: No module named sounddevice
I'm not sure if I followed the instructions incorrectly, or what the problem might be. I'm a total newbie to Raspberry Pi and the Linux ecosystem, so I wouldn't be surprised if I made a mistake that would be obvious to folks with more experience. Any help is greatly appreciated!
Thanks for making awesome software!
Hi,
As I was strugling to add sample marker to my wave files, and I don't want to buy sound forge only for this I wrote this little code to add sample marker to a wave file.
It's very basic but it can be useful.
I'm new to github so I don't know if I should pull it or something so here is the code :
`######## ---- samplemarker.py ----
######## THIS IS A SUPER BASIC CODE TO ADD SAMPLER MARKERS
######## TO ADD LOOP TO WAVE FILES THAT YOU WOULD LIKE TO USE
######## WITH SAMPLERS LIKE SAMPLERBOX
import struct
import binascii
print "welcome here buddy"
print "##################"
print "so you want to add sampler markers to a wave file ?"
print ""
print ""
my_file = raw_input("What's the name of your file ?")
print my_file
with open(my_file, 'rb+') as f:
#for i in range (4, 7) :
f.seek(4)
data = f.read(4)
data = struct.unpack("<L",data)
data = int(data[0])
print "Your file : "+my_file
print "File size : "+str(data)+" bytes"
print " "
start_loop = input("First sample of the loop ? ")
end_loop = input("Last sample of the loop ? ")
sure = raw_input("Are you really sure that you want to proceed (y/n) ? ")
if sure == "n":
print "abord mission ..."
quit()
else:
print "proceeding ..."
data = data+68 #ajoute 68 bytes au fichier
#print data
data = struct.pack("<L",data)
#print data
f.seek(4)
f.write(data)
f.close
with open(my_file, 'a+') as f:
smplmarker = '736D706C3C0000000000000000000000000000003C00000000000000000000000000000001000000000000000000000000000000'
smplmarker = binascii.unhexlify(smplmarker)
#print smplmarker
f.write(smplmarker)
start_loop = struct.pack("<L",start_loop)
f.write(start_loop)
end_loop = struct.pack("<L",end_loop)
f.write(end_loop)
endmarker = '0000000000000300'
endmarker = binascii.unhexlify(endmarker)
f.write(endmarker)
f.close
print 'Done !!!'
`
In documentation and discussion it is made clear that one should not expect good audio quality without a sound card. This is obvious as soon as you try to play ~4-6 notes at once, you get the clicking static. With a sound card the clicking static happens, but it doesn't show up until you are repeating 8 note chords with sustain pedal. Is this as good as it gets?
Occasionally, usually when pressing way too many keys on the keyboard, I run into the following error which makes it impossible to recover. Sometimes restarting the python app helps, sometimes I need to reboot the PI. I don't know whether anything can actually be done from within the SamplerBox project though, esp. because I haven't yet found a fully reliable way to reproduce the problem.
Expression 'alsa_snd_pcm_start( stream->playback.pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2925
Expression 'AlsaStart( stream, 0 )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 3246
Expression 'AlsaRestart( self )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 3313
Expression 'PaAlsaStream_HandleXrun( self )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 4182
Expression 'PaAlsaStream_SetUpBuffers( stream, &framesGot, &xrun )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 4355
See https://www.samplerbox.org/article/midiinwithrpi point 3.
Needs to be double-checked if it still works nowadays, with new kernels.
There are 3 places to check:
Line 387 in ea16c5f
Then we have to connect a real hardware synthesizer (e.g. Roland or Yamaha), and see if it still works.
Some experience:
-sometimes I cant remounted r/w the file system (when I modified files on sd card, with an other pc) : mount -o remount,rw / mount -> can't find / in /etc/fstab
solution:
mount /dev/mmcblk0p1 /boot
mount -o remount,rw /dev/mmcblk0p2 /
Solution:
touch /etc/asound.conf
and write into 2 lines:
defaults.pcm.card 1
defaults.ctl.card 1
(and into samplerbox.py: AUDIO_DEVICE_ID = 2)
def MidiCallback..:
midinote = note + 12
in the open audio section (try-except): blocksize=0 (instead of 512, 128, 32 etc)
But there is still a lot of latency. I think 20-30 ms. Especially when I played piano preset. It has fast attack, and I feel the latency, and it disturb me a bit. Whit the slow attack preset (like slow string, chello etc) it isn't annoying.
Have someone ever try any real-time kernel, or very small and easy raspbian image for faster system? If you have any idea, please write. Thanks.
redtide/ConvertWithMoss enables conversion between a wide variety of sample libraries, my goal is to convert DecentSampler/PianoBook sample collections into a format compatible with SamplerBox. I tried just using the wav files provided with a decent sampler patch , but they seem to include a bunch of silence at the beginning so it seems that to be more widely compatible with sample sets, I would have to modify SamplerBox to be able to support a very large set of custom attributes per-patch such as sample-start-time, loop points, and a seemingly unending list of potential attributes that would quickly exhaust the constraints of extracting such data via filename.
So, I propose, instead that we expand the instructions in the FAQ for the SamplerBox's sample format, to make implicit assumptions more explicit. Does each sample presume the sample starts at the transient? How are loop points handled? What about envelopes? Should the samples be normalized to a specific db-range?
Can we get some clarification on sampler-box's requirements to make more sample libraries compatible?
remi posted Jun 9, 15:41:
http://www.samplerbox.org/forum/9
Windows version:
https://www.dropbox.com/s/2r2cetkqeg7qy8p/portableSamplerBox.rar?dl=0
Forum --> HansEhv posted Apr 10, 01:55
http://www.samplerbox.org/forum/137
Hi all,
Our band needed a one-time sample player with looping capabilities and I've used Joseph's great idea to build it.
Please feel free to use (parts of) this build for more nice things, but mind it's still in early stage of usage so there may still be some flaws in it.
You can find a description and source here
http://homspace.xs4all.nl/homspace/samplerbox/
The link to the 6€ DAC on eBay is broken.
Maybe a link to something more stable than eBay and a note telling the reader one can find them on eBay for ~6€.
Hi Joseph,
SamplerBox is a wonderful creation. Thank you for making and sharing!
I think that samplerbox_20170710 fails to boot in my 2019 Rpi because (I'm guessing) it's built on an OS that is now incompatible with the latest Raspberry Pi (which has some hardware change).
Please can you rebuild the load-and-go download using the latest OS? I'm sure that there will be many people who will be very grateful and it's a shame for this excellent project to not have a much longer life.
Thanks!
John
Is new raspberry PI supported? Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.