The Arduino Synthesizer

260,627

621

55

Introduction: The Arduino Synthesizer

About: I used to work for instructables.com, now I just make stuff. // follow me to see what I'm up to: https://www.echoechostudio.com



The Arduino is able to output sound through a library that has been developed called the Tone Library.

By creating an interface and a program that can call certain values to be output to an audio out, the Arduino Synthesizer is a robust tool for making a rudimentary noise machine. It uses granular synthesis techniques to generate a distinctive sound that can be a whole lot of fun for musicians, artists, tinkerers, and hobbyists.




Step 1: How It Works

Sound is created by playing the same sound grain, or samples (small pieces of around 1 to 50ms) over and over again at very high speed. Our ears and brains turn this into an audible hybrid of the repetition rate and the original grain, and it sounds like a constant tone.

The grain consists of two triangular waves of adjustable frequency, and adjustable decay rate.

The repetition rate is set by another control.

Step 2: Materials and Tools

To make this project, you will need the following things.

Parts:

(5X) 5K potentiometer
(5X) Potentiometer knobs
(3X) LEDs
(1X) SPDT switch
(1X) Light Dependent Photo Resistor
(1X) Arduino
(1X) Arduino Protoboard
(1X) Tactile Switch
(1X) Project enclosure
(1X) 1/8" Audio Jack
(1X) a whole lot of solid core wire
(1X) heat shrink
(1X) breadboard
(1X) jumper wire
(3X) 10K ohm resistors
(3X) 220 resistors
(1X) 9V battery
(1X) 9V battery clip
(1X) size M coaxial DC power plug

Tools:

  • soldering iron
  • solder
  • flux
  • glue
  • multimeter
  • drill

Step 3: Code, Circuit Diagram, and Power.

I have attached the code for the Arduino to this Instructable. You will need a USB 2.0 to upload it to your board. After you have uploaded the code from your computer, go ahead and attach the Proto Shield to your Arduino. 

You have many options when it comes to power. The Arduino is capable of running on a 9v wall wart power supply, or you may use a 9V battery with a battery clip to a size M coaxial DC power plug. You may also power via your USB cable.

The circuit diagram was made with Fritzing, it has also been attached to this step.

Step 4: Using a Breadboard.

By using a breadboard to build the circuit first, it is much easier to transfer the circuit to your Protoboard later. Run wires from the GND and 5V to the - and + rails of your breadboard.

Then, connect the signal wires from the potentiometers to Analog Input 0-4 on the Arduino. The right and left side leads will get connected to the ground rail, and positive rail of the breadboard.

Connecting the potentiometers will control the grain, frequency, and decay of the synthesizer.

Analog in 0: Grain 1 pitch
Analog in 1: Grain 2 decay

Analog in 2: Grain 1 decay
Analog in 3: Grain 2 pitch

Analog in 4: Grain repetition frequency

Step 5: Wire Your Audio Jack.

Solder wires to the your 1/8" mono audio jack, make your leads fairly long. Connect your positive lead to PWM~ 3 on the Arduino. You will need a 10K ohm resistor between the arduino board and the positive lead of your audio jack. Connect the negative lead of your jack to ground rail of the breadboard.

Step 6: Connect Your Photoresistor.

One lead of your photoresistor is wired directly to your 5V positive rail on the breadboard, as well as Analog Input 5 on the Arduino. The other lead of the photoresistor is connected to a 10K ohm resisted ground rail.

Step 7: Connect a SPDT Switch.

Connect the signal, middle, lead of your SPDT switch to Digital pin 02 on the Arduino. The remaining leads are connected to ground, and the 5V positive rail that is resisted by a 10K ohm resistor.

Step 8: Wire the Tactile Switch.

The tactile switch has four leads. Allow the switch to straddle the bridge of the breadboard. Connect one of the two parallel pins to your 5V positive rail on the bread board, and the other to a 10K ohm resisted ground pin.  The last connection of your tactile switch connects a signal wire between the switch and Digital Pin 6 on the Arduino.

Step 9: Connect the LEDs.

Step 10: Test It!

This is the completed breadboarded circuit. Test with a pair of headphones, or connect to a small speaker. If you are using headphones, this is a mono output, and it will be loud. Do not put your headphones directly near your ear when firing up this synth.

Step 11: Drill the Enclosure.

Drill out holes in the project enclosure for each of the components that were placed in the breadboard. I used a gold paint pen to mark where I wanted my holes.

Drill five holes for the potentiometers.

Five small holes in a square for the tactile switch.

Three pairs of small holes for each of the LEDs

Two holes close together for the photoresistor.

One hole for your audio jack.

One additional hole for the SPDT switch.

Step 12: Start Adding Components to the Enclosure.

Thread the five potentiometers through the holes that have been drilled, then secure them into place.


Step 13: Add the Rest of the Components.

Secure the LEDs, SPDT switch, tactile switch, audio jack, and photoresistor into place. A dab of hot glue worked great to quickly mount all of these components.

Step 14: Wire the Audio Jack to the Protoboard.

The next few steps outline how to move the circuit from the breadboard to the Protoboard. Because all of your components are secured to the enclosure, it will be simple to run wires from your components to the board.

Solder lead wires to all of the components within the the enclosure, using red and black wires respectively to denote which leads are positive and negative.

On the Protoboard, connect one wire to digital pin 3, and solder into place, run a jumper wire to the center of the board so that you may break the line with the same 10K ohm resistor from the breadboard.

When you solder these into place, make sure you drop enough solder on to the board to connect the wire to the resistor.

Step 15: Solder in the Resistors for Photo Resistor, Tactile Switch, and SPDT Switch

Extend two jumper wires from the ground rail, and a jumper wire from the positive rail, out to the middle of the board. Form connections to your remaining 10K ohm resistors.

Connect a small jumper wire from Analog 5 that will run to the lead of the photo resistor.

Step 16: Solder Your LEDs Into Place

Connect 3 220 Ohm resisotrs to pins 9-11 on the Protoboard, sink the other ends of the resistors into the open holes of the protoboard, and then solder those wires to you LEDs.

Daisy chain the ground wires for the LEDs, then run a single grounding wire back to the ground rail on the Protoboard.

Step 17: Wire the Potentiometers to the Protoboard.

Daisy chain the positive and ground leads from the potentiometers together, then insert them into their respective rails on the Protoboard.

Wire the signal wires of the potentiometers to Analog 0-4, I kept the grain and frequency knobs on the first row of knobs, and the sync knobs below them.

Again, the signal wires sync accordingly:

Analog in 0: Grain 1 pitch
Analog in 1: Grain 2 decay

Analog in 2: Grain 1 decay
Analog in 3: Grain 2 pitch

Analog in 4: Grain repetition frequency

Step 18: Attach Your Knobs to Your Potentiometers.

Zero all of your potentiometers out, then align the line on the knob with the zero position on the potentiometer shaft.

Using a small flathead screwdriver, attach your potentiometer knobs.


Step 19: Connect the Protoboard to the Arduino.

Connect the short jumper wires on the Protoboard to the long leads in the enclosure. Solder the remaining wires to the ground rail, and 5V rail on the Protoboard, respectively.

Snap the Protoboard into place on top of the Arduiono.

Plug it in, seal it up, and you're ready to jam!

Step 20: Play With It!

All of the switches and potentiometers are completely interchangeable! instead of using all those potentiometers try replacing each of them with photo resistors, or combinations of the two.

References:
http://blog.lewissykes.info/daves-auduino/
http://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation
http://arduino.cc/en/Tutorial/Tone
http://itp.nyu.edu/physcomp/Labs/ToneOutput
http://code.google.com/p/tinkerit/wiki/Auduino

Make It Real Challenge

Participated in the
Make It Real Challenge

4 People Made This Project!

Recommendations

  • For the Home Contest

    For the Home Contest
  • Make It Bridge

    Make It Bridge
  • Big and Small Contest

    Big and Small Contest

55 Comments

0
electricinsect
electricinsect

3 years ago

can someone copy the whole arduino sketch in the comments? I can't open the .ino file unfortunately :(

0
ronaldsheaks
ronaldsheaks

Reply 3 years ago

// Auduino, the Lo-Fi granular synthesiser
//
// by Peter Knight, Tinker.ithttp://tinker.it
//
// Help: http://code.google.com/p/tinkerit/wiki/Auduino
// More help: http://groups.google.com/group/auduino
//
// Analog in 0: Grain 1 pitch
// Analog in 1: Grain 2 decay
// Analog in 2: Grain 1 decay
// Analog in 3: Grain 2 pitch
// Analog in 4: Grain repetition frequency
//
// Digital 3: Audio out (Digital 11 on ATmega8)
//
// Changelog:
// 19 Nov 2008: Added support for ATmega8 boards
// 21 Mar 2009: Added support for ATmega328 boards
// 7 Apr 2009: Fixed interrupt vector for ATmega328 boards
// 8 Apr 2009: Added support for ATmega1280 boards (Arduino Mega)
// 11 Mar 2012: edit code to fit corresponding Fritzing diagram.
/*
10/07/10 Prodical contributed:
- additional mapping modes - diatonic major and minor and pentatonic major and minor
- switchable between modes by a single button which cycles through each and differentiates by an LED blinking as per the mode number
- a light dependent resistor (LDR) - calibrated in the first five seconds after switching on - replacing the main (grain repetition) frequency pot on a switch (using an external interrupt) with an LED indicator when it’s active but which also dims according on the LDR value
more details at http://blog.lewissykes.info
*/
/*
Calibration
Demonstrates one techinque for calibrating sensor input. The
sensor readings during the first five seconds of the sketch
execution define the minimum and maximum of expected values
attached to the sensor pin.
The sensor minumum and maximum initial values may seem backwards.
Initially, you set the minimum high and listen for anything
lower, saving it as the new minumum. Likewise, you set the
maximum low and listen for anything higher as the new maximum.
The circuit:
* Analog sensor (potentiometer will do) attached to analog input 0
* LED attached from digital pin 9 to ground
created 29 Oct 2008
By David A Mellis
Modified 17 Jun 2009
By Tom Igoe
http://arduino.cc/en/Tutorial/Calibration
This example code is in the public domain.
*/
// AUDUINO code STARTS
#include <avr/io.h>
#include <avr/interrupt.h>
uint16_t syncPhaseAcc;
uint16_t syncPhaseInc;
uint16_t grainPhaseAcc;
uint16_t grainPhaseInc;
uint16_t grainAmp;
uint8_t grainDecay;
uint16_t grain2PhaseAcc;
uint16_t grain2PhaseInc;
uint16_t grain2Amp;
uint8_t grain2Decay;
// Map Analogue channels
#define SYNC_CONTROL (4)
#define GRAIN_FREQ_CONTROL (3)
#define GRAIN_DECAY_CONTROL (2)
#define GRAIN2_FREQ_CONTROL (1)
#define GRAIN2_DECAY_CONTROL (0)
// Changing these will also requires rewriting audioOn()
#if defined(__AVR_ATmega8__)
//
// On old ATmega8 boards.
// Output is on pin 11
//
#define LED_PIN 13
#define LED_PORT PORTB
#define LED_BIT 5
#define PWM_PIN 11
#define PWM_VALUE OCR2
#define PWM_INTERRUPT TIMER2_OVF_vect
#elif defined(__AVR_ATmega1280__)
//
// On the Arduino Mega
// Output is on pin 3
//
#define LED_PIN 13
#define LED_PORT PORTB
#define LED_BIT 7
#define PWM_PIN 3 //3
#define PWM_VALUE OCR3C
#define PWM_INTERRUPT TIMER3_OVF_vect
#else
//
// For modern ATmega168 and ATmega328 boards
// Output is on pin 3
//
#define PWM_PIN 3 //3
#define PWM_VALUE OCR2B
#define LED_PIN 13
#define LED_PORT PORTB
#define LED_BIT 5
#define PWM_INTERRUPT TIMER2_OVF_vect
#endif
// AUDUINO code ENDS
// BUTTON, SWITCH, LDR & LEDs - START
// Button
#define BUTTON_PIN (6) // the number of the pushbutton pin
int buttonValue; // variable for reading the button status
int buttonState; // variable to hold the button state
int mapMode = 0; // What scale/mapping mode is in use?
// LDR
//#define LDRSWITCH (4)
// switch replaced by external interrupt
volatile int LDRswitchState = LOW;
#define LDR_PIN (5)
#define LDRLED_PIN (9)
//Callibration variables
int LDRValue = 0; // the sensor value
int LDRMin = 1023; // minimum sensor value
int LDRMax = 0; // maximum sensor value
// PWM_VALUE LED
#define FRQLED_PIN (11) // not as consistent as pin 13
// mapmode LED
#define mapModeLED_PIN (10) // the number of the LED pin
int mapModeLEDState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
int BlinkRate = 5; // no of blinks per second i.e. fps - empirically tested as just slow enough to count
int BlinkCount = 0; // variable to store no of blinks
int BlinkLoopLength = 14; // err... blink loop length
// BUTTON, SWITCH, LDR & LEDs - ENDS
// MAPPINGS - START
// Smooth logarithmic mapping
//
uint16_t antilogTable[] = {
64830,64132,63441,62757,62081,61413,60751,60097,59449,58809,58176,57549,56929,56316,55709,55109,
54515,53928,53347,52773,52204,51642,51085,50535,49991,49452,48920,48393,47871,47356,46846,46341,
45842,45348,44859,44376,43898,43425,42958,42495,42037,41584,41136,40693,40255,39821,39392,38968,
38548,38133,37722,37316,36914,36516,36123,35734,35349,34968,34591,34219,33850,33486,33125,32768
};
uint16_t mapPhaseInc(uint16_t input) {
return (antilogTable[input & 0x3f]) >> (input >> 6);
}
// Stepped chromatic mapping
//
uint16_t midiTable[] = {
0,17,18,19,20,22,23,24,26,27,29,31,32,34,36,38,41,43,46,48,51,54,58,61,65,69,73,
77,82,86,92,97,103,109,115,122,129,137,145,154,163,173,183,194,206,218,231,
244,259,274,291,308,326,346,366,388,411,435,461,489,518,549,581,616,652,691,
732,776,822,871,923,978,1036,1097,1163,1232,1305,1383,1465,1552,1644,1742,
1845,1955,2071,2195,2325,2463,2610,2765,2930,3104,3288,3484,3691,3910,4143,
4389,4650,4927,5220,5530,5859,6207,6577,6968,7382,7821,8286,8779,9301,9854,
10440,11060,11718,12415,13153,13935,14764,15642,16572,17557,18601,19708,20879,
22121,23436,24830,26306,27871
};
uint16_t mapMidi(uint16_t input) {
return (midiTable[(1023-input) >> 3]);
}
//// Stepped Pentatonic mapping
//
uint16_t pentatonicTable[54] = {
0,19,22,26,29,32,38,43,51,58,65,77,86,103,115,129,154,173,206,231,259,308,346,
411,461,518,616,691,822,923,1036,1232,1383,1644,1845,2071,2463,2765,3288,
3691,4143,4927,5530,6577,7382,8286,9854,11060,13153,14764,16572,19708,22121,26306
};
uint16_t mapPentatonic(uint16_t input) {
uint8_t value = (1023-input) / (1024/53);
return (pentatonicTable[value]);
}
// Lewis added - I've got an Excel spreadsheet with these workings out on my blog...
// Stepped major Diatonic mapping
//
uint16_t majordiatonicTable[76] = {
0,17,19,22,23,26,29,32,34,38,43,46,51,58,65,69,77,86,92,103,115,129,137,154,173,183,206,231,259,274,308,346,366,
411,461,518,549,616,691,732,822,923,1036,1097,1232,1383,1465,1644,1845,2071,2195,2463,2765,2930,3288,
3691,4143,4389,4927,5530,5859,6577,7382,8286,8779,9854,11060,11718,13153,14764,16572,17557,19708,22121,23436,26306
};
uint16_t mapmajorDiatonic(uint16_t input) {
uint8_t value = (1023-input) / (1024/53);
return (majordiatonicTable[value]);
}
// Stepped minor Diatonic mapping
//
uint16_t minordiatonicTable[76] = {
0,17,19,20,23,26,27,31,34,38,41,46,51,54,61,69,77,82,92,103,109,122,137,154,163,183,206,218,244,274,308,326,366,
411,435,489,549,616,652,732,822,871,978,1097,1232,1305,1465,1644,1742,1955,2195,2463,2610,2930,3288,
3484,3910,4389,4927,5220,5859,6577,6968,7821,8779,9854,10440,11718,13153,13935,15642,17557,19708,20879,23436,26306
};
uint16_t mapminorDiatonic(uint16_t input) {
uint8_t value = (1023-input) / (1024/53);
return (minordiatonicTable[value]);
}
// Stepped major Pentatonic mapping
//
uint16_t majorpentatonicTable[55] = {
0,17,19,22,26,29,34,38,43,51,58,69,77,86,103,115,137,154,173,206,231,274,308,346,
411,461,549,616,691,822,923,1097,1232,1383,1644,1845,2195,2463,2765,3288,
3691,4389,4927,5530,6577,7382,8779,9854,11060,13153,14764,17557,19708,22121,26306
};
uint16_t mapmajorPentatonic(uint16_t input) {
uint8_t value = (1023-input) / (1024/53);
return (majorpentatonicTable[value]);
}
// Stepped minor Pentatonic mapping
//
uint16_t minorpentatonicTable[55] = {
0,17,20,23,26,31,34,41,46,51,61,69,82,92,103,122,137,163,183,206,244,274,326,366,
411,489,549,652,732,822,978,1097,1305,1465,1644,1955,2195,2610,2930,3288,
3910,4389,5220,5859,6577,7821,8779,10440,11718,13153,15642,17557,20879,23436,26306
};
uint16_t mapminorPentatonic(uint16_t input) {
uint8_t value = (1023-input) / (1024/53);
return (pentatonicTable[value]);
}
// MAPPINGS - END
void audioOn() {
#if defined(__AVR_ATmega8__)
// ATmega8 has different registers
TCCR2 = _BV(WGM20) | _BV(COM21) | _BV(CS20);
TIMSK = _BV(TOIE2);
#elif defined(__AVR_ATmega1280__)
TCCR3A = _BV(COM3C1) | _BV(WGM30);
TCCR3B = _BV(CS30);
TIMSK3 = _BV(TOIE3);
#else
// Set up PWM to 31.25kHz, phase accurate
TCCR2A = _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS20);
TIMSK2 = _BV(TOIE2);
#endif
}
void setup() {
pinMode(PWM_PIN,OUTPUT);
audioOn();
pinMode(LDRLED_PIN,OUTPUT);
pinMode(FRQLED_PIN,OUTPUT);
pinMode(mapModeLED_PIN,OUTPUT);
pinMode(BUTTON_PIN,INPUT);
attachInterrupt(0, LDRswitched, CHANGE);
// Calibration
//Serial.begin(9600);
// turn on LED to signal the start of the calibration period:
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
// calibrate during the first five seconds
while (millis() < 5000) {
LDRValue = analogRead(LDR_PIN);
// record the maximum sensor value
if (LDRValue > LDRMax) {
LDRMax = LDRValue;
}
// record the minimum sensor value
if (LDRValue < LDRMin) {
LDRMin = LDRValue;
}
}
// signal the end of the calibration period
digitalWrite(9, LOW);
// END calibration code
}
void LDRswitched()
{
LDRswitchState = !LDRswitchState;
}
void loop() {
// The loop is pretty simple - it just updates the parameters for the oscillators.
//
// Avoid using any functions that make extensive use of interrupts, or turn interrupts off.
// They will cause clicks and poops in the audio.
// Smooth frequency mapping
//syncPhaseInc = mapPhaseInc(analogRead(SYNC_CONTROL)) / 4;
// Stepped mapping to MIDI notes: C, Db, D, Eb, E, F...
//syncPhaseInc = mapMidi(analogRead(SYNC_CONTROL));
// // Stepped pentatonic mapping: D, E, G, A, B
// syncPhaseInc = mapPentatonic(analogRead(SYNC_CONTROL));
// could add switch here to choose between midiIn() and the twisty-pot pitch control
//BEGIN Calibration
// read the sensor:
LDRValue = analogRead(LDR_PIN);
// apply the calibration to the sensor reading
LDRValue = map(LDRValue, LDRMin, LDRMax, 0, 1023);
// in case the sensor value is outside the range seen during calibration
LDRValue = constrain(LDRValue, 0, 1023);
// // fade the LED using the calibrated value: (this moved below)
// analogWrite(LDRLED_PIN, LDRValue);
// Serial.println(LDRValue);
//END Calibration
// button presses cycle through scales/mapping modes
buttonValue = digitalRead(BUTTON_PIN); // read input value and store it in val
if (buttonValue != buttonState) { // the button state has changed!
if (buttonValue == 0) { // check if the button is pressed
if (mapMode == 0) { // if set to smooth logarithmic mapping
mapMode = 1; // switch to stepped chromatic mapping
}
else {
if (mapMode == 1) { // if stepped chromatic mapping
mapMode = 2; // switch to stepped major Diatonic mapping
}
else {
if (mapMode == 2) { // if stepped major Diatonic mapping
mapMode = 3; // switch to stepped minor Diatonic mapping
}
else {
if (mapMode == 3) { // if stepped minor Diatonic mapping
mapMode = 4; // switch to stepped major Pentatonic mapping
}
else {
if (mapMode == 4) { // if stepped major Pentatonic mapping
mapMode = 5; // switch to stepped minor Pentatonic mapping
}
else {
if (mapMode == 5) { // if stepped major Pentatonic mapping
mapMode = 0; // switch back to smooth logarithmic mapping
}
}
}
}
}
}
}
buttonState = buttonValue; // save the new state in our variable
}
// mapMode LED indicator - blinks number of scale/mapping mode on a fixed 'frame' cycle
if (millis() - previousMillis > 1000/BlinkRate)
{
BlinkCount = BlinkCount + 1;
// save the last time you blinked the LED
previousMillis = millis();
digitalWrite(mapModeLED_PIN, LOW);
if (BlinkCount <= (mapMode+1)*2)
{
//if the LED is off turn it on and vice-versa:
if (mapModeLEDState == LOW)
{
mapModeLEDState = HIGH;
}
else{
mapModeLEDState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(mapModeLED_PIN, mapModeLEDState);
}
// resets Blink loop after 14 blinks
else if (BlinkCount >= BlinkLoopLength)
{
BlinkCount = 0;
}
//debug
//Serial.println(BlinkCount);
}
//Map modes to select with button. LED blinks as per mode currently in use
//selects which array to pull data from to get SyncPhaseInc
//1. Smooth logarithmic mapping
if (mapMode == 0) {
if (LDRswitchState == HIGH) {
syncPhaseInc = mapPhaseInc(1023-LDRValue) / 4;
analogWrite(LDRLED_PIN, LDRValue);
}
else
{
syncPhaseInc = mapPhaseInc(analogRead(SYNC_CONTROL)) / 4;
digitalWrite(LDRLED_PIN, LOW);
}
}
//2. Stepped chromatic mapping to MIDI notes: C,C#,D,Eb,F,F#,G,Ab,A,Bb,B
if (mapMode == 1) {
if (LDRswitchState == HIGH) {
syncPhaseInc = mapMidi(1023-LDRValue);
analogWrite(LDRLED_PIN, LDRValue);
}
else
{
syncPhaseInc = mapMidi(analogRead(SYNC_CONTROL));
digitalWrite(LDRLED_PIN, LOW);
}
}
//3. Stepped major Diatonic mapping: C,D,E,F,G,A,B
if (mapMode == 2) {
if (LDRswitchState == HIGH) {
syncPhaseInc = mapmajorDiatonic(1023-LDRValue);
analogWrite(LDRLED_PIN, LDRValue);
}
else
{
syncPhaseInc = mapmajorDiatonic(analogRead(SYNC_CONTROL));
digitalWrite(LDRLED_PIN, LOW);
}
}
//4. Stepped minor Diatonic mapping: C,D,Eb,F,G,Ab,Bb
if (mapMode == 3) {
if (LDRswitchState == HIGH) {
syncPhaseInc = mapminorDiatonic(1023-LDRValue);
analogWrite(LDRLED_PIN, LDRValue);
}
else
{
syncPhaseInc = mapminorDiatonic(analogRead(SYNC_CONTROL));
digitalWrite(LDRLED_PIN, LOW);
}
}
//5. Stepped major Pentatonic mapping
if (mapMode == 4) {
if (LDRswitchState == HIGH) {
syncPhaseInc = mapmajorPentatonic(1023-LDRValue);
analogWrite(LDRLED_PIN, LDRValue);
}
else
{
syncPhaseInc = mapmajorPentatonic(analogRead(SYNC_CONTROL));
digitalWrite(LDRLED_PIN, LOW);
}
}
//6. Stepped major Diatonic mapping
if (mapMode == 5) {
if (LDRswitchState == HIGH) {
syncPhaseInc = mapminorPentatonic(1023-LDRValue);
analogWrite(LDRLED_PIN, LDRValue);
}
else
{
syncPhaseInc = mapminorPentatonic(analogRead(SYNC_CONTROL));
digitalWrite(LDRLED_PIN, LOW);
}
}
//input from pots
grainPhaseInc = mapPhaseInc(analogRead(GRAIN_FREQ_CONTROL)) / 2;
grainDecay = analogRead(GRAIN_DECAY_CONTROL) / 8;
grain2PhaseInc = mapPhaseInc(analogRead(GRAIN2_FREQ_CONTROL)) / 2;
grain2Decay = analogRead(GRAIN2_DECAY_CONTROL) / 4;
digitalWrite(FRQLED_PIN, PWM_VALUE);
}
SIGNAL(PWM_INTERRUPT)
{
uint8_t value;
uint16_t output;
syncPhaseAcc += syncPhaseInc;
if (syncPhaseAcc < syncPhaseInc) {
// Time to start the next grain
grainPhaseAcc = 0;
grainAmp = 0x7fff;
grain2PhaseAcc = 0;
grain2Amp = 0x7fff;
LED_PORT ^= 1 << LED_BIT; // Faster than using digitalWrite
}
// Increment the phase of the grain oscillators
grainPhaseAcc += grainPhaseInc;
grain2PhaseAcc += grain2PhaseInc;
// Convert phase into a triangle wave
value = (grainPhaseAcc >> 7) & 0xff;
if (grainPhaseAcc & 0x8000) value = ~value;
// Multiply by current grain amplitude to get sample
output = value * (grainAmp >> 8);
// Repeat for second grain
value = (grain2PhaseAcc >> 7) & 0xff;
if (grain2PhaseAcc & 0x8000) value = ~value;
output += value * (grain2Amp >> 8);
// Make the grain amplitudes decay by a factor every sample (exponential decay)
grainAmp -= (grainAmp >> 8) * grainDecay;
grain2Amp -= (grain2Amp >> 8) * grain2Decay;
// Scale output to the available range, clipping if necessary
output >>= 9;
if (output > 255) output = 255;
// Output to PWM (this is faster than using analogWrite)
PWM_VALUE = output;
}

0
ronaldsheaks
ronaldsheaks

Tip 3 years ago

I suggest just going as far as the breadboard unless you are at least intermediate level in electronics, I recreated the circuit with a permaboard PCB and it would power the Arduino off.

0
PhonX1
PhonX1

Question 4 years ago

I can't download tone library where the zip file?

0
AAxelB
AAxelB

Question 5 years ago

Hello everyone, I started with arduino and electronics, I tried this editing but it does not seem to work. I use potenciometers 10k, I think the problem comes from there, is it possible with some modifications in the code, to run this circuit with pot10k?

Thank you for your help !

0
claude_cundiff
claude_cundiff

6 years ago

This is great! Thank you! One of my goals before my departure from this world is to recreate the TB303 and perhaps make my own synths...so I guess that's more than one item in the ole bucket list.

0
LoekJ
LoekJ

6 years ago

could you tell me what to do when you get this error?

Arduino: 1.8.1 (Windows 10), Board:"Arduino/Genuino Uno"

De schets gebruikt 4324 bytes (13%) programma-opslagruimte. Maximum is 32256 bytes.
Globale variabelen gebruiken 967 bytes (47%) van het dynamisch geheugen. Resteren 1081 bytes voor lokale variabelen. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "\\.\COM4": Het systeem kan het opgegeven bestand niet vinden.

The translation:

Sketch Uses 4324 bytes (13%) program storage. Max is 32256 bytes.
Global variables using 967 bytes (47%) of the dynamic memory. This leaves 1081 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open (): Unable to open device "\\ \ COM4.": The System Can not Find The specified file.


Probleem bij het uploaden naar het board. Zie http://www.arduino.cc/en/Guide/Troubleshooting#up... voor suggesties.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
0
sergio4688
sergio4688

6 years ago

In addition to the input Jack, How could add another input Mini Jack?

0
ColinM74
ColinM74

6 years ago

could you tell me what values the photoresistor needs please?

0
licheong
licheong

6 years ago

When the output connect it to headphone, it is too loud because it is speaker-out level. Better add a 10k-1k resistor divider to protect your headphone!

0
ninuxi
ninuxi

7 years ago

I've play my bike With this arduino synth and Ipad with audiobus (Caramel, Stereo Designer, Muckraker, GliderVerb) https://youtu.be/mlR3V7W1JzA

0
solohust
solohust

7 years ago

All the links to RadioShack 404.

0
leolodreamland
leolodreamland

7 years ago

i cannot compile this. added the latest tone library but it just sticks compiling. tried classic 1.05 and classic 1.06 as well as latest full...

0
leolodreamland
leolodreamland

Reply 7 years ago

arduin uno btw

0
mathesen1097
mathesen1097

8 years ago on Introduction

What do the switches, photoresistor, and leds do? I wanted to replace the photoresistor with a distance sensor that used a laser and phototransistor.

0
randelia
randelia

9 years ago on Introduction

Code does not work on Leonardo. Code uses timer2 - leonardo does not have a timer2.
Does anyone have an update for how to run this on a Leonardo? I read something about using timer3 & tuning it's 16bit timer as compared to timer2 being 8bit...
Using Arduino 1.0.5 IDE - i get these compiler errors (all relating to timer2):
sketch_dec10b.ino: In function 'void audioOn()':
sketch_dec10b:259: error: 'TCCR2A' was not declared in this scope
sketch_dec10b:259: error: 'COM2B1' was not declared in this scope
sketch_dec10b:259: error: 'WGM20' was not declared in this scope
sketch_dec10b:260: error: 'TCCR2B' was not declared in this scope
sketch_dec10b:260: error: 'CS20' was not declared in this scope
sketch_dec10b.ino: In function 'void loop()':
sketch_dec10b:481: error: 'OCR2B' was not declared in this scope
sketch_dec10b.ino: In function 'void TIMER2_OVF_vect()':
sketch_dec10b:525: error: 'OCR2B' was not declared in this scope

0
AlexD6
AlexD6

Reply 8 years ago on Introduction

Did you ever find a solution? I'm trying to use a micro arduino and am having the same issue.