Poor man's sampler
What is it good for?
When you play live with a band, sometimes you need to play some audio samples in between of the performance. This could be for example intro, outro and interludes. This can theoretically be done by a sound engineer at the mixer, but often those guys do not know anything about you music, so end up having to play the samples by yourself.Samples can for example be played using a footswitch, so devices like the Digitech JamMan (https://digitech.com/en/products/jamman) come in handy.
If you happen to own a raspberry pi (no matter how old) and like some tinkering, you might be happy with my cheaper solution.
I used a peavey multi-purpose 2-button footswitch (https://peavey.com/products/index.cfm/item/870/118574), which i had laying around. It is important not to use the version with LED's as the circuit becomes more complex with it.
Raspberry Pi with footswitch connected |
How to build?
The idea of the sampler is to read in footswitch signals and play *.wav files in the raspberry pi. For this the GPIO's of the Raspberry Pi are used, which are accessible via the GPIO pin header (see for example https://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/#prettyPhoto). The GPIO's are configured as inputs with an activated pull-up resistor, so to enable a sound, the corresponding GPIO just needs to be connected to ground (GND).Attachement of phone jack to GPIO's and GND |
Python script
For the software side i implemented the following script, which is easily extensible for more inputs and corresponding *.wav files:
import pygame.mixer
from time import sleep
import RPi.GPIO as GPIO
from sys import exit
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
pygame.mixer.init(48000, -16, 1, 1024)
soundChannel = pygame.mixer.Channel(2)
ios = [23,24]
sounds = [pygame.mixer.Sound("1.wav"), pygame.mixer.Sound("2.wav")]
assert len(ios) == len(sounds)
playing = [False] * len(ios)
print "Soundboard Ready."
while True:
for idx, io in enumerate(ios):
if GPIO.input(io):
if not any(playing):
soundChannel.play(sounds[idx])
playing[idx] = True
else:
if playing[idx]:
soundChannel.fadeout(500)
playing[idx] = False
sleep(.01)
This code looks for low levels on the IO's every .01 seconds. If it finds a low level and no sound is yet played, the according sound playback is started. If a currently playing sound's according GPIO goes back to a high level, the playback is stopped.For extending the script, you need to
- add a GPIO setup for the according Pin as this:
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
- extend the array
ios = [23,24]
by the Pin number(s) - extend the array
sounds = [pygame.mixer.Sound("1.wav"),...
by the new sound files
Dependencies
I assume you have installed some kind of raspbian (use something up-to-date and minimal for fast boot). You will have to install python2.7 and the deb package python-pygame for playback of sound.
Access rights
Debian might not be happy with the user access rights, so you will only be able to execute the script as root (sudo). You might have to add your user to the according group (most likely gpio) with something like:sudo useradd -G gpio username
Startup automatically
To start the script automatically, you need to add a cronjob with the following command:crontab -e
Add a new job at the bottom like this:@reboot cd /home/pi/samples && python sampler.py
Kommentare
Kommentar veröffentlichen