Go Down

Topic: Record audio from a microphone to an SD card? (Read 19279 times) previous topic - next topic

Lucario448

Hello there!
My idea goes like this: I want to try to record the sound from a microphone (like my voice), to an SD card. I guess I can't expect record it at a sampling rate higher than 8 KHz (due to the timing of the functions). The audio will be stored in a "raw file" (because I don't know how to create the WAVE/RIFF header automatically); and maybe playback that recording with the same board (but that's the "stage two" of my plan). Now here are my questions:

  • Shall I need amplification for the microphone's signal, or changing the reference voltage will also help?
  • Can an analog input pin handle negative parts of a waveform? I think even a schottky diode will completely kill the input signal.
  • Since the recorded samples must be unsigned 8 bit, which of the following is faster? Map the value or shift two bits?
  • Would you mind suggest me a way to automatically stop recording? I guess suddenly stop writing to a file without closing it is a bad idea.


Thanks beforehand and sorry if I made misspellings.

Grumpy_Mike

1) you need an amplifier
2) no you need to bias the input waveform to 2.5V
3) shift
4) push switch, or when the input envelope drops to zero for a certain time

Lucario448

1) you need an amplifier
Even for a desktop computer microphone?

Quote
2) no you need to bias the input waveform to 2.5V
Is that like mixing 2.5V with my audio signal?
If so, can I just put both in the same pin, or do I need some additional components? (Apart from a voltage divider)

Grumpy_Mike

Quote
Even for a desktop computer microphone?
Yes.

Quote
Is that like mixing 2.5V with my audio signal?
If you like to think of it like that. The proper way of describing is adding a DC offset.

Quote
If so, can I just put both in the same pin,
Yes you have to.
Use 10K pull up and pull down on the analogue input and couple the audio in with a none polerised capacitor as big as you have got.

Lucario448

Use 10K pull up and pull down on the analogue input
I think this is the voltage divider part, right?

Quote
and couple the audio in with a none polerised capacitor as big as you have got.
  • How that capacitor goes here? Between the signal and the input pin (in series), or between the signal and ground (in parallel)?
  • Non-polarized capacitor of which type? Because I think a big one is electrolytic

DVDdoug

Quote
Even for a desktop computer microphone?
Almost all "computer microphones" are electret condenser types and they require 5V power (normally supplied by the soundcard).

Here is an example of an electret microphone preamp circuit with power for the mic and biased output.


Quote
Is that like mixing 2.5V with my audio signal?
Yes.   The Arduino can't read negative voltages, so and AC audio signal must be biased.   (You can subtract-out the bias in software if you wish.)   Hre is an example of a bias circuit.


Grumpy_Mike

Quote
How that capacitor goes here? Between the signal and the input pin
yes.

Quote
Non-polarized capacitor of which type?
doesn't matter.

Lucario448

All right, thank you very much!
Is not that hard to do this, but now I'm worried about two things:

analogRead function is so slow by default (and still not yet tested its "fast mode")
I don't know how long takes writting a byte to a file in a SD card. Will the technique discussed in this thread work too?

Grumpy_Mike

Quote
I don't know how long takes writting a byte to a file in a SD card.
No and you will not find out because it is not fixed. It depends on the type of SD card, where abouts on the card it is and its age. Plus a lot more factors.

Quote
Will the technique discussed in this thread work too?
No idea, the url is wrong.

Lucario448

No idea, the url is wrong.
Jeesh what I made wrong this time? How can I get the actual URL of a thread?

Grumpy_Mike

Copy and past normally works for me. Just put the link into url tags and don't use the link icon.

Lucario448

Copy and past normally works for me. Just put the link into url tags and don't use the link icon.
https://forum.arduino.cc/index.php?topic=377029.60

This is the actual URL of the thread then. Hope it works properly this time...

Grumpy_Mike

Yes it will work.
Another technique is to put a pin high, do the code and put it low, using port manipulation. Then measure the width of the pulse on an oscilloscope.

Lucario448

Another technique is to put a pin high, do the code and put it low, using port manipulation.
Will the "port manipulation" execute almost instantly? (unlike the digitalWrite function)

Quote
Then measure the width of the pulse on an oscilloscope.
Awwwwww. Will a cheapy one work too? I mean, this one:
http://www.amazon.com/SainSmart-DSO138-1Msps-Digital-Oscilloscope/dp/B00XXZB5LW

Grumpy_Mike

Quote
Will the "port manipulation" execute almost instantly?
Yes.

Quote
Will a cheapy one work too?
No that one is way too slow. It will only work at 1M samples per second. You have a 16MHz processor so to actually measure anything approaching accurately you need it 100 times better than this.

Go Up