3

I am looking to use the GPIO on a Raspberry Pi to get data from an ADC for audio signal processing.

For the purposes of this forum, my project is to produce a spectrum analyzer which will display the audio spectrum of some music playing on a projector through HDMI. This is to be used as visuals for a music event at university.

The first idea I had was to use an ATMega-328 (arduino mcu) to collect audio samples using the analog inputs, and send the data to the R-Pi using the digital io pins.

I believe that unless I program the ATMega-328 using machine code (asm), the performance will be poor. For example, I understand that using digitalWrite(), peak performance is about 230 Hz, as these functions are not implemented efficiently in the arduino libraries. http://www.codeproject.com/Articles/732646/Fast-digital-I-O-for-Arduino

Okay so this link has alternative libraries, but performance isn't as high as 44100 Hz. Realistically, I would like to achieve about 8 kHz sample rate, at 10 bits per sample.

In addition, the maximum sample rate of the ADC in the ATMega-328 (which is a 10 bit ADC, or will work as one with a precision reference) is about 10 kHz.

I then thought that an I2C device might provide increased performance. This device can sample 100 kHz.

The performance of the R-Pi's io should be greater than 1 MHz, but not higher than about 22 MHz. This should be adequate to carry the required data.

I then read about I2S devices on wikipedia, and understand that the R-Pi has only I2S output, as the pins for I2S input are not connected. (So that was a dead end?)

My question comes down to:

1: Are there any alternatives or better methods I have not considered? Which method would you recommend for this application?

2: Are there any improvements I can make to the second method described (using an external ADC with I2C) to increase performance, baring in mind that FFT's are computationally intensive, and there might not be much time for computing them, even at 900 MHz / 1 GHz clock speed on the R-PI.

Also I am a Physics student, so I know sort of what I'm doing, but I don't have much training in electronics.

I considered using something like the Wolfson Audio board but I understand that it is difficult to setup and use. I am not confident that I would be able to write a program to collect 1024 audio samples and process them using this board. This is where question 3 comes in: Has anyone used this board for a project, and would it be suitable for something like what I am trying to do?

Obviously these questions are quite open-ended. If you want a closed question, then that can be "how do I go about implementing this project that I want to build."

SlySven
  • 3,631
  • 1
  • 20
  • 46
user3728501
  • 248
  • 4
  • 11

2 Answers2

1

You should consider bit-banging SPI. This has two potential advantages.

  • the sample time can be precisely controlled, i.e. every 125 microseconds, not every 125 microseconds +/- 100 microseconds.
  • many devices can be sampled simultaneously.

You'll need to weigh those advantages against higher code complexity compared against the standard SPI interface.

An experiment in bit-banging SPI on the Raspberry Pi

joan
  • 71,852
  • 5
  • 76
  • 108
1

I […] thought that an I2C device might provide increased performance. [… But I] understand that the R-Pi has only I2S output, as the pins for I2S input are not connected.

This will work! The I2S input pins are connected now: to the P5 header, introduced in PCB revision 2.0 (came out Q3/Q4 2012).

For the software side, there is a kernel module for I2S PWM audio input.

(Before that driver existed, somebody got it working with "a modified I2S [kernel] driver and a "soundcard" driver that supplies the required master clock from GPCLK0" – see. His design successfully used a WM8783 ADC on the P5 header, together with an electrete mic and a preamp board, and achieved a 32 ksps sampling rate.)

tanius
  • 203
  • 1
  • 5