Would Arduino be fast enough to analogRead 44KHz 4 audio channels, do simple math operations with these (subtracting, multiplying, absolute value, isEqual) and do analogWrite to give out resulting audio also at 44KHz?
Yes, with an Arduino DUE.
ard_newbie:
Yes, with an Arduino DUE.
You sure of that. In order to read four channels at 44KHz each channel would have to be read at four times this, that is a rate of faster than 176 KHz, I don’t think it will go that fast. Note also that the Due’s D/A converter will not cover the full range of voltage outputs and is only 10 bits anyway. The A/D resolution on the Due is up to 12 bits, but seeing as the resolution on the output is only 10 bits and you have four channels you are only going to be able to cope with 8 bits resolution per channel.
The OP did not say what bit depth he wanted.
This is the sort of thing where you need a high end Teensy running two I2S devices. Mind you using isEqual, or the C equivalent == on a digital audio signal is not going to do much for you.
Thanks. I was hoping for 16bit audio, but maybe music at 10bit would not be too bad. I am not sure what to expect yet but now that you mentioned == not being very useful I have realized my error in thinking.
Regarding reading speed, in the meantime I have found this thread where there were talks of 1M reads per second so then it seems to be possible to read 4 channels at 44KHz.
By the way, I expected that 84MHz means 84 million instructions per clock cycle and that in a tight loop a sequence of Read Ch1, Read Ch2, subtract, Write would take only 4 instructions.
There are several steps to optimize ADC readings and accuracy. Either for accuracy improvement and speed, you will find hints or example sketches in the DUE sub forum.
Moreover oversampling 4 times the 4 ADC channels (still under 1 Msps) and averaging should improve ADC readings accuracy. DMA is the best approach to fill a buffer with ADC conversions while another one is processed.
Regarding reading speed, in the meantime I have found this thread where there were talks of 1M reads per second so then it seems to be possible to read 4 channels at 44KHz.
The 1M reads is a bit of a marketing thing, it referrers to the incremental speed. It is not what you get when you call an analogRead call. From my tests I got a sample rate of 333 Ksps ( samples per second ) reading the same input, given you need 44 X 4 = 176 Ksps you might just be on here. I say might because it does not include the settling time when changing channels.
By the way, I expected that 84MHz means 84 million instructions per clock cycle and that in a tight loop a sequence of Read Ch1, Read Ch2, subtract, Write would take only 4 instructions.
Again a misunderstanding. These are machine code instructions NOT C instructions. For example a digitalWrite takes about 96 machine cycles to complete. Most function calls in C are written in C and need to be compiled into machine code, there is no easy way to find out how long a given C call will take.
I was hoping for 16bit audio, but maybe music at 10bit would not be too bad.
Yes but you will not get 10bits output you will get the equivalent of 8 bits per channel. Take a simple case where you have four channels and are adding them all up. If you are restricted to 10 bits output then each individual channel can only be treated as an 8 bit signal to keep the sum below the 10 bits dynamic range of the output.
Grumpy_Mike:
If you are restricted to 10 bits output then each individual channel can only be treated as an 8 bit signal to keep the sum below the 10 bits dynamic range of the output.
That assumes all channels are at full volume simultaneously - often this isn't the case so you may get more
bits equivalent.
But these days sampling audio is simplest done with I2S, and ADCs are 16 or 24 bit typically, so no issue.
I've recently been using a Teensy with its Audio shield and this is a very powerful device (especially the latest
Teensy 4's).
Without an I2S ADC/DAC you'll have the issue of having to do precisely timed conversions as any jitter
in an audio ADC/DAC is very audible as spurious tones. I2S devices handle this for you.
That assumes all channels are at full volume simultaneously - often this isn't
If you are mixing them you have to assume that in order to grantee you get no clipping on the output. If you want to allow for the possibility of clipping then yes go ahead and add together numbers that could cause an overflow.
Thank you all! This information is still encouraging so I'll get the hardware and try it out.
OK just a warning, the analog output pin on a Due is a bit delicate. It can only source 3mA and sink 6mA. Many people, including me, have blown up DAC0 by putting even a modest overload on it. They often take to connecting a series resistor to the pin to limit the current output. Remember it is not just the resistance of the circuit attached to the pin that can be the problem, if it has to charge up a capacitor the current rush could exceed the maximum source current.
https://forum.arduino.cc/index.php/topic,139733.0.html
https://forum.arduino.cc/index.php?topic=227338.0
Also as I said before the range of the DAC pins is limited:-
https://forum.arduino.cc/index.php?topic=427593.0