How can i get audio samples from Analog Input

how can i get audio samples from Analog Input and get negative peak and positive peak like audacity something like this

real time thanks for your time

You connect it through a capacitor to the input, and then put two 100K resistors on the input and connect the other end of one to ground and the other to 5V or 3V3 depending on if you have a 5V or 3V3 working Arduino.

This is called mid point biasing and readings will go either side of 512. The bigger the amplitude the more the readings deviate from this value.

1 Like

Excuse me, I want to write a program to convert analog data to audio samples, and I do not know where to start.
i use Max4466 Microphone preamplifier

Follow Grumpy_Mike's suggestion realizing you will have to use one of the A/D inputs (A0 - A7) and sample for each point, it does not do a continuous read. If you want reasonable or music quality you need a codec, they are designed to do what you want.

But an Arduino Uno is not fast enough to drive a codec.

And what do you want to do with these samples?

I want to make an almost quality sound recorder

Can i do this with Arduino UNO R3 ?

No, its ADC is too slow and has a low resolution. It doesn't have DMA either, so it will struggle moving the large amount of data around between the input and e.g. an SD card.

Unless this is a project to learn programming and electronics, it's a much better idea to buy an off-the-shelf audio recorder.

Hi, @macanrezaiiii
Welcome to the forum.

Can you please tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

I have been programming for 5 years with C,C++,C#,python,javascript
and I have been using arduino for 6 months

thanks for your time and STM32 is a good option for that?

It supports I²S and DMA, so it could be used. You can find application notes like this one:
It uses a MEMS microphone, but you could an I²S ADC instead.

You could also use a Teensy, its Audio library is much more beginner friendly.

Excuse me, I can use this STM32F103 microcontroller?

If you look at the datasheet, you'll see that it supports I²S using DMA. It'll depend where you want to store the recording to.

Conceptually it's pretty simple. The Audacity website has a little introduction to digital audio.

I've made a few audio activated lighting effects. My World's Simplest Audio Effect might give you some ideas, It reads the audio data in a fast-loop* and saves the peaks (ignoring most of the readings).

There is also a schematic for the bias circuit.

Of course you have to record and play-back at the same sample rate and bit depth (or you have to convert & scale).

I've never used the STM32 but it's probably a better choice. The 10-bit Arduino ADC is not a standard audio bit depth so that would normally be scaled up to 16-bits or down to 8-bits. Plus, the Uno doesn't have a DAC and it doesn't have enough built-in memory for an audio recorder (44,100 samples per second, etc.).

Normally the bias should be subtracted-out, but if your DAC doesn't go negative it will have to be biased again, and then the DC can be filtered-out with a capacitor. (8-bit WAV files use unsigned data so they are "biased", but that's only important if you're using WAV files.)

  • With the Uno looping "as fast as possible", it's not fast enough for digital audio. I believe it can loop faster if you write assembly code but according to the datasheet, the ADC will loose accuracy if you sample fast-enough for high-quality audio. (It's only 10-bits to begin with.)

I don't know what to do and where to start. ?
I need an audio recorder with 44100 Sample rate and Mono with Microcontroller
Can anyone guide me?

What is the best microcontroller for this?

What is your actual goal here? Is this a university assignment of some sorts?
If it's just a hobby project, start with the Teensy Audio library. If you want to learn how to do this yourself, read the application note I linked to and the chip's datasheet (especially the I²S and DMA sections).

In fact, I have a project that I have to process the sound in real time I did this project before with c#


and what?
What was the hardware?
Did it work then?

Thanks.. Tom... :smiley: :+1: :coffee: :australia: