Go Down

Topic: Real Time Audio Processing (Read 2866 times) previous topic - next topic

zkhan

Feb 22, 2019, 08:04 am Last Edit: Feb 22, 2019, 08:05 am by zkhan
Hello,

I had a question regarding real time audio processing. Im trying to create a project that takes in a 3.5 mm jack/ and or mic input to A0 coverts it through ADC and outputs it on the audrino pins of the DAC. I have already created a preamp that takes in a mic into A0 as well as a 3.5 jack.

Furthermore Ive created a R2R resistor ladder with a low pass filter, power amplifier, and output. I know the R2R ladder can be low quality. Ive inserted an image of my dac circuit below. As well can be seen in this link https://www.instructables.com/id/Arduino-Audio-Output/


However my question is there a way I can code to take the audio and output it to the R2R resistor ladder I am fairly new to this and any help is greatly appreciated. Thank you! (preferable register programming help rather than libraries)

Grumpy_Mike

Unless you use resistors that are matched to within 0.2% of each other than that circuit will cause all sorts of distortions in your already poor audio signal.
It is poor because you have a limited sample rate.
You will need to use the direct register addressing to write to them and you will need more than one access because you do not have a clear run of 8 bits free in any register used with an Arduino. This will cause additional glitches in your sample.

But your big problem is lack of memory for the processing code. Unless you can add some external memory what you could do will be limited.

PieterP

#2
Feb 22, 2019, 01:16 pm Last Edit: Feb 22, 2019, 06:52 pm by PieterP
The AVR microcontrollers used in Arduinos are not suited for audio processing.
They were simply not designed with audio in mind: they lack memory, processing power, ADC resolution and speed, and a DAC.

Use a microcontroller with more memory, I²S support, DMA, etc.
Take a look at ARM microcontrollers like STM32 if you have some experience, or use a Teensy if you want a more beginner-friendly platform.
You could probably also use an ESP32.

If you're interested in learning low-level DSP, the CMSIS-DSP library might be useful.

If you don't care about DSP at all, and you just want to get your audio project working, you can use the PJRC Audio library.

freedsp.cc is also worth a look.

Pieter

MarkT

You can't parallel opamps like in your circuit, if you want more current than one opamp can supply there is
a way to do it: https://e2e.ti.com/blogs_/archives/b/thesignal/archive/2013/03/26/paralleling-op-amps-is-it-possible

The resistor ladder needs most precision in the resistors closer to the output end, note.

With tight coding you can do this audio processing to some extent, you'll need to up the ADC clock speed a bit
I think, and restrict the processing to cheap operations.  An external SPI ADC can be a lot quicker to read
(compared to waiting for the on-chip ADC), freeing lots of processor cycles.

You can even do noise-shaping to increase the effective number of bits on the output for lower frequencies,
but you need a high sampling rate for this to be effective.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

ard_newbie

#4
Feb 22, 2019, 03:37 pm Last Edit: Feb 22, 2019, 03:37 pm by ard_newbie
This I2S library allows the Arduino DUE to interface with a large number of audio codecs and enables higher quality audio I/O than what is available with the standard on-chip ADC and DACs.


To make use of the on-chip ADC and DACs plus a real time digital filtering, there is this tutorial (google translate is your best friend).




Grumpy_Mike

The resistor ladder needs most precision in the resistors closer to the output end, note.
No, think about it. To achieve monotonicity all resistors have to be of the same precision.

Lucario448

However my question is there a way I can code to take the audio and output it to the R2R resistor ladder [...] (preferable register programming help rather than libraries)
Not sure why you want to an audio passthrough with an Arduino (besides a proof of concept maybe), but it's not that difficult:

Code: [Select]
void setup() {
  DDRD = 255; // The whole port as an output
  // ADC settings that speed it up and I don't remember the register name.
  TIMSK0 = 0; // Improves "sampling rate" a little more, but it's optional (since this disables delay and time functions)
}

void loop() {
  PORTD = analogRead(A0) >> 2;
}

Since this is a simple passthrough, precise timing of the sampling is not that important. It may go as fast as it can.

MarkT

No, think about it. To achieve monotonicity all resistors have to be of the same precision.
I did think about it, the resistor precisions are weighted by bit position, a 10% resistor for the LSB is
a smaller deviation than a 0.1% resistor in the MSB for an 8 bit ladder.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

zkhan

Thank you for all you helpful responses.  Any tutorial or simplest way I can accomplish this task. Tutorial maybe. Thank you.

Grumpy_Mike

I did think about it, the resistor precisions are weighted by bit position, a 10% resistor for the LSB is
a smaller deviation than a 0.1% resistor in the MSB for an 8 bit ladder.
No the contribution of the most significant bit must be as accurate as the least. Because 0111 1111 must be lower than 1000 0000

DVDdoug

#10
Feb 22, 2019, 08:00 pm Last Edit: Feb 22, 2019, 08:01 pm by DVDdoug
Quote
Thank you for all you helpful responses.  Any tutorial or simplest way I can accomplish this task. Tutorial maybe. Thank you.
What is "this task"?     You didn't say what quality/resolution you want and you didn't say what kind of audio processing you want to do.   

I think some people have made simple-limited guitar pedal effects...   But, the Arduino is not going to do anything high-fidelity or highly-complex.   (And DSP tends to be mathematically complex unless you're something simple like volume manipulation.)

You might want the MiniDSP or the Dayton DSP  ?

PieterP

Thank you for all you helpful responses.  Any tutorial or simplest way I can accomplish this task. Tutorial maybe. Thank you.
The simplest way is to put aside the Arduino and connect the output of the microphone preamp to the input of the speaker amplifier.

What do you really want to do?

I already posted a link to the Teensy Audio library, it's not going to get easier than that.

zkhan

#12
Feb 22, 2019, 08:44 pm Last Edit: Feb 22, 2019, 08:55 pm by zkhan
Sorry for bad english. Like there is no other way to create a program with the implementation above. (R2R ladder with A0 preamp).

For example using the ADC of the audrino and a DAC Tutorial to output an analog signal from A0


zkhan

#14
Feb 22, 2019, 11:32 pm Last Edit: Feb 23, 2019, 12:23 am by zkhan
I had a question, so I was able to implement the code below with the specification i said above. However the static noise is very loud. I already have a low pass filter as stated up in my specification. Anything i can do to reduce the static.



Code: [Select]

void setup() {
  //
  cli();
 
  //
  TCCR2A = 0x00;
  TCCR2B = 0x00;
  TCNT2 = 0x00;
  OCR2A = 249;
  TCCR2A |= (1 << WGM21);
  TCCR2B |= (1 << CS21);
  TIMSK2 |= (1 << OCIE2A);
 
  //
  sei();

}

ISR(TIMER2_COMPA_vect) {
  //
  analogWrite(10, map(analogRead(0), 0, 1023, 0, 255);
}

void loop() {
 
}

Go Up