Januar 2020 archive

Samplerbox Hardware with Raspberry PI

The Project Samplerbox is still activ. (2020-01-26)
I used the image and instruction from http://homspace.xs4all.nl/homspace/samplerbox/index.html

I have tried to use earlier versions in last years but it does not work as expected with my older Raspi 1.
I bought a Raspberry 3+  to test samplerbox with it. For now it works fine with the last image from Hans!

Samplerbox-rearside,
3 Buttons, 1 LCD, 4 USB-Ports, the ethernet-Port is hidden in the case.
Side-View, with Left Audio Out, Right Audio-Out, MIDI

Bill of material to build a Samplerbox:

  • Raspberry Pi 3+ ( perhaps newer works too)
  • Powersupply, 5V, 2.5 Amps or more
  • SD-Card
  • generic USB-Sound-Card – or DAC-Board PCM5102
  • USB-Stick to store Samples
  • Case for the Raspberry Pi
  • Optional:
    • MIDI-Board (DIN-Socket, 1x10k, 1x1k, 1x 220Ohm Resistor, 6N138 Optocoupler, 1 Diode)
    • USB-MIDI-Keyboard or MIDI-Keyboard with DIN-MIDI if the MIDI-Board is build
    • LCD Display 16×2 HD44780 (16 Pins)
    • 3 Buttons
    • Status-LEDs: 2 LEDs & 220Ohm Resistor

I didn´t buy a lot because I had already most things in stock. I used “Guttagliss” – Hobbycolor plates to build a case and painted it with spray paint. Hobbycolor looks like plastic but is some more flexible and very easy to cut with a knife, could be glued, bend with the heatgun and painted. In the top of the case, I have cutted the holes for the LCD and the 3 Buttons. Finally I used a transparent acrylic-plate to cover to top. Finally, inside the case I used some layers of Hobbycolor-pieces to create some support structures to be able to fix the different circuit with woodscrews.

I created 3 circuit, first circuit to connect to all GPIO-Pins of the Raspberry PI and provides space for the PCM5102-Board.

Second a Circuit to hold the 3 Buttons and which has the width of the LCD. Both, button-board and LCD is mounted with four 3mm Screws and some layers of nuts to get the right distance to the top of the holes in the case.

Third circuit, and the last, is the MIDI-Converter, which transforms classical MIDI into 3.3Volts serial data. This board is the smallest and I have used a small circuit-board which is too small in my case because it has to be mounted very well and fixed with the case. The big DIN-Plug causes some force and this has to be managed with screws between DIN-Plug and the case.

If you would only test the software, the minimum would be Raspberry PI, a USB-Sound-Device which is compliant as Sounddevice for Linux and a USB-Keyboard. There is already one sound on the SD-Image.

My Result, – the view inside with the Circuits ( the MIDI-Circuit was added later)

, the background is the inside the case and is the backside of the top plate. The green Circuit is the LCD-Board. The board at the bottom is the board for the buttons.
The upper board connects to the Raspberry Pi and on its backside, there is the PCM5102-DAC and all the wired. The upper Breadboard is fixed by 4 screws. The 2 jacks on the right-side are the Audio-Output 1/4 inch, 6.3mm – jacks.

Backpanel of the case with some features for aircondition. The white and black stripes at the corner are “inside” and are used to fix the screws from the side.

Wiring of the PCM-, LCD- and MIDI-Board with the Raspberry-Pi-GPIOs

The wiring through the Audio-Jacks is made with plastic jacks which connect the tip- and ring-contact to an outpoing pin if no plug is inserted in the jacks. That way, the upper jack is stereo if nothing is connected to the right-side-jack. The right-side-jack is a mono-jack, the left-side-jack is a stereo jack.

The MIDI-Circuit was tested with an LED, because I had to order the 6N138 and wanted to avoid any mistake.

Test MIDI-Circuit with LED first

Finally after testing, I was able to connect all cables.
Powersupply, Audio, MIDI-Keyboard, USB-Stick with samples, USB-Keyboard,

How does it sound? – exactly as the samples are. On the USB-Stick, for every instrument or “patch”, you need a folder which starts with a number.
Inside each folder, you have to store all needed samples for the patch and a definition.txt which declares the structure, placing of the samples etc.

The wave-files could contain Loop-Points to be able to play an area of the sample in a loop as long as you presses the key on the keyboard.
For short samples – or most string- or drum-instruments, it sounds more realistic to use a long sounding sample which simple fades out. After releasing the key, samplerbox will release these samples in a few milliseconds which mostly sounds natural.

The content of a definition.txt looks a bit like “code” but is very “simple” to declare for “simple” instruments. Lets view the “code”.
To avaid load distorsion, I lower the gain for this instrument to 80% – 0.8.
%%velmode=accurate is more or less a standard which has to be defined.
The last line of my definition is something like a Regular Expression but much more easier. * covers all content in flexible length. %notename has to be something like C4, c4 or c#4 or C#4 but NOT Gb3 or G.
By default, the notation could be used as the notenames but only normal notes or sharp notes. As an alternative, “%notenumber” could be used which is simply the MIDI-Notenumber, C4=60. %velocity could be used to provide a %velocity-Number to define WAV-Files when keys are hitted faster/stronger for loader notes and other WAV-Files for quite notes.
There are a lot more options available for the definition.txt which are described well in the internet.

%%gain=0.8
%%velmode=accurate
* %notename %velocity.wav

The definitions are made mostly for key-ranges without a specified border of the range. If you would like to define something for a specific key, that could be done with specific variables in the code:
kick.wav, %midinote=36

The Options per Sound are:
%notename
%midinote
%velocity

More Details are documented here, but this documents don´t cover the version from HANS by 100%!!
samplerbox.readthedocs.io/en/latest/Sample_Sets/

The Software-Image from Hans covers special files on the SD-Card! – /boot/config.txt and /boot/samplerbox/configuration.txt and some more…
These files provide the ability to define the used GPIO-Ports and are used to enabled the Serial-MIDI-Port. ( BT would be moved to miniuart to make the real UART available for the MIDI-Port via midi-uart0)
(The configuration-files are readable on the SD-Card on MAC and probably windows.)

Raspi3+ in config.txt I changed this:

enable_uart=1
dtoverlay=pi3-miniuart-bt
dtoverlay=midi-uart0

and removed from config.txt
init_uart_clock=2441406,
init_uart_baud=38400 in config.txt and

and remove this in cmdline.txt
bcm2708.uart_clock=3000000

MIDI-Controllers could be used to control all the effects or the select the patches. I am using an older Novation Launchkey MINI MK2 which does not provide Program-Change command. Therefore, I used the Controller-Configuration from HANS to remap 2 buttons on the launchkey to do so and a POT on the Launchkey to control the volume. All Configuration-Files are described here: http://homspace.xs4all.nl/homspace/samplerbox/SBconfig.html

What could You do better than I did?
– Try to push all connections to only 2 sides of the case. I have created connections on the left side for audio and MIDI and the Power-Plug is on the right side and USB-Ports on the top . That way, the Samplerbox takes too much place on my desk.
– create a stiffer case and a bigger circuit-board for the MIDI-Port. A MIDI-Port, shaking loosely inside the case wouldn´t be “pro”,
– Try to use the OLED-SPI-Display-Option, – my 16×2 LCD does not work well and shows agyptian characters when the Raspberry Pi is cold. My LCD is specified for 5 Volts but the data-pins of the Raspi provide 3.3Volts, this could be the problem. – but sometimes it works!?
– Don´t use litz-wires for the connection between the circuits. I had to rethink and rebuild the circuits and the case and had many issues with wires which created shorts or were simply disconnected.
– Test Your setup on a breadboard first
– Connect the LCD only with Data-Pins Data4-Data7, – the 8Bit-Mode is not supported by the version from HANS.

What I would do with the samplerbox?
I already own a Akai MPC2500, – which plays drumsounds well but not keyboard-sounds mapped to a keyboard. I own a Novation-Circuit too which has limited polyphony and I am thinking about to create 2 small samplerboxes to extend the MPC and the Circuit.
I already sampled a few instruments by using the MPC 2.0 Software (version 2.6 with the autosampler) and created samples of my mandolins and mandola by using garageband as the “recorder”.
I would like to use the Samplerbox as a small expander with Samples which I recorded or to provide drum-loops.
A further step would be a Arduino as a MIDI-Merger and Sequencer between the MIDI-Board and the Samplerbox. A Arduino-Nano or ESP32 could do that perhaps.

Things, which are not that good:
The documentation is not covering all different versions of Samplerbox. The Effectsettings are global and are not saved in the definition.txt for a single patch. But to be fair, all these effects are a great step forward for samplerbox.
The forum(s) is not splittet into different subjects. Most forum-posts are asking for help or saying that the sound is crappy – they only need the hint to lower the gain in definition.txt. That way, samplerbox-users are not in a real discussion in the forum.

PHP mit Curl Export File

Es gibt manchmal das Problem, dass keine direkte Verarbeitung, sondern ein Loggen des Ergebnis von CURL gewünscht ist. Dazu muss man nicht erst eine Verarbeitung des Returnvalues durch PHP starten.

Ausschnitt aus PHP:

$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $out);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $file);

Samplerbox basierend auf Raspberry PI – 2020 lohnt sich das noch?

Samplerbox hatte ich schon mit dem Raspberry-PI, gefühlt 2010 getestet. Es war sicher 2 oder 3 Jahre später aber der Sampleplayer basierend auf Raspberry 2 lief eher mit Fehlern und die Klangqualität ware eher sehr bescheiden.

Samplerbox ist eine Software – oder besser schon “Betriebssystem”, das man als Boot-Image auf eine SD-Karte kopiert und dann diese in den Raspberry-Pi steckt.
In die USB-Ports des Raspberry-PI steckt man noch ein USB-MIDI-Keyboard, eine USB-Soundcard und einen USB-Stick mit Sounds. Nach dem Booten kann man dann die Sounds, die auf dem USB-Stick gespeichert sind auf dem MIDI-KEyboard abspielen.

Technisch war Samplerbox als einfacher mobiler Keyboard-Expander angesetzt. Dank gut gesampelter Piano-Sounds scheint das Projekt aber nun eher bei Usern zum Upgrade von Homepianos eingesetzt zu werden.

Im Vergleich zu einem vollwertigen Sampler, – so wie es sie früher in den 90ern mal gab, fehlen der Samplerbox viele Funktionen:

  • Samplen kann man damit nicht, nur Sounds wiedergeben
  • Es gibt keine ADSR-Hüllkurve, sondern nur eine Releasetime
  • 16Bit, und somit kann es bei vollem “Gain” zu Verzerrungen kommen
  • Kein integrierter Sample-Editor

Auf der Plusseite haben wir aber 2020 mit der Version von Hans ( http://homspace.xs4all.nl/homspace/samplerbox/SBbuild.html ) nun eine stabile Version, die auch schon eine größere Liste von Effekten kennt: Lowpass, Freeverb, Delay, WahWah.
Die Version von Hans läuft auch nach Stunden und wildem Wechsel des USB-Sticks noch stabil!

Die Version von Hans unterstützt auch ein einfaches optionales GUI, mit 2 Buttons, einem Display (16x2LCD oder SPI-OLED), DIN-Midi und 2 LEDs.

Ich habe mir eine einfache PCM5180-Platine bei Amazon bestellt und diese als Hifiberry-Soundcard installiert, ein LCD-Display und 2 Buttons verbaut. Da ich noch keinen 3D-Drucker habe, habe ich ein Gehäuse aus Guttagliss PHoobycolor – Platten gebaut. .. das ging auch in wenigen Minuten.

Anders als angegeben müssen nur die Datenleitungen D4 bis D7 des LCDs mit GPIO-Pins verbunden werden. Die final ausgewählte Belegung wird in einer Configdatei (configuration.txt) auf der SD-Card definiert. Somit können auch vorhandene LCDs und Hifiberry weiter verwendet werden.

Sounds habe ich mit der Akai MPC erstellt und dann auf den USB-Stick rüber kopiert und somit stehen diese nun mit einer Polyphonie von 80 Sounds zur Verfügung.

Spaß machen die A-Piano und E-Piano-Sounds, bei denen man keine besonderen ADSR-Hüllkurven erwartet. Synth-Sounds klingen sehr statisch, denn hier erwartet man eben Sounds, die genau nochmal eine Veränderung zeigen, wenn man länger drückt, fester drückt (Aftertouch) oder los lässt.

Für alle, die einen einfachen MIDI-Expander, – Sampleplayer für Keyboard-Sounds, Drum-Sounds oder Loops suchen und schon einen Raspberry-Pi ab Modell 3 haben, sollten Samplerbox nochmal testen.

Ich werde meinen Raspberry PI noch mit einem DIN-MIDI-Port ausstatten und einen Arduino als Sequencer hinzufügen und zu meinem kleinen Volca-Beat synchronisieren.

Links:

http://homspace.xs4all.nl/homspace/samplerbox/SBbuild.html

Script to sample down the sounds of a SF2-File
https://github.com/adrianhoehne/Sf2_Batch_Recording/blob/master/Sf2_Batch_Recording

Trick zur Sample-Convertierung:
Unter MacOSX gibt e snatürlich viele Tools um vorhandene Sounds in einem Verzeichnis auf die richtige Sample-Frequenz und die richtige Bitgröße zu bringen. Mit dem Tool “SOX” geht das auch in der CLI/Bash:
for file in *.wav; do ./sox “$file” -r 44100 -b 16 44100/”$file” -V; done

Erweiterung zum Samplen gibt es lieder noch nicht fertig. Aber es gibt ein Script, welches die Basics zum Samplen abdeckt: https://www.samplerbox.org/forum/444

import RPi.GPIO as gpio 
from recorder import Recorder 
gpio.setmode(gpio.BCM)  

class ButtonRecorder(object): 
    def __init__(self, filename): 
        self.filename = filename 
        gpio.setup(23, gpio.IN, pull_up_down=gpio.PUD_UP) 
        self.rec = Recorder(channels=2) 

    def start(self): 
        gpio.add_event_detect(23, gpio.FALLING, callback=self.falling, bouncetime=10) 

    def rising(self, channel): 
        gpio.remove_event_detect(23) 
        print 'Button up' 
        gpio.add_event_detect(23, gpio.FALLING, callback=self.falling, bouncetime=10) 
        self.recfile.stop_recording() 
        self.recfile.close() 

    def falling(self, channel): 
        gpio.remove_event_detect(23) 
        print 'Button down' 
        gpio.add_event_detect(23, gpio.RISING, callback=self.rising, bouncetime=10) 
        self.recfile = self.rec.open(self.filename, 'wb')    
        self.recfile.start_recording() 

rec = ButtonRecorder('36.wav')
rec.start() 

try: 
    raw_input() 

except KeyboardInterrupt: 
    pass 

gpio.cleanup()