Simple Electret Mic test
Rayman
Posts: 14,619
Just got this electret microphone test working.
Usually, one needs an amplifier to boost the signal level.
But here, I'm testing connecting directly to P2 pin.
The circuit is real simple, just a 2.2k resistor from VDD to mic and a capacitor from mic to P2 pin.
With P2 in 100X ADC mode, getting a possibly acceptable signal level.
I multiply what I get by 10X and send to speakers in this example to get a reasonable volume.
I'm not 100% happy with it, but might be good enough for basic needs.
Update: See post #8 for code that records from mic, plays it on speakers, then saves to uSD.
Comments
The code is something whipped up fast...
Hijacked the waveplayer code with a 16kHz mono wav test file.
Records mic first to HUB RAM and then substitutes that data for the wav data from uSD.
Definitely need a better code, but this shows what we have to work with...
This sounds a lot better. Adding up 8 samples to create each output sample:
Added a simple low pass filter and sounds better:
What values do you use for pinstart ()? From the waitx ##1000 and the rdpin(13)-$2000 I can guess you use SINC2 sampling mode. Why? And instead of adding up 8 samples you could simply use a longer sampling period for the ADC.
Hardware manual says SINC2 is best for DC and SINC3 is best for fast signals.
I'm thinking this is some middle ground where doesn't really matter.
Definitely worth exploring though...
I think SINC3 makes not much sense because the longest sample period is 512 clocks which is way too fast. SINC2 sampling is the most forgiving mode because you don't have to subtract the last accumulation value in software but the Z register always holds a valid sample value even if your rdpin()s are not synchronized. But you'll get aliasing effects if they aren't and this is definitely the case because the waitx ##1000 isn't very accurate in Spin. You should set an apropriate sampling period and wait for IN to become high, either by setting up an event or by polling with pinr().
Here's code that records a bit of audio from the mic, plays it, and then saves it as .wav file to uSD.
Also, here's an example recording, MIC1.WAV (in mic1.zip). A version that is cleaned up a bit with Audacity is in MIC1_Filtered.WAV
This recording was with mic about 1 foot away from mouth, spoken in a normal-ish volume