-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Welcome to the Motivation-Radio-Drum-Machine wiki!
The Motivation Radio Drum machine sketch can be used as a drum machine or a general purpose sample player.
Samples: 16 bit PCM samples are compiled into the binary via header files. see /resources for the wav2header utility which will create the required header files from 16 bit PCM .wav files at 44 or 22khz.
A great source of samples are Soundfonts. Most of the included drum kits are from Soundfonts I found on the web. There are several utilities that can extract .wav files from a Soundfont. I use sf2wav http://sanfransys.com/main_downloads.htm
The heart of the app is the ISR that runs at 22khz. It loops through the sample table, adds up samples that are playing, scales them and sends them to DAC0 (leftmost). It also samples the CV inputs round robin i.e. one channel per interrupt. Soft SPI is used to drive the DAC and ADC. Expressif`s Arduino SPI libraries are very slow for short transfers and they cannot be used within an ISR. Soft SPI is much faster for this application. The ISR takes about 25uS which is more than 50% of the CPU - if you mod this code be careful not to add significant execution time here.
There is a second ISR running at 4khz which samples the Gate/Trigger inputs. Its much less time critical. This is where some of the fun stuff like changing sample playback based on CV inputs is done. Because the timing of the 22khz ISR and this one are asynchronous (i.e. there is timing skew) the gate inputs are sampled twice before a sample is triggered. This ensures that the CV input value is valid before we trigger the sample.
Bluetooth and Wifi are not implemented in this app because the ESP32 wireless libraries are huge - in most cases you will need the flash space for samples. Adding Bluetooth MIDI or AppleMIDI (MIDI over Wifi) is straightforward - cut and paste the code from the other Motivation Radio example sketches such as BLEMIDI.