II.3.1. Writing Simplest Effect Processor
The simplest effect processor is an input-output device without any control. When the device is powered, it would simply work to process the input signal and deliver the processed signal to the output. Here is the steps to write such simple effect processor:
- Include the library header <blackstomp.h>
- Define an effect module derived from effectModule class with process() and init() methods.
- Setup the pedal name and the input-output configuration inside the init() method.
- Implement the processing codes inside the process() method.
- Call the blackstompSetup() inside Arduino’s setup() function.
Let’s try to write a “Gain Doubler” pedal as an example of the simplest Blackstomp sketch. It would simply boost the signal from the stereo input by multiplying the signal of left and right channel by factor of 2.0 and deliver to the stereo output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
#include <blackstomp.h> //effect module class definition class gainDoubler:public effectModule { public: void init(); void deInit(); void process(float* inLeft, float* inRight, float* outLeft, float* outRight, int sampleCount); }; //effect module class implementation void gainDoubler::init() { //select the appropriate device by uncommenting one of the following two lines: //setDeviceType(DT_ESP32_A1S_AC101); setDeviceType(DT_ESP32_A1S_ES8388); //define your effect name name = "GAIN DOUBLER"; //define the input mode (IM_LR or IM_LMIC) inputMode = IM_LR; } void gainDoubler::deInit() { //do all the necessary deinitialization here } void gainDoubler::process(float* inLeft, float* inRight, float* outLeft, float* outRight, int sampleCount) { for(int i=0;i<sampleCount;i++) { outLeft[i] = 2 * inLeft[i]; outRight[i] = 2 * inRight[i]; } } //Arduino core setup //declare an instance of your effect module gainDoubler myPedal; void setup() { blackstompSetup(&myPedal); //run system monitor at 38400 baud rat, at 2000 ms update period //don't call this function when MIDI is implemented //try lowering the baudrate if audible noise is introduced on some boards runSystemMonitor(38400, 2000); } //Arduino core loop //let the main loop empty to dedicate the core 1 for the main audio task void loop() { } |
The signal processing algorithm is what we code inside the process() function (line #27). You can see that the processing formula of this “Gain Doubler” pedal is just a simple multiplication by 2 (line #31 and #32).
The function blackstompSetup is called inside the Arduino’s setup function at line #41. Because the serial port is free (not used for MIDI) then we can call the function runSystemMonitor() after blackstompSetup() at line #46 to produce periodic report by sending some texts to the serial port, which can monitored with “serial monitor” tool of the Arduino IDE.