Pages: [1]   Go Down
Author Topic: Arduino basic audio recording project  (Read 1277 times)
0 Members and 1 Guest are viewing this topic.
SF Bay Area
Offline Offline
Full Member
***
Karma: 1
Posts: 182
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know this has been asked before but I did not see much in specifics.

Is it feasible with a Arduino Mega to record 1 channel of audio at 4kHz, or possibly 8kHz straight to SD card?
Or possibly over Wi-Fi or X-Bee?

I'm hoping to do that as well as record some other channels from a couple of A/D channels
 at 100Hz on a MCP3208 12-bit ADC. I've done this part and send it to processing over serial, but not to an SD card yet.
http://ww1.microchip.com/downloads/en/devicedoc/21298c.pdf

Is this project feasible? I know the Arduino is not the best fit for the job but I don't really want to jump
into a PIC or Beagleboard quite yet.

I could in the future get away with a rectifier/RMS circuit to get something akin to SPL.
But it would be hard to get there without first hearing/analyzing the audio to determine the frequency range.

I want to use a contact microphone using a Meas PVDF sensors.
http://www.meas-spec.com/downloads/DT_Series.pdf

Alternatively, I could record the audio on my laptop, and integrate everything with Processing, but that will make it very cumbersome being tethered like that. I want to keep this small and portable.

So, essentially I think I have a few questions that I'll list more directly below. FYI, I'm a decent programmer, but am a novice at the electronics.

1. Is the arduino Mega capable of doing the audio capture and writing to the SD card with the MCP3208?
2. Could it be done with WiFi or Xbee?
3. What is a good option for creating the gain necessary on the pvdf sensor?
4. What is a good tutorial or some suggestions for creating simple circuits for making the low-pass/high-pass filters for this setup?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46240
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is it feasible with a Arduino Mega to record 1 channel of audio at 4kHz, or possibly 8kHz straight to SD card?
At what level of integrity? Will the resulting data be intelligible when replayed? How will you replay it?

You need to sample the input on an analog pin often enough to be able to reproduce understandable data. How many samples per second will that require?

How long does analogRead() take to return a value? With these two pieces of information, you should be able to determine whether the project is feasible.

Of course, it takes time to write the data to the SD card, so you must take that time into consideration. How much time? Well, that depends on how you write the data. One sample at a time? With buffering, so you write a bunch of samples at once?

You are limited, when sending serial data, to 115200 baud (bytes per second). How many bytes of data can you generate per second? Does the latency of a XBee or WiFi pose a problem?

What are you planning to do with the recorded data?
Logged

SF Bay Area
Offline Offline
Full Member
***
Karma: 1
Posts: 182
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wasn't planning on using analogRead() cause I'd be using a separate ADC chip.

I'm sure I'm not looking in the right places, but I'm not finding what the throughput and latencies are for the SD card. Is it limited by just the serial interface?

I can chunk up the data and write it, but it's not clear to me what is the best. Still trying to read up on the SD card interface and see what's the best way to use it.

I don't know all the throughput and latencies, yet, but it seems that it should be in the ballpark.
Audio projects seem to be ill-advised generally here with the arduino, so I thought maybe I'm overlooking something.

Even at 8kHz (assuming 2 bytes holding sample), you'd only have 16000 bytes/second. Too much for 9600 bps, but for 115200 should be fine. Unless the jitter is huge, it would seem fine to sample the audio.

I imagine there could be a problem with sampling it and doing something else with it simultaneously (ie writing to disk or WiFi, etc). If sampling/sending 1 or 2 bytes at a time is too much, then that's a problem. It could be buffered to send, and would that alleviate the bottleneck or is there something else I'm missing?

Since I only want to record, to be analyzed later on the PC, I'm thinking this is viable. I won't be asking the arduino to do anything besides these basic I/O functions. I will write some code in java or Processing to split up the file and create a wav file, and other formats that I can read in my own viewer.
« Last Edit: May 16, 2011, 02:23:55 pm by oscarcar » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
you'd only have 16000 bytes/second. Too much for 9600 bps, but for 115200  should be fine
115 200 bits per second is 11 250 bytes per second.
16 000 bytes is going to be a squeeze.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

SF Bay Area
Offline Offline
Full Member
***
Karma: 1
Posts: 182
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Woops. You're absolutely right.

I guess 4kHz would be the highest, and I can see that it's going to be a little tight even at that.

I think I'll plan on using Processing on the PC and capture the audio and arduino signals for now.
Logged

SF Bay Area
Offline Offline
Full Member
***
Karma: 1
Posts: 182
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just another thought. If I use an i2c ADC would that allow me to bypass the SPI baud rate limitation?

It seems like it should, but I haven't tried i2c yet.

And it looks like those calculations were a tad off before:
115200 bits per second = 14400 bytes per second
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
And it looks like those calculations were a tad off before:
115200 bits per second = 14400 bytes per second
OK, that's interesting arithmetic - could you explain it, please?
(remember one start bit, one stop bit, eight data bits)
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31541
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Just another thought. If I use an i2c ADC would that allow me to bypass the SPI baud rate limitation?
No, I2C is much slower than SPI.
Logged

SF Bay Area
Offline Offline
Full Member
***
Karma: 1
Posts: 182
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, back to drawing board.

I didn't realize the stop & start bits are included in the throughput values. My bad.

Thanks for the replies.

It looks like I might have to eventually grab a beagleboard, although maybe still
incorporate a mini arduino for the simplicity. It would be kind of cool to have
a shield to place an arduino on top of a beagleboard.
Logged

SF Bay Area
Offline Offline
Full Member
***
Karma: 1
Posts: 182
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was trying to research the Arduino Mega maximum baud rate, and it seems that others
say they can set it to 1 or even 2 megabits per second. I don't know what to check on my ADC
chip to see if it can operate at those speeds, but I assume it can get close since it can sample at 100k samples per second. (edit: It looks like it can operate at 2Mhz operating at 5V, so I think that's promising)

I guess I'll just try it and see if I can get something at that rate.
« Last Edit: May 17, 2011, 12:20:56 pm by oscarcar » Logged

SF Bay Area
Offline Offline
Full Member
***
Karma: 1
Posts: 182
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It looks like I can get about 40 ksps, so it is far more than enough for my purposes.

The guy who wrote the code got about 62 ksps.

40 ksps * 2 bytes = 80 kilobytes/second = 640 kilobits/second

I assume I can fit this within the SD card throughput (altho this is way more than I need), but I'm not sure as I haven't been able to find any hard numbers. I've only seen someone mention they can get 150 Kbytes/second write speeds, again way more than enough.

Am I missing anything else? Will I be overtaxed trying to do input simultaneously with output?
Logged

Pages: [1]   Go Up
Jump to: