I'm interested in creating a synthesizer barely similar to the Korg Volca Keys. Since I have limited knowledge of analog electronics, I'm thinking of starting with something simple using the Arduino Due. Specifically, I'd like to:
Develop a digital sawtooth oscillator with a frequency range from 20Hz to around 20kHz.
Implement true MIDI hardware communication to play notes with my MIDI keyboard (Arturia Keystep 32).
Digitally implement an ADSR (Attack Decay Sustain Release).
Digitally implement a low-pass filter (digital implementation due to the next point).
Digitally implement an ASDR on the filter.
Make all sounds come out from the DAC to a headphone jack.
I plan to control all parameters with separate potentiometers, utilizing all 12 analog inputs.
Is the Arduino Due the right choice for this project, or should I consider another board? Additionally, considering that I am more of a programmer than an electronics expert, is this path relatively simple?
Hi, @wootrop.
This project does not seem easy to me. It's strange that even though it's easy for you, you run into problems right from the start. According to the datasheet, the Arduino Due has a pretty fast DAC.
I think it will need a faster CPU. Ideally an FPGA.
Either way, I think you will need to go beyond the Arduino API and program CPU features directly. The example in the tutorial isn't useful apart from demonstrating the limitations.
I made a quick frequency generator for a project at work using a Due. I just needed 2 or 3 sine waves with different frequencies, none of the expensive test kit we had could do that. I only needed low frequencies known at compile time, which made it very doable.
One method as follows:
Create a wave table in RAM for each channel
Set a timer interrupt for a particular sample rate
In the interrupt, get the value for each channel and sum them
Write the DAC register with the summed value
If the max freq is 20kHz and you had 128 samples per cycle then the required interrupt rate is 2.56 Mhz, or about 30 instruction cycles per interrupt, which is really on the limit of what the Due could handle. If the max freq was 10kHz, that would be more manageable.
There may be a way to use DMA to offload some of the data transfer.
To handle the analog inputs, I would set up the ADC to do conversions automatically. Handling of the UI I would do in a background loop, which would also re-calculate the wave tables.
So probably steps 1 to 3 would be doable but only with limitations. Adding a low pass filter adds more CPU load, which is where you might struggle.
Anyway, I would develop a proof of concept with Due and see how much CPU time it requires.
I had already heard about the Teensy microcontroller, but what held me back a bit was the fact that the Teensy 4 doesn't have an integrated DAC on board. I would have had to order the audio shield as well, with parts to solder... (I don't have a soldering iron, and I'm not skilled at soldering). Besides, being in Italy, I would have had to order these two things from the United States. So, I opted for the Arduino DUE, also considering some small past experiences with the Arduino UNO.
As for Mozzi library, it seems like an excellent point to start with, but on the website, it doesn't appear to natively support Arduino DUE. I have also tried running some examples but it doesn't work...
However, I may have found a good starting point:
Do you have any other boards to recommend that are easy to use and perhaps designed specifically for audio hardware development?
In the meantime, I will try to do some more research and experiments with Arduino DUE.
Thank you very much!
Thanks @Grumpy_Mike for the source codes. I gave them a quick look, but I have a general doubt...
How can I obtain any audio waveform that has a 0 voltage offset at the output? In other words, how can I obtain any audio waveform that swings equally in the positive and negative directions?
I read on the internet that using PWM, I can control a device that produces analog voltages, even in the negative range. Would it be suitable for audio as well? At this point, the use of DAC seems to be unnecessary, and the choice of Arduino Due might be superficial. I'm a bit confused...
You have to do this in hardware, as you will struggle to get an D/A that handles negative voltages. This is very easy to do. Just two resistors and a capacitor. For a Due the top resistor would be to the 3V3 pin not the 5V one.
No.
PWM can only produce values from 0 to Vcc. Where Vcc is the voltage of the processor driving the pin. However, you simply use the above circuit with a PWM generated output signal.
So either the D/A or PWM can be used to provide the output you need.
Note like a lot of pins on the Due, DAC outputs can handle very little in terms of output current and is very easily damaged. This is 3mA source and 6mA sink current.