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?
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.
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.
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.
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.
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.
scottjenson:
I'm a bit worried that the recording function has the following comment:
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.
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.
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:
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?
MarkT:
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.
Grumpy_Mike:
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).
Lucario448:
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.
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.
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).
Lucario448:
I don't wanna keep deviating this thread, buuuut I have to ask this:
Should all variables have to be signed (accumulators and local ones)?
They are signal samples, signals are ac, so signed. I posted the link to the full code which has all the variable declarations...
Why the resulting sample has an offset? What if an overflow occurs after the addition?
Offset because its going to a DAC or PWM output. If you have overflow your signal has clipped, there's nothing you can do about that in the output stage!
Can sample come from a WAVE file and the shaper still work fine?
They are signal samples, as I've said, so they can come from whatever you like.
Will this shaper also work fine at the sample rate of the previously mentioned WAVE file?
Yes, but noise shaping has much more benefit as over-sampling ratio increases. IE if using 44.1k
samples and 62k PWM you won't get much benefit, but 11k sampling and 125k PWM will be much
more effective - the noise has to go somewhere, you can only push it around, not remove it!
Didn't tried it yet, but I'm afraid of hearing a mess rather than the actual sound
You can get this to work with more integrator stages, but you have to deal with scaling and headroom
issues then, and indeed if you get it wrong its a mess.
noise shaping is indistinquishable from magic if you look at the output samples, the total amount of noise
increases (markedly for high order), but the amount of noise at low frequencies reduces, which is
all you care about.
Here's some simulation of what happens with sigma-delta noise shaping for various orders (top to bottom),
showing the output waveform (top left is original), and the spectrum (before and after some low pass filtering). The test signal is a synthesized set of sinusoidal tones that show up as equal height spikes
in the spectrum, the noise is the "floor" in each spectrum.
The output waveform is a simulation of some mild low-pass filtering applied to a 16-level DAC output.
You can see the high frequency artifacts building up as the noise shaping order increases, but the spectra
show that this lower frequencies have less and less noise, down to about -120dB (19 bit equivalent).
Without low pass filtering the high frequency noise is more prominant.
Note the top right image is the original spectrum, not a processed one, for reference.