Go Down

Topic: Simple microphone shield to generate WAV files? (Read 523 times) previous topic - next topic

scottjenson

I've read the forums and there are LOTS of examples of microphones but they tend to be fairly low level, requiring special hardware and often complex sampling software.

I'm hoping to find a shield that will do most of the work. Ultimately, I'd like to have a StartRecording() command and StopRecording() that returns a pointer to the audio. As I'm only recording a few seconds it can record to memory or an SD card. I just need access to the file on the SD card.

I've found a play/record shield that acts like a voice recorder but it appears to act as a stand alone peripheral. It can ONLY record and play and hides away the file.

I don't mind a little soldering but I'm trying to avoid writing a lot of sampling/buffering code as that can be very time consuming. Any suggestions?

PieterP

The reason it's so hard is that an Arduino was never designed for audio recording.

You could use a Teensy with the PJRC Audio library. It handles all low-level buffering and DMA for you.

Pieter

scottjenson

That's why I'm assuming a shield, which does all the work, would be even more valuable to the Arduino community. Given the large number of microphone builds I've found on this forum, it's clear people REALLY like to use microphones + arduino! That's why I was hoping to find a shield that made things easier.

PieterP

#3
Jan 15, 2019, 05:53 pm Last Edit: Jan 15, 2019, 05:59 pm by PieterP
There are I²S "shields" for Teensy.
https://www.pjrc.com/store/teensy3_audio.html
However, most I²S ADCs should work.

The reason that there are no shields for Arduino is that AVR chips are too slow for real-time audio processing, and they don't have enough memory for recording audio. Either you use a more powerful microcontroller like the ARM on the Teensies, or you add an external chip that handles all audio stuff. Moving audio from that external chip to the AVR doesn't make much sense, because of the problems mentioned before.

scottjenson

As it turns out, I'm using an NRF9160 which DOES have a Arm processor on it. I was hoping to keep my question simple and 'just ask for a shield'. The ARM could easily do all the processing, and has the memory, but it's a lot of custom code to write.

I'm still a bit shocked that given how many tutorials/examples there are for audio on Arduino. *No one* has come up with a simpler add-on that allows for easy audio capture?

I found the ISD1820 Voice recorder which is close, but it involves quite a bit of external circuitry.

There is the Sounduino 3 which looks nearly perfect but the device has no docs, which worries me. I worry that it is just as 'peripheral with controls'. There doesn't appear to be any way to get the recorded data.

The waveshare.com/wiki/Music_Shield looks promising but the docs make it clear you have to sample/buffer the sound yourself. Again, that's a lot of complex code to write.

I don't think I'm asking for anything overly complex from a shield: 1) record audio 2) access to the file. It seems like something the community would like and use.

Lucario448

Have you tried TMRpcm by enabling the recording function in its config file?

This way, the Arduino ifself does most of the job. You'll only need an amplified and biased (where silence represents 2.5V, avoiding negative voltages that the ADC can't handle) microphone and the SD card; in fact the recording is directly saved into the card as a standard WAVE (.wav) file.

scottjenson

Thank you! That's an interesting recommendation. Have you used it? I'm a bit worried that the recording function has the following comment:

Quote
Audio recording is still being tested and may not perform as expected.
But I'll still take a look at it.

Grumpy_Mike


Lucario448

Have you used it?
Not myself (because I don't have a proper microphone), but this video shows up how it works and an example of how to use it. For the mic, looks like the guy recommends the module with the MAX9814 amplifier.
It also shows up briefly the sound quality you should expect from this method.



I'm a bit worried that the recording function has the following comment:

Quote
Audio recording is still being tested and may not perform as expected.
I think it's because the developers didn't tested enough this feature to be 100% sure with the results.
Nevertheless, watch the video, listen carefully the example recording playback part (where Audacity appears on screen), and then judge yourself.


How long do you want to record for?
Seen this https://nootropicdesign.com/audiohacker/
Key question, because if it's possible to retrieve the samples; then it should be no problem to save the entire recording into a SD card as a WAVE file.

I also like the DAC feature, it should give a "cleaner" audio output than the PWM the Arduino offers.

Grumpy_Mike

Quote
Key question, because if it's possible to retrieve the samples; then it should be no problem to save the entire recording into a SD card as a WAVE file.
Yes, if you can do projects like the voice changer on the web sites, then you can simply read those samples and save it to an SD card. But the sample is only about 12 seconds long, depending on the sample rate.

MarkT

I also like the DAC feature, it should give a "cleaner" audio output than the PWM the Arduino offers.
Its possible to use two 8-bit PWM channels together to synthesize 16 bit output, if you scale them
with resistors in a 1:256 ratio.

You can also use sigma-delta noise-shaping to drive a high speed, low-resolution PWM channel to give very
high effective number-of-bits.

So there _are_ ways to get quality audio without having to resort to a DAC.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Grumpy_Mike

Quote
if you scale them with resistors in a 1:256 ratio.
Note both the resistors have to have a tolerance of better than 0.39% for this to work.

Lucario448

Its possible to use two 8-bit PWM channels together to synthesize 16 bit output, if you scale them
with resistors in a 1:256 ratio.
I know TMRpcm can play 16-bit mono audio, but I never tested it because I had no idea of the resistor values. For my particular setup, I think 200 ohm for the high byte and 51K for the low byte should do the trick... right?


You can also use sigma-delta noise-shaping to drive a high speed, low-resolution PWM channel to give very
high effective number-of-bits.
That sounds like some DSP, which I think an AVR doesn't have enough horsepower to pull that off at high sampling rates.



Note both the resistors have to have a tolerance of better than 0.39% for this to work.
Welp... :o guess I can't get the theoretical sound quality anyways. I mean, even 1% tolerant resistors are either rare or more expensive to get (but most likely both at the same time).

MarkT

#13
Jan 18, 2019, 11:50 pm Last Edit: Jan 19, 2019, 12:20 am by MarkT
I know TMRpcm can play 16-bit mono audio, but I never tested it because I had no idea of the resistor values. For my particular setup, I think 200 ohm for the high byte and 51K for the low byte should do the trick... right?
Looks reasonable, but you have to account for the output impedance of the Arduino pin, which is around
30 to 40 ohms depending on supply voltage, so a trimpot is probably the way to go to allow tweaking for best performance, or picking higher resistance values.
Quote
That sounds like some DSP, which I think an AVR doesn't have enough horsepower to pull that off at high sampling rates.
integrators are just addition in the digital domain, very low overhead for simple noise-shaping as
its just a few integrators.

Look at post #5 in this thread: https://forum.arduino.cc/index.php?topic=455680.0

The guts of the 2nd order noise shaper is just:
Code: [Select]

    acc  += sample ;
    acc2 += acc ;
    top = acc2 >> 24   ;
    long feedback = ((long)top) << 24 ;
    acc  -= feedback ;
    acc2 -= feedback ;
    OCR2A = top + 0x80 ;

Which runs in an ISR at 62.5kHz
Quote
Welp... :o guess I can't get the theoretical sound quality anyways. I mean, even 1% tolerant resistors are either rare or more expensive to get (but most likely both at the same time).
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Jimjon

The reason it's so hard is that an Arduino was never designed for audio recording.

You could use a Teensy with the PJRC Audio library. It handles all low-level buffering and DMA for you.

Pieter
Thanks man, I have searched for such info so long and now I got it, thanks again

Go Up