Audio over I2C for guitar effect pedal possible?


16 posts
by Simius » Thu Jan 24, 2013 12:04 pm
Hi,

so I had the idea to build a digital effect pedal for an electric guitar with my Raspberry Pi.

I've read that I2S is not quite working yet on the Raspberry. An interface over USB might be too much and also too slow. Also, I don't need PCM or I2S. I just want to mess with the signal and put it out again.

My idea is to use an Analog-to-Digital converter with an I2C (sic!) interface such as this to receive the raw guitar signal.
I would then make simple modifications on the signal and output it over a DAC chip.

Do you think this is all possible? I think I don't need high quality since the signal is distorted anyways.

I've seen a similar thing here. However, I believe the Arduino is only used to control the digi-pot chip which is doing the distortion. Correct me if I am wrong :).

Thanks a lot!
Posts: 6
Joined: Thu Jan 24, 2013 11:33 am
by Burngate » Thu Jan 24, 2013 2:50 pm
Simius wrote:...My idea is to use an Analog-to-Digital converter with an I2C (sic!) interface such as this to receive the raw guitar signal ...

That A-D is a bit slow even for lo-fi guitar - its fastest conversion is 240 samples per second, so the highest frequency you could use it for is 120Hz
Wyszkowski's Second Law: Anything can be made to work if you fiddle with it long enough.
Brain surgery is easier than psychoanalysis
User avatar
Posts: 2907
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
by Simius » Thu Jan 24, 2013 3:17 pm
Okay. Could it work then if I use ADC with a higher sample rate? I read that electric guitars have a frequency of roughly 170hz - 2khz but most amps have 10khz.
Posts: 6
Joined: Thu Jan 24, 2013 11:33 am
by Rendagar » Thu Jan 24, 2013 9:06 pm
Just a quick bit of background for you on the theory behind sampling a signal.

Simius wrote:I read that electric guitars have a frequency of roughly 170hz - 2khz but most amps have 10khz.


This is the frequency range in which the guitar is most dominant. This does not mean that higher frequencies are not important, just less pronounced. Not including up to 20kHz (theoretical limit of human hearing) will distort your sound, thou you will have to experiment if it is noticeable in your application. Because you say guitar speakers generally are characterized up to 10Khz I would assume the entire range of human hearing is not necessary for the guitar. Sadly I do not have the experience to give you a more concrete answer.

Also don't confuse distorted sound with low quality sound. Just compare a cheap and high and distortion pedal and you will most certainly notice a difference.

If you want to understand what Burngate means by the ADC being to slow check out the Nyquist–Shannon sampling theorem. This is a theory you should really understand if you want to sample audio. In short this states:

To be able to perfectly reproduce a signal you need to sample it at at least twice the highest frequency found in the signal.

If you do not to so the signal will alias (introduce extra harmonics not represented in the original signal).
So if you want to reproduce a 2kHz signal you need to sample it at 4kHz and if you want to be able to reproduce a signal up to 10Khz you will need a ADC capable of handling 20kHz signals.

Hope this is a bit clear. If not pleas ask.

Cheers,
Posts: 4
Joined: Thu Jan 24, 2013 12:30 pm
by Grumpy Mike » Fri Jan 25, 2013 8:58 pm
Basically you can not do audio input with a simple A/D because Linux will not allow you the consistent and regular access to it that you need to make it work.
Ditch Linux and you stand a chance.
User avatar
Posts: 784
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
by Simius » Sat Jan 26, 2013 10:11 am
Hi,

thx for your help.

So, I probably need a 20khz ADC. At least, that would be my first shot.

@Grumpy Mike: Why would Linux not allow a consistent access? How do more sophisticated inputs work?
Posts: 6
Joined: Thu Jan 24, 2013 11:33 am
by aortiz557 » Mon Feb 04, 2013 8:09 pm
you need an realtime operating system to guarantee that your samples will be taken at a set interval. if you tried that with linux, it would take a sample every time it had a free chance, which depending on what else is running, would not be at equal intervals. also, why not skip the adc and just use a usb soundcard?
Posts: 2
Joined: Fri Oct 05, 2012 12:29 pm
by Simius » Tue Feb 05, 2013 10:13 am
Hi,

I don't want to use a USB soundcard because I think it might be too slow and mainly because I want to get my hands on bare metal.

Just on the side: How does a soundcard manage a continous sound in Linux?
Posts: 6
Joined: Thu Jan 24, 2013 11:33 am
by jimijames » Fri Mar 01, 2013 7:29 am
See what this guy is doing for ideas. Very cool.
http://guitarextended.wordpress.com/
http://pierreetleloup.bandcamp.com/track/we-own-the-sky

I hope to do something similar, if a little simpler.
Posts: 2
Joined: Wed Jul 25, 2012 10:11 am
by Simius » Fri Mar 01, 2013 11:54 am
That sounds cool.

I found a port of FreeRTOS for Raspberry Pi (http://www.freertos.org/Interactive_Fra ... most-Ready). I will look into that and see if I get it to work with an ADC with 20khz. Anyways, I think it would be cool to get FreeRTOS to work probably and offer an image.
Posts: 6
Joined: Thu Jan 24, 2013 11:33 am
by Joeboy » Fri Mar 01, 2013 11:58 am
This is where I'm hopefully heading with http://www.joebutton.co.uk/blog/baremet ... spberrypi/ , although I'm sadly not finding time to work on it at the moment.
Posts: 24
Joined: Wed Oct 31, 2012 11:59 am
by mhelin » Fri Mar 01, 2013 12:19 pm
This module does not use I2C but SPI instead but it can be interfaced to RPi as well and can work as CODEC + as MIDI synth at the same time:

https://www.sparkfun.com/products/9943

I think Olimex and other companies have similar "MP3 shield" in their product portfolio.

If you look at schematics the line in and mic in are connected to ground via a resistor and cap so you have to mod the circuit a little bit.

Documentation for the chip can be found here:
http://www.vlsi.fi/en/products/vs1053.html
Posts: 99
Joined: Wed Oct 17, 2012 7:18 pm
by mhelin » Fri Mar 01, 2013 12:25 pm
Here's another on Amazon:
http://www.amazon.com/music-breakout-VS ... sbs_misc_5
http://www.geeetech.com/vs1053-mp3-brea ... p-611.html

With Line Input connector and onboard electrec capsule microphone as well.
Docs: http://www.geeetech.com/wiki/index.php/ ... th_SD_card

So instead of decoding MP3 you "decode" and "encode" 16-bit PCM data (so you have to send also the WAV file header to it in the beginning of playback which is kind of funny) at some reasonable rate. I think 30-40 kHz sampling rate (Line6 POD uses 39.9 kHz) is fine, even less is OK.
Posts: 99
Joined: Wed Oct 17, 2012 7:18 pm
by mhelin » Fri Mar 01, 2013 1:01 pm
According to this thread it's better to use VS1063 chip for full-duplex I/O though with VS1053 it's possible but a special software (provided by VLSI) is needed:

http://www.vsdsp-forum.com/phpbb/viewto ... ?f=7&t=712

So this is actually the one you want to use with RPi:

https://www.sparkfun.com/products/11684

Linux drivers:
http://sourceforge.net/projects/vs10xx/?source=dlp
Posts: 99
Joined: Wed Oct 17, 2012 7:18 pm
by AutoStatic » Fri Mar 01, 2013 7:10 pm
Simius wrote:I don't want to use a USB soundcard because I think it might be too slow
What do you mean by too slow, are you referring to latency? You can achieve quite low latencies with USB interfaces.

Jeremy
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
User avatar
Posts: 311
Joined: Tue Jan 01, 2013 10:27 pm
by AutoStatic » Fri Mar 01, 2013 7:15 pm
aortiz557 wrote:you need an realtime operating system to guarantee that your samples will be taken at a set interval. if you tried that with linux, it would take a sample every time it had a free chance, which depending on what else is running, would not be at equal intervals. also, why not skip the adc and just use a usb soundcard?
Afaik this is not true. Linux can take and deliver samples at exact equal intervals as long as you use JACK and give it a high enough rtprio. The RPi kernel is a PREEMPT one so it allows for using SCHED_FIFO.

Jeremy
RPi and real-time, low-latency audio: http://wiki.linuxaudio.org/wiki/raspberrypi
RPi audio repository: http://rpi.autostatic.com/
User avatar
Posts: 311
Joined: Tue Jan 01, 2013 10:27 pm