Granular synthesis creates a unique type of distortion caused by discontinuities between individual grains in the outgoing signal. Sometimes this distortion creates an effect I can only describe as a "ripping" sound, other times it introduces new frequencies into the audio that were not present before. Here is an example by Aphex Twin, the granular synthesis is especially prominent in the bridge at around 3min in. Another example of granular synthesis, this time applied to vocals for pitch shifting and textural effects, is from Paul Lansky. My favorite thing to do with this effects box is to use subtle pitch shifting to achieve an androgynous vocal sound, I got the idea for the project after listening to copious amounts of Fever Ray this past winter, you can hear how she pitch shifts her voice to sound somewhat masculine at times.
PARTS LIST
(1x) Arduino Uno REV 3 Radioshack 276-128
(7x) 10K Ohm 1/4-Watt Carbon Film Resistor (2 packages) Radioshack #271-1335
(9x) 20K Ohm 1/4-Watt Carbon Film Resistor (2 packages)
(1x) 1K Ohm 1/4-Watt Carbon Film Resistor Radioshack 271-1321
(1x) 50K-Ohm Linear-Taper Potentiometer Radioshack #271-1716
(1x) 10KOhm Audio Control Potentiometer with SPST Switch Radioshack #271-215 (this will be used to control volume and turn the device on/off)
(5x) 0.25" Knurled Knob Radioshack 274-424
(2x) 9V Alkaline Battery Radioshack #23-866
(2x) Heavy-Duty 9V Snap Connectors Radioshack #270-324
(1x) PC Board with Copper Radioshack #276-147
(1x) SPST PC-Mountable Submini Toggle Switch Radioshack #275-645
(2x) Male Header Pins Jameco 103393
(3x) 8 pin socket Radioshack 276-1995
(1x) TL082 Wide Dual JFET Input Op Amp Radioshack 276-1715
(3x) 100K Ohm 1/4-Watt Carbon Film Resistor (1 package) Radioshack 271-1347
(1x) 10uF electrolytic capacitor
(1x) 47nF capacitor
(3x) 0.1uf capacitor Radioshack 55047557
(2x) 1M-Ohm Linear Taper Potentiometer Radioshack 271-211
(1x) 1MOhm logarithmic potentiometer
(1x) 2kOhm 1/4-Watt Carbon Film Resistor
(1x) male header pins Jameco 103393
(1x) 10K-Ohm Linear-Taper Potentiometer Radioshack 271-1715
(1x) DPDT Flatted Metal Lever Toggle Switch Radioshack 275-636
(2x) 1/4" stereo jack Radioshack 274-141 or Radioshack 274-312
(2x) 5mm High-Brightness White LED (1 package) Radioshack 276-017
(2x) 100 ohm 1/4W 5% Carbon Film Resistor Radioshack 271-1311
(2x) TS922IN Dual Op Amp Digikey 497-3049-5-ND (one TS924 would also work, but they are not available on digikey at the moment)
Additional Materials:
22 Gauge Wire Radioshack #278-1224
Solder Radioshack #64-013
sand paper
plywood
wood glue
hot glue
screws
Download Arduino IDE
Step 1: Schematic
The first schematic shows the audio out circuit. This project outputs audio through an 8 bit R2R digital to analog converter through Arduino digital pins 0-7. This signal is sent through an amplifier, a low pass filter, and a volume control pot before being sent out to speakers.
The second schematic shows the mic input circuit. The line in the from the mic is sent through an amplifier and a DC offset circuit before being sent into the Arduino via analog input pin A0.
The third schematic shows how all the controls of the effects box are connected to the Arduino. There are two LED indicators in this project: one clipping indicator and one output indicator. Three pots on the device control grain size, pitch, and wet/dry mix and a switch controls the direction of sample playback (forward or reverse).
Step 2: Header Pins
Step 3: DAC: Part 1
Step 4: DAC: Part 2
Step 6: Test DAC
Some info about the code- basically what I've done here is set up a timer interrupt that increments the variable t at a frequency of 40kHz. Once t reaches 627 it resets back to zero (this happens with a frequency of 40,000/628 = 63Hz). Meanwhile, in the main loop the Arduino sends a value between 0 (00000000 in binary) and 255 (11111111 in binary) to digital pins 0 through 7 (PORTD). It calculates this value with the following equation:
PORTD=byte(127+127*sin(2*t/100));
So as t increments from 0 to 627 the sine function moves through one complete cycle. The value sent to PORTD is a sine wave with frequency 63Hz and amplitude 127, oscillating around 127. The DAC translates this to a voltage between 0 and 5V, where a 0 sent to PORTD equals 0V and a 255 sent to PORTD equals 5V.
Step 7: 8 pin socket and buffer
Step 8: Wire up pot
Step 9: Second 8 pin socket
Step 10: Voltage divider
If you are planning to send the output out as line level into another effects module or amplifier, then do not add this voltage divider.
Step 11: RC low pass filter
Nyquist's Theroum states that for a sampling rate of x Hz, the highest frequency that can be produced is x/2 Hz. So if you have a sampling rate of 40kHz (standard for most audio), then the maximum frequency you can reproduce is 20kHz (the upper limit of the audible spectrum).
By using a low pass filter on the signal with a cutoff frequency of 20kHz, you can smooth out the "steps" in your waveform while keeping the overall shape of the waveform intact. I used a simple RC flow pass filter to achieve this: a resistor and a capacitor in series to ground. Connect the resistor to the incoming signal and the capacitor to ground, the signal from the junction between these two components will be low pass filtered.
You can calculate the values of the capacitor and resistor you need for a low pass filter according to the following equation:
cutoff frequency = 1/ (2*pi*R*C)
so for a cutoff frequency of 20,000Hz and 1kOhm resistor:
20000=1/(2*3.14*1000*C)
C =~ 8nF
Since 8nF capacitors are hard to come by I rounded up to 0.01uF. This gives a cutoff frequency of about 16kHz. You can mess around with different values and see what you like best, I tend to like heavier filtering bc it removes more unwanted noise.
Solder a 1kOhm resistor to the junction from the voltage divider from the last step (if you did not include the voltage divider, solder straight to pin 7). Solder a 0.01uF capacitor in series with this resistor to ground. Solder a wire from the junction between the capacitor and resistor to pin 5 of the second socket.
Step 12: More buffering
Solder a wire between the two non-inveting inputs of the op amps (pins 5 and 3 of the second socket). Solder another wire between the two outputs (pins 1 and 7 of the second socket). On the underside of the board solder the inverting inputs to their outputs (fig 2).
Step 13: DC offset
Solder the - end of a 100uF (or higher) capacitor to the output of the second op amp. The signal coming from the + end of the capacitor will be DC offset to oscillated around 0V.
Step 14: Audio Jack
Use hot glue to add some structural support to these connections and prevent short circuits. Solder the green wire to the + end of the 100uF capacitor and solder the black wire to ground.
Step 15: Microphone Circuit
Fig 3 shows the same microphone signal after amplification, you can see how the height of the peaks has increased so that the wave oscillates between -2.5 and 2.5 V (amplitude of 2.5V). Fig 4 shows the signal after it has been DC offset; it still has an amplitude of 2.5V, but the center point is 2.5V instead of 0V, so the wave never drops down below 0V. (Note- the slight change in shape between the signals in figure 3 and 4 is dues to changes in my voice between the two pics, it has nothing to do with the circuit). The signal in fig 4 is ready to go to an Arduino analog input pin.
Step 16: Batteries
Step 17: Amplifier socket and power
Step 18: Microphone input
Step 19: Non-inverting amplifier: part 1
Step 20: Non-inverting amplifier: part 1
Step 21: Non-inverting amplifier: part 2
Step 22: DC offset: part 1
Step 23: DC offset: part 2
Step 24: DC offset: part 3
Step 25: Connect to analog input
Step 26: Simple audio out
Step 27:
In the code below I triggered the output to the DAC via the ADC interrupt. This interrupt is similar to other Arduino timer interrupts, but it only executed when a new ADC value has been reached (in this case at a rate of ~38.5kHz, or every 26us). The output of the code below is exactly the same as the code above, but it will be more convenient to use the interrupt code moving forward.
Step 28: Half frequency playback
Step 29: RC potentiometers
Solder a row to header pins to digital pins 9-13. Solder a 10kOhm resistor and 0.1uF capacitor in series to pins 10-12. Solder the free end of the 0.1uF capacitors together and connect to Arduino +5V. Connect the outside pin of two 1mOhm linear taper pots to the junction between the resistor and capacitor attached to digital pins 11 and 12. Connect the outside pin of a 1mOhm logarithmic taper pot to the junction between the resistor and capacitor attached to digital pin 10. Solder the middle pins of each pot to ground.
I you'd like you can increase the resolution of any of these controls by increasing the capacitance of the 0.1uF cap to 1uF or 10uF. This change will have to be accounted for in the final firmware as well.
Step 30: Switch
Step 31: Indicator LEDs
Step 32: Output switch
Step 33: Enclosure
I coated the plywood in three coats of polycrylic and glued the sides together with wood glue. I glued three small triangular pieces into the corners of the enclosure so that I could screw the back panel on with wood screws (fig 3).
Attach the Arduino to the header pins on the protoboard and begin installing the components in the enclosure. I started by attaching the pots and switches to the front panel and then added the jacks, LED indicators, and pots to the sides. Finally I pushed the arduino's usb port through the square hole on the bottom of the enclosure. My arduino sat firmly in place, you could screw it to the back panel for an extra secure fit.
I've attaches the corel file for the enclosure that I built.
enclosure.cdr14 KB











































































































Visit Our Store »
Go Pro Today »




I see. Yeah I was actually quite surprised at the relatively high samplerate you managed to achieve! I though the atmega328 was way to slow/simple to handle that. Have you considered using a audio codec (external ADC and DAC) (http://uk.rs-online.com/web/c/?sra=oss&r=t&searchTerm=audio+codec&x=-608&y=-21) for both input and output? I don't think there is very much point in increasing the fidelity after the processing when the audio is compressed to 8-bit fidelity when 'entering' the Arduino.
This could also be something to look into: http://soniccrayon.blogspot.no/2012/08/anti-nautilus-or-autoglitch.html (the schematic, first image below the youtube video)
http://www.instructables.com/id/Split-rail-power-supply-from-a-single-rail-supply/
you can see in this project how there's a +V, -V, an 0V supply. Connect the 0V supply to Arduino ground.
http://www.instructables.com/id/Stereo-Audio-with-Arduino/
your dac setup should be similar, let me know if you still can't get it up and running, I can take a look at the data sheet.
I had this hooked up and was messing around with sound on my PC speakers and was wondering if this voice stream could get sent to my PC via ethernet. Say using the ethernet shield connected to the arduino being used?
http://www.arduino.cc/en/Main/ArduinoEthernetShield
so you will need keep those pins free. If you keep the clipping indicator, you will need to move it to another digital pin (like pin 9)
Check out this piece of code:
http://www.instructables.com/id/Arduino-Audio-Input/step7/Interrupt/
you should try to send your serial data via ethernet inside the interrupt routine. Hopefully the Ethernet Shield is fast enough to send data at 38.5kHz, I'm not sure.
code with clipping indicator is at the bottom of this page:
http://www.instructables.com/id/Arduino-Audio-Input/step8/Clipping-Indicator/
change all the 13's to 9's
I'm working on a project and wondering if this can also work with voice input, via an electret (specifically using this one: http://www.sparkfun.com/products/9964) ?
Thanks for your assistance!
Let me know what you make! and definitely let me know if you have questions!
I connected up the DAC as per your instructions. However, using the sketch in step 27, I don't get any sound through to my headphones (zero output). I find this odd as my serial monitor is giving me an endless stream of symbols (input from electret).
Please help, I have no idea what I could be doing wrong, may have missed something.
Oh, for now I'm just working on inputting voice, through a mic and out through headphones, manipulating it with arduino. This seems pointless at the moment but it will be implemented into a larger project with arduino at it's core. Will keep you updated as I go along.
Thanks again for your help :)
Thanks for the super clear images and directions.
not sure you have the unit sitting around that you could just set it up and go about your business there in the lab/office.
thanks again for the great work.
amanda
It says "time was not declared in this scope" in the following part.
void checkWetDry(){
PORTB &= 239;//set pin 12 low
time = 0;
while(digitalRead(12)){
wetDryPot = time;//from 0 to ~185
Can someone please help?
I have used the same values on the componentsa as you. But i am using electrolytic caps for the RC circuitry.. Maybe that doesn't work.
forward = newForward;//update direction
scale = newScale;//update scale
grain = newGrain;//update grain
is the output working now? it should just following the incoming signal.
try changing int scale = 10
does that give you half frequency playback?
int scale = 10 does not change anything.
The caps are .1µF