Pages: [1]   Go Down
Author Topic: FreqOut- Audio/Midi synth | MCP4725 I2C DAC  (Read 1919 times)
0 Members and 1 Guest are viewing this topic.
New York City, NY
Offline Offline
Full Member
***
Karma: 0
Posts: 101
Arduino Rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all, I am working on a project that involves reading 16 analog inputs to output musical note based on which of the sensors are touched, ...code copied from http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html. At the moment I am able to send midi note and I would like to add audio Out. This much I get...:http://itp.nyu.edu/physcomp/Labs/ToneOutput http://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation
Hardware:
8ohm speaker/piezo
resistor
to digital pin and ground.
Software:
pitches.h http://www.arduino.cc/playground/Main/Freqout
I have a file called pitches.h which contain the note frequencies.
That much I understand.
Now can I have both midi out and audio out that the same time, and how might I implement that?
I've also noticed that I'm getting multiple midi notes on one piezo sensor (not good),
Quote

I am thinking adding a capacitor to each input would fix that. Any thoughts?  

Thanks in advance
Caesar
« Last Edit: May 23, 2011, 08:44:49 pm by Pitchoilcan » Logged

================================
http://twit.tv/floss61
Think different
Think UbuntuStudio
============================

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 441
Posts: 23834
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How many notes do you want to sound at one time?
I believe you can do analogWrite(frequency) and it will go out as PWM until you stop the write.
(have not actually tried this myself, but I think it works that way, built in atmega hardware function).
Thus you have a fast loop that checks for a keypress, check a list of flags and see if you have a "free" PWM output, assign that note to the "free" PWM pin and set the flag to "in-use", next time thru the loop see if the key is still pressed, if not stop the note  with analogwrite(0) and set its flag to "free". (maybe watch how long its been in use and free after some time limit, so quasi-piano like vs organ/synthesizer?)
Take all the PWMs and mix together using a summing amplifer o-amp or similar:
http://masteringelectronicsdesign.com/how-to-derive-the-summing-amplifier-transfer-function/
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

New York City, NY
Offline Offline
Full Member
***
Karma: 0
Posts: 101
Arduino Rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One note per sensor. So in this case 16 notes. The original idea came to me after seeing Musical arduino Mididrumkithttp://todbot.com/blog/2006/10/29/spooky-arduino-projects-4-and-musical-arduino/. See schematic below. Output pin 1 is transmiting midi. For audio out I plan  to attach the speaker and resistor to PWM output pin 9 and ground. #include pitches.h and then.....????? Is it matter of doing digtalwrite on pin1 (TX) for midi and pin 9 for FREQOUT? I have a MCP4725 I2C DAC 12Bit DAC I picked up at sparkfun. I read somewhere it's good for implementing audio on musical instruments built using Arduino. At the moment all I have are two multiplexers reading Analog input 0-1 i.e. 16 inputs. I havn't included the DAC, or the port expander (as in midifootsteps) for the LED array yet. At this point I am concerned with PWM
« Last Edit: May 23, 2011, 08:45:20 pm by Pitchoilcan » Logged

================================
http://twit.tv/floss61
Think different
Think UbuntuStudio
============================

New York City, NY
Offline Offline
Full Member
***
Karma: 0
Posts: 101
Arduino Rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

code for a one octave sensor board
Quote
/*
   keyboard
 
  Plays a pitch that changes based on a changing analog input
 
  circuit:
  * 13 force-sensing resistors from +5V to analog in 0 through 5
  * 13 10K resistors from analog in 0 through 5 to ground
  * 8-ohm speaker on digital pin 8
 
  created 21 Jan 2010
  by Tom Igoe
 
  */

 #include "pitches.h"

 const int threshold = 10;    // minimum reading of the sensors that generates a note

 // notes to play, corresponding to the 3 sensors:
 int notes[] = {
   NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_D#4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_C3  };

 void setup() {

 }

 void loop() {
   for (int thisSensor = 0; thisSensor < 13; thisSensor++) {
     // get a sensor reading:
     int sensorReading = analogRead(thisSensor);

     // if the sensor is pressed hard enough:
     if (sensorReading > threshold) {
       // play the note corresponding to this sensor:
       tone(8, notes[thisSensor], 20);
     }
   }
   Serial.println();
 }
Logged

================================
http://twit.tv/floss61
Think different
Think UbuntuStudio
============================

Pages: [1]   Go Up
Jump to: