As part of a school project I have to make a voice recorder in order to record the discussion of two people sitting on a table and save the wav files on an SD card.
Compared to this tutorial, my approach differs on that I'm using an Arduino Uno and a sparkfun electret microphone breakout. Also, I haven't incorporated the batteries yet, but the system is powered by my laptop.
I managed to get a .wav in the SD card but with a continuous noise in the background. You can hear what I get in the attached file.
The WAV file is corrupt - something wrong with the header. Goldwave says that it is 8-bit sampled at 16kHz.
But the audio is obviously totally screwed. The audio of your voice only occurs as negative samples interspersed with regular clicks. My guess is that the clicks are caused when the data are written to the SD card. Perhaps the card can't keep up with the sampling rate of 16kB/sec. But you need to post your code.
There are several things wrong with your code but the major one is that you can't do all the recording in the button function. That is an interrupt service routine which must deal with an event quickly and then return.
The button function should only set a flag (ideally an unsigned character which must also be declared volatile). The loop function then continuously tests this flag and when it is on it then executes the code that you currently have in the button function AND it also turns the flag off again.
If this code is meant to delay it definitely should not be in an interrupt routine but:
while (i < 300000) {
i++;
}
it may not delay at all. The compiler is probably smart enough to figure out that the result of that loop is to set i to 300000 and will replace the loop with i = 300000;
Even if the compiler leaves it as it is, how long is this delay supposed to last? You'd be better off using delay or millis.
There are obviously other problems too but fix these up first.
Thank you both for your replies. Based on them, I decided to start fresh and build the project from scratch by removing the button and the LED and keeping only the microphone and the SD card.
Maybe there is a difference in the microphone. I don't know how the library works but the microphone used on inscrutables uses a MAX9814, it means that you have a full wave recording and that the zero is not at 0 but at 512. Other simple microphone doesn't work in this way.
Thanks for you reply zoomx.
I had already done what it was written in the link you submitted, but you were right about the microphone. I used a MAX 9814 and the result is better (see attachment 1.zip), even though there is still a background noise.
I also used the MAX 9814 with a new code that I downloaded from here: (APC’s April 2023 issue is on sale now! | TechRadar, Project 18) and I got a similar result (see attachment 2.zip).
that is not a real microphone until you scream on it. I am not sure but this microphone works only on half of the wave, it means that in silence it gives 0 and loud sound give 1023 on ADC. It is more like a sound sensor that can listen a hand clap, nothing more.
The remaining noise is due to the connections and Arduino itself but I was surprised about the quality of this simple recorder, I have a MAX 9814 microphone too.
Thanks for sharing your results!
Update: I made the same project and got the noise. I am using the laptop to power the Arduino and the laptop is connected to the mains. The noise came from the mains and the laptop.
Hi, I am wondering if you have resolved your issues and what your solution is. I am trying to record with MAX9814 with Arduino Uno. I also tried the "Make your own spy bug" code. It doesn't work. All I heard is clicking sound. Any advice or suggestion would be nice. Thank you.
Grumpy_Mike:
Always remember that instructables are by and large crap written by people who have a vastly inflated idea of their own skill level.
There are some good ones, but the website used to look so horrible and cluttered it put me off anyway.
They have sorted that out at least, but their is simply no curation or quality control.
I also tried the "Make your own spy bug" code. It doesn't work.
Was that the one by Great Scott? If so he has, or had at the time, no idea about biasing an audio input. But the lack of any acceptable results didn’t stop him from posting this pile of crap.
Grumpy_Mike:
Was that the one by Great Scott? If so he has, or had at the time, no idea about biasing an audio input. But the lack of any acceptable results didn’t stop him from posting this pile of crap.
Hi Mike, yeah. It was from that post. I saw some people replied that they made it so I decided to use it as part of my school project and bought all the components he suggested. But the recording did not work at all.
I am new to Arduino. Still trying to find a good example of audio recording with Max9814.
Well the Max9814 board should be biased correctly so there is no worry about that one, providing the supply matches the processor’s supply voltage. However the AGC while in general is a great feature when it is used to handle speech with gaps in will tend to distort when the sound suddenly starts and the gain is rapidly turned down.
The trick to sound at low bit resolutions is to keep the samples close to the maximum. So for example if you use that board with the internal A/D you are digitising at 10 bits. Where as if the playback is through PWM that is only 8 bits. So the normal response is to throw away two bits of the recording. This leaves you with, in effect, only digitising at 8 bits.
One way round this loss of resolution is to record onto you SD card at 10 bits, so that is two bytes per sample. Then have a code that scans through that file and finds the peak sample. Then works out a scaling factor than will scale that peak to a full 8 bits, that is 255. Then go through the recording again applying that scaling factor to each sample and storing it into another file for playback by PWM.
This is in effect what I did here to get these samples:-
Although I did do this process on a laptop using the Processing language, there is nothing to stop you doing it on board an Arduino.
zoomx:
Same years ago I tested the SpuBug project.
Better to use a battery, PC USB has a lot of noise.
This was my sketch with the modified library.
Don't expect great results!
Hi Thank you! I tried with your code but still got the same recording. I have attached the example here. I tried it with PC first with the expectation that there would be a lot of noise. But this is not right, is it?
zoomx:
Same years ago I tested the SpuBug project.
Better to use a battery, PC USB has a lot of noise.
This was my sketch with the modified library.
Don't expect great results!
Sorry, forgot to mention that the code was succesfully compiled, but it has this warning for every single recording line: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
case 1: audio.startRecording("1.wav", 16000, A0); break;
Was it the same for you? I am using Arduino Uno. Thank you very much.