Show Posts
Pages: [1] 2 3
1  Using Arduino / Audio / Re: Rogue tone library, mega 2560 r3 and millis() simple problem on: April 08, 2013, 05:44:26 pm
I believe that did the trick, I'll be able to tell more once I get further along with the envelopes and the hardware.

I also took out all the library inclusions in the .cpp, this seems to work:

#include <arduino.h>
#include "Tone.h"
2  Using Arduino / Audio / Re: Rogue tone library, mega 2560 r3 and millis() simple problem on: April 08, 2013, 09:14:23 am
https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

here it is, I think the problem may be in the .cpp, and not identifying the mega 2560,
changing this:

#if defined(__AVR_ATmega1280__)

to this:

#if defined(__AVR_ATmega1280__)||(__AVR_ATmega2560__)

might have fixed it, I'll test it this afternoon.
3  Using Arduino / Audio / Rogue tone library, mega 2560 r3 and millis() simple problem on: April 07, 2013, 09:48:45 pm
I'm finally managing to isolate what has been messing with me with a project and it's been driving me nuts chasing it.

Anyway, using the tone library and enabling any more than two tones (on a Mega 2560 with 6 timers), causes it to not work. I've looked at the cpp, read up on timer pins and conflicts and have tried a load of variations, but it comes down to this:

Put an indicator LED in pin 40 with the - leg tied to ground thru a 1k resistor, and toggle on 

Tone tone3;
Tone tone4;

Presto! no longer works.

smiley-sad

Anybody have any ideas?


Code:
#include <Tone.h>
int blinker = 40;
unsigned long lastTime;
int blinkerState = LOW;
int wait = 200;
Tone tone1;
Tone tone2;
//Tone tone3;
//Tone tone4;
void setup()
{
  pinMode(blinker, OUTPUT);
  tone1.begin(7);
  tone2.begin(6);
//  tone3.begin(5);
//  tone4.begin(4);
}
//__________________________________________________________LOOP 
void loop()
{
  unsigned long currentMillis=millis();
  if ((currentMillis - lastTime) >=  wait)
  {
    lastTime=currentMillis;
    {
      if (blinkerState == LOW)
      {
        blinkerState = HIGH;
      }
      else
      {
        blinkerState = LOW;

      }
      digitalWrite(blinker, blinkerState);
   }
  }
}
4  Using Arduino / Project Guidance / Re: Mega 2560 r3 and polyphonic tones on: April 07, 2013, 07:19:11 pm
I got it. It works just fine if I only enable 2 voices.
If anyone can help me get the 4 I was hoping for out of this project I would be grateful and would certainly share all the filter specs once I get it going.


code, fwiw

Code:
//tonetoy r0001


#include <SoftwareSerial.h>
#include <serLCD.h>
#include <SPI.h>
#include <Tone.h>
 
 //________________________________________________pins!
 
  //spi slave select
const int slaveSelectPin = 53;
const int selectButton = 31;
const int playButton = 30;
// Set pin to the LCD's rxPin
int pin = 18;
serLCD lcd(pin);

int blinker = 40;

//_________________________________________________timing stuff
int menuUpdate = 100;
long menuRefresh = millis();
//last time note played
   long lastTime[4] = {0,0,0,0};

//__________________________________________________noteplayer stuff
int voice;
int numVoices = 4;
Tone NotePlayer[4];
int PlayNote;
//noteplayers on/off
boolean active = false;

#define scaleC 0
#define scaleC# 1
#define scaleD 2
#define scaleD# 3
#define scaleE 4
#define scaleF 5
#define scaleF# 6
#define scaleG 7
#define scaleG# 8
#define scaleA 9
#define scaleA# 10
#define scaleB 11

//Scale bitmasks
   int modeCode[] = {
    2773, 2906, 3670, 2937, 3498, 2457, 2418, 4095, 3289, 3243, 2922, 3449, 2777, 2905, 3170, 2875,
    2873, 3162, 2840, 3434, 2742, 3352, 2774, 3413, 3417, 3510, 3305, 3290, 2726, 2642, 3250, 2869, 2730
   };
      //key offsets
   int keyOffset[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
   //notes
    //NOTES
   int Notes[] = {
NOTE_B0, NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_DS1, NOTE_E1, NOTE_F1, NOTE_FS1,
NOTE_G1, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_B1, NOTE_C2, NOTE_CS2, NOTE_D2, NOTE_DS2,
NOTE_E2, NOTE_F2, NOTE_FS2, NOTE_G2, NOTE_GS2, NOTE_A2, NOTE_AS2, NOTE_B2, NOTE_C3,
NOTE_CS3, NOTE_D3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3, NOTE_G3, NOTE_GS3, NOTE_A3,
NOTE_AS3, NOTE_B3, NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4,
NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5,
NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6,
NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6,
NOTE_AS6, NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7,
NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7, NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8
 };

//______________________________________________________________menus and parameters
int pointer;
 // main menu string 10 options
 int menuOptions = 10;
 int Mode = 0;
 int Key = 1;
 int Top = 2;
 int Bottom = 3;
 int Length = 4;
 int Odds = 5;
 int Attack = 6;
 int Decay = 7;
 int Sustain = 8;
 int Release = 9;
//main menu
  char* menuString[]={"Mode ", "Key     ", "Top     ", "Bottom  ", "Length  ",
"Odds    ", "Attack  ","Decay   ","Sustain ","Release "};

//mode menu 33 modes
 char* modeString[]={"Major       ", "Minor       ", "Adonai      ", "Algerian    ",
 "Altered     ", "Augmented   ", "Blues       ", "Chromatic   ", "Arabic      ", "Enigmatic   ",
 "HalfDim     ", "Bebop       ", "HarmMaj     ", "HarmMin     ", "Hirajoshi   ", "HuGypsy     ",
 "HuMinor     ", "Insen       ", "Iwato       ", "Locrian     ", "Lydian      ", "Hemitonic   ",
 "Mixolydian  ", "NeaMajor    ", "NeaMinor    ", "Octatonic   ", "Persian     ", "Phrygian    ",
 "Prometheus  ", "Slendro     ", "Tritone     ", "UkrDorian   ", "WholeTone   "};
 
  //Keys submenu 12 keys
   char* keyString[]={
 "C        ", "CS       ", "D        ", "DS       ", "E        ", "F        ",
 "FS       ", "G        ", "GS       ", "A        ", "AS       ", "B        " };
 
    //main parameter holder array
    //random start values
   int settingsGrid[4][10] = {
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
   };
   
   //_________________________________________________________SETUP
   
   void setup()
{


randomSeed(analogRead(0));
  //signal LED
pinMode(40, OUTPUT);
  pinMode(playButton, INPUT);
  pinMode(selectButton, INPUT);
lcd.clear();
//slave select spi
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();
}
 //__________________________________________________________LOOP 
  void loop()
{
 digitalWrite(blinker, LOW);
   //menu refresh delay timer
   if( (long)( millis() - (menuRefresh)+menuUpdate ) >= 0)
   {
   menuRefresh = millis();
   //LCD commands
lcd.setCursor(1, 1);
lcd.print("Voice");
lcd.setCursor(1, 8);
voice = (analogRead(1)/256);
lcd.print((voice+1));
  //Line 2 of display 
lcd.setCursor(2,1);
pointer = (analogRead(2)/103);
lcd.print(menuString[pointer]);
// Menu scrolling
if (pointer == 0)
 {
      lcd.print(modeString[settingsGrid[voice][pointer]]);
 };
 if (pointer == 1)
{
   lcd.print(keyString[settingsGrid[voice][pointer]]);
}
if (pointer >= 2)
{
    lcd.print(settingsGrid[voice][pointer]);
lcd.print("      ");
}
   }
   
//ENTER DATA
while (digitalRead(selectButton) == HIGH)
 {
 switch (pointer)
 {
 case 0:
    settingsGrid[voice][pointer] = (analogRead(2)/31.5);
     lcd.setCursor(2,6);
   lcd.print(modeString[settingsGrid[voice][pointer]]);
   break;
  case 1:
 settingsGrid[voice][pointer] = (analogRead(2)/86);
      lcd.setCursor(2,9);
 lcd.print(keyString[settingsGrid[voice][pointer]]);
   break;
case 2:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 3:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 4:
  settingsGrid[voice][pointer] = (((analogRead(2)/8)*10)+50);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 5:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 6:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
      lcd.setCursor(2,9);
      lcd.print(settingsGrid[voice][pointer]);
      lcd.print("   ");
break;
case 7:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 8:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
  case 9:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
 }
 }
  //NOTE SELECT, INITIALIZE PLAY, ADSR LOOP?
while (digitalRead(playButton) == HIGH)
{
 // digitalWrite(blinker, HIGH);
 if (active == false)
{ //INITIALIZE VOX

   NotePlayer[0].begin(7);
   NotePlayer[1].begin(6);
   //NotePlayer[2].begin(5);
   //NotePlayer[3].begin(4);
 active = true;
}
 


 for (int CurrentVoice = 0; CurrentVoice <= numVoices; CurrentVoice++)
 {
    //if (NotePlayer[CurrentVoice].isPlaying() == false)
    if (millis()>=(lastTime[CurrentVoice]+(settingsGrid[CurrentVoice][Length])))
{
  //NotePlayer[CurrentVoice].stop();
//lastTime[CurrentVoice] = millis();
       
     int ModeSig = settingsGrid[CurrentVoice][Mode];
  int SelectNote = random ((((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12));
  {
  if ((bitRead(modeCode[ModeSig], SelectNote)) ==1)
   {
   PlayNote = (SelectNote + settingsGrid[CurrentVoice][Key] + (settingsGrid[CurrentVoice][Bottom]*12));
  }
       if (PlayNote > (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12))
  //     digitalWrite(blinker, HIGH);
  {
    PlayNote = PlayNote - (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12);
  }
  }
if (random(256)<=settingsGrid[CurrentVoice][Odds])
{
  NotePlayer[CurrentVoice].play(Notes[PlayNote]);
  lastTime[CurrentVoice]=millis();
    }
    else
    {
      NotePlayer[CurrentVoice].stop();
    lastTime[CurrentVoice]=millis();
    }
   
  }
 }}}
5  Using Arduino / Project Guidance / Re: Mega 2560 r3 and polyphonic tones on: April 07, 2013, 06:41:12 pm
This one finally works on all 4 channels, but for the life of me I can't get past using this is a trigger:

 if (NotePlayer[CurrentVoice].isPlaying() == false)
    //if (millis()>=(lastTime[CurrentVoice]+(settingsGrid[CurrentVoice][Length])))

I'd like to is the bottom line so I can work blank spaces based on settingsGrid[CurrentVoice][Length]






Code:
//tonetoy r0001


#include <SoftwareSerial.h>
#include <serLCD.h>
#include <SPI.h>
#include <Tone.h>
 
 //________________________________________________pins!
 
  //spi slave select
const int slaveSelectPin = 53;
const int selectButton = 31;
const int playButton = 30;
// Set pin to the LCD's rxPin
int pin = 18;
serLCD lcd(pin);

int blinker = 40;

//_________________________________________________timing stuff
int menuUpdate = 100;
long menuRefresh = millis();
//last time note played
   long lastTime[4] = {0,0,0,0};

//__________________________________________________noteplayer stuff
int voice;
int numVoices = 4;
Tone NotePlayer[4];
int PlayNote;
//noteplayers on/off
boolean active = false;

#define scaleC 0
#define scaleC# 1
#define scaleD 2
#define scaleD# 3
#define scaleE 4
#define scaleF 5
#define scaleF# 6
#define scaleG 7
#define scaleG# 8
#define scaleA 9
#define scaleA# 10
#define scaleB 11

//Scale bitmasks
   int modeCode[] = {
    2773, 2906, 3670, 2937, 3498, 2457, 2418, 4095, 3289, 3243, 2922, 3449, 2777, 2905, 3170, 2875,
    2873, 3162, 2840, 3434, 2742, 3352, 2774, 3413, 3417, 3510, 3305, 3290, 2726, 2642, 3250, 2869, 2730
   };
      //key offsets
   int keyOffset[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
   //notes
    //NOTES
   int Notes[] = {
NOTE_B0, NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_DS1, NOTE_E1, NOTE_F1, NOTE_FS1,
NOTE_G1, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_B1, NOTE_C2, NOTE_CS2, NOTE_D2, NOTE_DS2,
NOTE_E2, NOTE_F2, NOTE_FS2, NOTE_G2, NOTE_GS2, NOTE_A2, NOTE_AS2, NOTE_B2, NOTE_C3,
NOTE_CS3, NOTE_D3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3, NOTE_G3, NOTE_GS3, NOTE_A3,
NOTE_AS3, NOTE_B3, NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4,
NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5,
NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6,
NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6,
NOTE_AS6, NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7,
NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7, NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8
 };

//______________________________________________________________menus and parameters
int pointer;
 // main menu string 10 options
 int menuOptions = 10;
 int Mode = 0;
 int Key = 1;
 int Top = 2;
 int Bottom = 3;
 int Length = 4;
 int Odds = 5;
 int Attack = 6;
 int Decay = 7;
 int Sustain = 8;
 int Release = 9;
//main menu
  char* menuString[]={"Mode ", "Key     ", "Top     ", "Bottom  ", "Length  ",
"Odds    ", "Attack  ","Decay   ","Sustain ","Release "};

//mode menu 33 modes
 char* modeString[]={"Major       ", "Minor       ", "Adonai      ", "Algerian    ",
 "Altered     ", "Augmented   ", "Blues       ", "Chromatic   ", "Arabic      ", "Enigmatic   ",
 "HalfDim     ", "Bebop       ", "HarmMaj     ", "HarmMin     ", "Hirajoshi   ", "HuGypsy     ",
 "HuMinor     ", "Insen       ", "Iwato       ", "Locrian     ", "Lydian      ", "Hemitonic   ",
 "Mixolydian  ", "NeaMajor    ", "NeaMinor    ", "Octatonic   ", "Persian     ", "Phrygian    ",
 "Prometheus  ", "Slendro     ", "Tritone     ", "UkrDorian   ", "WholeTone   "};
 
  //Keys submenu 12 keys
   char* keyString[]={
 "C        ", "CS       ", "D        ", "DS       ", "E        ", "F        ",
 "FS       ", "G        ", "GS       ", "A        ", "AS       ", "B        " };
 
    //main parameter holder array
    //random start values
   int settingsGrid[4][10] = {
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
   };
   
   //_________________________________________________________SETUP
   
   void setup()
{


randomSeed(analogRead(0));
  //signal LED
pinMode(40, OUTPUT);
  pinMode(playButton, INPUT);
  pinMode(selectButton, INPUT);
lcd.clear();
//slave select spi
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();
}
 //__________________________________________________________LOOP 
  void loop()
{
 digitalWrite(blinker, LOW);
   //menu refresh delay timer
   if( (long)( millis() - (menuRefresh)+menuUpdate ) >= 0)
   {
   menuRefresh = millis();
   //LCD commands
lcd.setCursor(1, 1);
lcd.print("Voice");
lcd.setCursor(1, 8);
voice = (analogRead(1)/256);
lcd.print((voice+1));
  //Line 2 of display 
lcd.setCursor(2,1);
pointer = (analogRead(2)/103);
lcd.print(menuString[pointer]);
// Menu scrolling
if (pointer == 0)
 {
      lcd.print(modeString[settingsGrid[voice][pointer]]);
 };
 if (pointer == 1)
{
   lcd.print(keyString[settingsGrid[voice][pointer]]);
}
if (pointer >= 2)
{
    lcd.print(settingsGrid[voice][pointer]);
lcd.print("      ");
}
   }
   
//ENTER DATA
while (digitalRead(selectButton) == HIGH)
 {
 switch (pointer)
 {
 case 0:
    settingsGrid[voice][pointer] = (analogRead(2)/31.5);
     lcd.setCursor(2,6);
   lcd.print(modeString[settingsGrid[voice][pointer]]);
   break;
  case 1:
 settingsGrid[voice][pointer] = (analogRead(2)/86);
      lcd.setCursor(2,9);
 lcd.print(keyString[settingsGrid[voice][pointer]]);
   break;
case 2:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 3:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 4:
  settingsGrid[voice][pointer] = (((analogRead(2)/8)*10)+50);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 5:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 6:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
      lcd.setCursor(2,9);
      lcd.print(settingsGrid[voice][pointer]);
      lcd.print("   ");
break;
case 7:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 8:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
  case 9:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
 }
 }
  //NOTE SELECT, INITIALIZE PLAY, ADSR LOOP?
while (digitalRead(playButton) == HIGH)
{
 // digitalWrite(blinker, HIGH);
 if (active == false)
{ //INITIALIZE VOX

   NotePlayer[0].begin(7);
   NotePlayer[1].begin(6);
   NotePlayer[2].begin(5);
   NotePlayer[3].begin(4);
 active = true;
}
 {


 for (int CurrentVoice = 0; CurrentVoice <= numVoices; CurrentVoice++)
 {
    if (NotePlayer[CurrentVoice].isPlaying() == false)
    //if (millis()>=(lastTime[CurrentVoice]+(settingsGrid[CurrentVoice][Length])))
{
//lastTime[CurrentVoice] = millis();
       
     int ModeSig = settingsGrid[CurrentVoice][Mode];
  int SelectNote = random ((((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12));
  {
  if ((bitRead(modeCode[ModeSig], SelectNote)) ==1)
   {
   PlayNote = (SelectNote + settingsGrid[CurrentVoice][Key] + (settingsGrid[CurrentVoice][Bottom]*12));
  }
       if (PlayNote > (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12))
  //     digitalWrite(blinker, HIGH);
  {
    PlayNote = PlayNote - (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12);
  }
  }
 
  //digitalWrite(blinker, HIGH);
  NotePlayer[CurrentVoice].play(Notes[PlayNote], settingsGrid[CurrentVoice][Length]);
  lastTime[CurrentVoice] = millis();
  }
 }
 }
}
}
6  Using Arduino / Project Guidance / Re: Mega 2560 r3 and polyphonic tones on: April 07, 2013, 05:12:01 pm
No Love, huh?

Anyway, still chasing my tail trying to do polyphony on this thing. Been mashing around trying to get it two work when I should have realized I can only get 2 of the claimed 6 tone functions to work. I stripped the notepicking part and subbed in an LED for troubleshooting, and that's when I realized how dead my loop was.

   NotePlayer[0].begin(7);
   NotePlayer[1].begin(6);
   //NotePlayer[2].begin(5);
   //NotePlayer[3].begin(4);

This works (in setup()),

this kills it dead:

   NotePlayer[0].begin(7);
   NotePlayer[1].begin(6);
   NotePlayer[2].begin(5);
   NotePlayer[3].begin(4);

Any suggestions on getting this to work? I thought by using 4 tones I'd be avoiding timer functions.


Code:
//tonetoy r0001


#include <SoftwareSerial.h>
#include <serLCD.h>
#include <SPI.h>
#include <Tone.h>
 
 //________________________________________________pins!
 
  //spi slave select
const int slaveSelectPin = 53;
const int selectButton = 31;
const int playButton = 30;
// Set pin to the LCD's rxPin
int pin = 18;
serLCD lcd(pin);

int blinker = 40;


//_________________________________________________timing stuff
int menuUpdate = 100;
long menuRefresh = millis();
//last time note played
   unsigned long lastTime[4] = {0,0,0,0};
   int blinkerState = LOW;


//__________________________________________________noteplayer stuff
int voice;
int numVoices = 4;
Tone NotePlayer[4];
int PlayNote;
//noteplayers on/off


#define scaleC 0
#define scaleC# 1
#define scaleD 2
#define scaleD# 3
#define scaleE 4
#define scaleF 5
#define scaleF# 6
#define scaleG 7
#define scaleG# 8
#define scaleA 9
#define scaleA# 10
#define scaleB 11

//Scale bitmasks
   int modeCode[] = {
    2773, 2906, 3670, 2937, 3498, 2457, 2418, 4095, 3289, 3243, 2922, 3449, 2777, 2905, 3170, 2875,
    2873, 3162, 2840, 3434, 2742, 3352, 2774, 3413, 3417, 3510, 3305, 3290, 2726, 2642, 3250, 2869, 2730
   };
      //key offsets
   int keyOffset[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
   //notes
    //NOTES
   int Notes[] = {
NOTE_B0, NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_DS1, NOTE_E1, NOTE_F1, NOTE_FS1,
NOTE_G1, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_B1, NOTE_C2, NOTE_CS2, NOTE_D2, NOTE_DS2,
NOTE_E2, NOTE_F2, NOTE_FS2, NOTE_G2, NOTE_GS2, NOTE_A2, NOTE_AS2, NOTE_B2, NOTE_C3,
NOTE_CS3, NOTE_D3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3, NOTE_G3, NOTE_GS3, NOTE_A3,
NOTE_AS3, NOTE_B3, NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4,
NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5,
NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6,
NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6,
NOTE_AS6, NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7,
NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7, NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8
 };

//______________________________________________________________menus and parameters
int pointer;
 // main menu string 10 options
 int menuOptions = 10;
 int Mode = 0;
 int Key = 1;
 int Top = 2;
 int Bottom = 3;
 int Length = 4;
 int Odds = 5;
 int Attack = 6;
 int Decay = 7;
 int Sustain = 8;
 int Release = 9;
//main menu
  char* menuString[]={"Mode ", "Key     ", "Top     ", "Bottom  ", "Length  ",
"Odds    ", "Attack  ","Decay   ","Sustain ","Release "};

//mode menu 33 modes
 char* modeString[]={"Major       ", "Minor       ", "Adonai      ", "Algerian    ",
 "Altered     ", "Augmented   ", "Blues       ", "Chromatic   ", "Arabic      ", "Enigmatic   ",
 "HalfDim     ", "Bebop       ", "HarmMaj     ", "HarmMin     ", "Hirajoshi   ", "HuGypsy     ",
 "HuMinor     ", "Insen       ", "Iwato       ", "Locrian     ", "Lydian      ", "Hemitonic   ",
 "Mixolydian  ", "NeaMajor    ", "NeaMinor    ", "Octatonic   ", "Persian     ", "Phrygian    ",
 "Prometheus  ", "Slendro     ", "Tritone     ", "UkrDorian   ", "WholeTone   "};
 
  //Keys submenu 12 keys
   char* keyString[]={
 "C        ", "CS       ", "D        ", "DS       ", "E        ", "F        ",
 "FS       ", "G        ", "GS       ", "A        ", "AS       ", "B        " };
 
    //main parameter holder array
    //random start values
   long settingsGrid[4][10] = {
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
   };
   
   //_________________________________________________________SETUP
   
   void setup()
{

randomSeed(analogRead(0));
  //signal LED
pinMode(40, OUTPUT);
  pinMode(playButton, INPUT);
  pinMode(selectButton, INPUT);
lcd.clear();
//slave select spi
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();

   NotePlayer[0].begin(7);
   NotePlayer[1].begin(6);
   //NotePlayer[2].begin(5);
   //NotePlayer[3].begin(4);

  //
}

}
 //__________________________________________________________LOOP 
  void loop()
{
 digitalWrite(blinker, LOW);
   //menu refresh delay timer
   if( (long)( millis() - (menuRefresh)+menuUpdate ) >= 0)
   {
   menuRefresh = millis();
   //LCD commands
lcd.setCursor(1, 1);
lcd.print("Voice");
lcd.setCursor(1, 8);
voice = (analogRead(1)/256);
lcd.print((voice+1));
  //Line 2 of display 
lcd.setCursor(2,1);
pointer = (analogRead(2)/103);
lcd.print(menuString[pointer]);
// Menu scrolling
if (pointer == 0)
 {
      lcd.print(modeString[settingsGrid[voice][pointer]]);
 };
 if (pointer == 1)
{
   lcd.print(keyString[settingsGrid[voice][pointer]]);
}
if (pointer >= 2)
{
    lcd.print(settingsGrid[voice][pointer]);
lcd.print("      ");
}
   }
   
//ENTER DATA
while (digitalRead(selectButton) == HIGH)
 {
 switch (pointer)
 {
 case 0:
    settingsGrid[voice][pointer] = (analogRead(2)/31.5);
     lcd.setCursor(2,6);
   lcd.print(modeString[settingsGrid[voice][pointer]]);
   break;
  case 1:
 settingsGrid[voice][pointer] = (analogRead(2)/86);
      lcd.setCursor(2,9);
 lcd.print(keyString[settingsGrid[voice][pointer]]);
   break;
case 2:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 3:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 4:
  settingsGrid[voice][pointer] = (((analogRead(2)/8)*10)+50);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 5:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 6:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
      lcd.setCursor(2,9);
      lcd.print(settingsGrid[voice][pointer]);
      lcd.print("   ");
break;
case 7:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 8:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
  case 9:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
 }
 }
  //NOTE SELECT, INITIALIZE PLAY, ADSR LOOP?
while (digitalRead(playButton) == HIGH)
{

 if (active == true)
{



  //


 // digitalWrite(blinker, HIGH);

unsigned long currentMillis=millis();
//digitalWrite(blinker, HIGH);
if ((currentMillis - lastTime[3]) >=  (settingsGrid[3][Length]))
{
lastTime[3]=currentMillis;
//if ((millis() >=  long (lastTime[CurrentVoice] + settingsGrid[CurrentVoice][Length])))
{
   if (blinkerState == LOW)
   {
      blinkerState = HIGH;
   }
    else
    {
      blinkerState = LOW;
     
    }
    digitalWrite(blinker, blinkerState);
   

}}}}}
7  Using Arduino / Project Guidance / Re: Mega 2560 r3 and polyphonic tones on: April 05, 2013, 12:29:30 am
FWIW this I think works insofar as tones on all 4 channels... need to figure out how to do the 'rests' based on odds.


Code:
etoy r0001


#include <SoftwareSerial.h>
#include <serLCD.h>
#include <SPI.h>
#include <Tone.h>
 
 //________________________________________________pins!
 
  //spi slave select
const int slaveSelectPin = 53;
const int selectButton = 31;
const int playButton = 30;
// Set pin to the LCD's rxPin
int pin = 18;
serLCD lcd(pin);

int blinker = 40;

//_________________________________________________timing stuff
int menuUpdate = 100;
long menuRefresh = millis();
//last time note played
   long lastTime[4] = {0,0,0,0};

//__________________________________________________noteplayer stuff
int voice;
int numVoices = 4;
Tone NotePlayer[4];
int PlayNote;
//noteplayers on/off
boolean active = false;

#define scaleC 0
#define scaleC# 1
#define scaleD 2
#define scaleD# 3
#define scaleE 4
#define scaleF 5
#define scaleF# 6
#define scaleG 7
#define scaleG# 8
#define scaleA 9
#define scaleA# 10
#define scaleB 11

//Scale bitmasks
   int modeCode[] = {
    2773, 2906, 3670, 2937, 3498, 2457, 2418, 4095, 3289, 3243, 2922, 3449, 2777, 2905, 3170, 2875,
    2873, 3162, 2840, 3434, 2742, 3352, 2774, 3413, 3417, 3510, 3305, 3290, 2726, 2642, 3250, 2869, 2730
   };
      //key offsets
   int keyOffset[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
   //notes
    //NOTES
   int Notes[] = {
NOTE_B0, NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_DS1, NOTE_E1, NOTE_F1, NOTE_FS1,
NOTE_G1, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_B1, NOTE_C2, NOTE_CS2, NOTE_D2, NOTE_DS2,
NOTE_E2, NOTE_F2, NOTE_FS2, NOTE_G2, NOTE_GS2, NOTE_A2, NOTE_AS2, NOTE_B2, NOTE_C3,
NOTE_CS3, NOTE_D3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3, NOTE_G3, NOTE_GS3, NOTE_A3,
NOTE_AS3, NOTE_B3, NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4,
NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5,
NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6,
NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6,
NOTE_AS6, NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7,
NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7, NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8
 };

//______________________________________________________________menus and parameters
int pointer;
 // main menu string 10 options
 int menuOptions = 10;
 int Mode = 0;
 int Key = 1;
 int Top = 2;
 int Bottom = 3;
 int Length = 4;
 int Odds = 5;
 int Attack = 6;
 int Decay = 7;
 int Sustain = 8;
 int Release = 9;
//main menu
  char* menuString[]={"Mode ", "Key     ", "Top     ", "Bottom  ", "Length  ",
"Odds    ", "Attack  ","Decay   ","Sustain ","Release "};

//mode menu 33 modes
 char* modeString[]={"Major       ", "Minor       ", "Adonai      ", "Algerian    ",
 "Altered     ", "Augmented   ", "Blues       ", "Chromatic   ", "Arabic      ", "Enigmatic   ",
 "HalfDim     ", "Bebop       ", "HarmMaj     ", "HarmMin     ", "Hirajoshi   ", "HuGypsy     ",
 "HuMinor     ", "Insen       ", "Iwato       ", "Locrian     ", "Lydian      ", "Hemitonic   ",
 "Mixolydian  ", "NeaMajor    ", "NeaMinor    ", "Octatonic   ", "Persian     ", "Phrygian    ",
 "Prometheus  ", "Slendro     ", "Tritone     ", "UkrDorian   ", "WholeTone   "};
 
  //Keys submenu 12 keys
   char* keyString[]={
 "C        ", "CS       ", "D        ", "DS       ", "E        ", "F        ",
 "FS       ", "G        ", "GS       ", "A        ", "AS       ", "B        " };
 
    //main parameter holder array
    //random start values
   int settingsGrid[4][10] = {
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
   };
   
   //_________________________________________________________SETUP
   
   void setup()
{
randomSeed(analogRead(0));
  //signal LED
pinMode(40, OUTPUT);
  pinMode(playButton, INPUT);
  pinMode(selectButton, INPUT);
lcd.clear();
//slave select spi
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();
}
 //__________________________________________________________LOOP 
  void loop()
{
 digitalWrite(blinker, LOW);
   //menu refresh delay timer
   if( (long)( millis() - (menuRefresh)+menuUpdate ) >= 0)
   {
   menuRefresh = millis();
   //LCD commands
lcd.setCursor(1, 1);
lcd.print("Voice");
lcd.setCursor(1, 8);
voice = (analogRead(1)/256);
lcd.print((voice+1));
  //Line 2 of display 
lcd.setCursor(2,1);
pointer = (analogRead(2)/103);
lcd.print(menuString[pointer]);
// Menu scrolling
if (pointer == 0)
 {
      lcd.print(modeString[settingsGrid[voice][pointer]]);
 };
 if (pointer == 1)
{
   lcd.print(keyString[settingsGrid[voice][pointer]]);
}
if (pointer >= 2)
{
    lcd.print(settingsGrid[voice][pointer]);
lcd.print("      ");
}
   }
   
//ENTER DATA
while (digitalRead(selectButton) == HIGH)
 {
 switch (pointer)
 {
 case 0:
    settingsGrid[voice][pointer] = (analogRead(2)/31.5);
     lcd.setCursor(2,6);
   lcd.print(modeString[settingsGrid[voice][pointer]]);
   break;
  case 1:
 settingsGrid[voice][pointer] = (analogRead(2)/86);
      lcd.setCursor(2,9);
 lcd.print(keyString[settingsGrid[voice][pointer]]);
   break;
case 2:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 3:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 4:
  settingsGrid[voice][pointer] = (((analogRead(2)/8)*10)+50);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 5:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 6:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
      lcd.setCursor(2,9);
      lcd.print(settingsGrid[voice][pointer]);
      lcd.print("   ");
break;
case 7:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 8:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
  case 9:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
 }
 }
  //NOTE SELECT, INITIALIZE PLAY, ADSR LOOP?
while (digitalRead(playButton) == HIGH)
{
 // digitalWrite(blinker, HIGH);

//INITIALIZE VOX
if (active == false)
{
   NotePlayer[0].begin(7);
   NotePlayer[1].begin(6);
   NotePlayer[2].begin(5);
   NotePlayer[3].begin(4);
   active = true;
  //
}
 for (int CurrentVoice = 0; CurrentVoice <= numVoices; CurrentVoice++)
 {
    if (NotePlayer[CurrentVoice].isPlaying() == false)
{

        {
     int ModeSig = settingsGrid[CurrentVoice][Mode];
  int SelectNote = random ((((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12));
  {
  if ((bitRead(modeCode[ModeSig], SelectNote)) ==1)
   {
   PlayNote = (SelectNote + settingsGrid[CurrentVoice][Key] + settingsGrid[CurrentVoice][Bottom]);
  }
       if (PlayNote > (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12))
  //     digitalWrite(blinker, HIGH);
  {
    PlayNote = PlayNote - (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12);
  }
  }
 
  //digitalWrite(blinker, HIGH);
  NotePlayer[CurrentVoice].play(Notes[PlayNote], settingsGrid[CurrentVoice][Length]);
 
 
  } 
 

}


 }
}
}
8  Using Arduino / Project Guidance / Re: Mega 2560 r3 and polyphonic tones on: April 04, 2013, 10:22:15 pm
although it only seems to make farting noise sounds, nothing I would call a tone.
9  Using Arduino / Project Guidance / Re: Mega 2560 r3 and polyphonic tones on: April 04, 2013, 06:46:15 pm
Got it working (at least a buzzer buzzes in the output pins and the debugging LED says all good) after I cleaned up the dogpile of code:
there's still a debugging LED in there as I have not fired up the SPI pots yet.

Code:
//tonetoy r0001


#include <SoftwareSerial.h>
#include <serLCD.h>
#include <SPI.h>
#include <Tone.h>
 
 //________________________________________________pins!
 
  //spi slave select
const int slaveSelectPin = 53;
const int selectButton = 31;
const int playButton = 30;
// Set pin to the LCD's rxPin
int pin = 18;
serLCD lcd(pin);

int blinker = 40;

//_________________________________________________timing stuff
int menuUpdate = 100;
long menuRefresh = millis();
//last time note played
   long lastTime[4] = {0,0,0,0};

//__________________________________________________noteplayer stuff
int voice;
int numVoices = 4;
Tone NotePlayer[4];
int PlayNote;
//noteplayers on/off
boolean active = false;

#define scaleC 0
#define scaleC# 1
#define scaleD 2
#define scaleD# 3
#define scaleE 4
#define scaleF 5
#define scaleF# 6
#define scaleG 7
#define scaleG# 8
#define scaleA 9
#define scaleA# 10
#define scaleB 11

//Scale bitmasks
   int modeCode[] = {
    2773, 2906, 3670, 2937, 3498, 2457, 2418, 4095, 3289, 3243, 2922, 3449, 2777, 2905, 3170, 2875,
    2873, 3162, 2840, 3434, 2742, 3352, 2774, 3413, 3417, 3510, 3305, 3290, 2726, 2642, 3250, 2869, 2730
   };
      //key offsets
   int keyOffset[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
   //notes
    //NOTES
   int Notes[] = {
NOTE_B0, NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_DS1, NOTE_E1, NOTE_F1, NOTE_FS1,
NOTE_G1, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_B1, NOTE_C2, NOTE_CS2, NOTE_D2, NOTE_DS2,
NOTE_E2, NOTE_F2, NOTE_FS2, NOTE_G2, NOTE_GS2, NOTE_A2, NOTE_AS2, NOTE_B2, NOTE_C3,
NOTE_CS3, NOTE_D3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3, NOTE_G3, NOTE_GS3, NOTE_A3,
NOTE_AS3, NOTE_B3, NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4,
NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5,
NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6,
NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6,
NOTE_AS6, NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7,
NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7, NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8
 };

//______________________________________________________________menus and parameters
int pointer;
 // main menu string 10 options
 int menuOptions = 10;
 int Mode = 0;
 int Key = 1;
 int Top = 2;
 int Bottom = 3;
 int Length = 4;
 int Odds = 5;
 int Attack = 6;
 int Decay = 7;
 int Sustain = 8;
 int Release = 9;
//main menu
  char* menuString[]={"Mode ", "Key     ", "Top     ", "Bottom  ", "Length  ",
"Odds    ", "Attack  ","Decay   ","Sustain ","Release "};

//mode menu 33 modes
 char* modeString[]={"Major       ", "Minor       ", "Adonai      ", "Algerian    ",
 "Altered     ", "Augmented   ", "Blues       ", "Chromatic   ", "Arabic      ", "Enigmatic   ",
 "HalfDim     ", "Bebop       ", "HarmMaj     ", "HarmMin     ", "Hirajoshi   ", "HuGypsy     ",
 "HuMinor     ", "Insen       ", "Iwato       ", "Locrian     ", "Lydian      ", "Hemitonic   ",
 "Mixolydian  ", "NeaMajor    ", "NeaMinor    ", "Octatonic   ", "Persian     ", "Phrygian    ",
 "Prometheus  ", "Slendro     ", "Tritone     ", "UkrDorian   ", "WholeTone   "};
 
  //Keys submenu 12 keys
   char* keyString[]={
 "C        ", "CS       ", "D        ", "DS       ", "E        ", "F        ",
 "FS       ", "G        ", "GS       ", "A        ", "AS       ", "B        " };
 
    //main parameter holder array
    //random start values
   int settingsGrid[4][10] = {
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
   };
   
   //_________________________________________________________SETUP
   
   void setup()
{

  //signal LED
pinMode(40, OUTPUT);
  pinMode(playButton, INPUT);
  pinMode(selectButton, INPUT);
lcd.clear();
//slave select spi
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();
}
 //__________________________________________________________LOOP 
  void loop()
{
 digitalWrite(blinker, LOW);
   //menu refresh delay timer
   if( (long)( millis() - (menuRefresh)+menuUpdate ) >= 0)
   {
   menuRefresh = millis();
   //LCD commands
lcd.setCursor(1, 1);
lcd.print("Voice");
lcd.setCursor(1, 8);
voice = (analogRead(1)/256);
lcd.print((voice+1));
  //Line 2 of display 
lcd.setCursor(2,1);
pointer = (analogRead(2)/103);
lcd.print(menuString[pointer]);
// Menu scrolling
if (pointer == 0)
 {
      lcd.print(modeString[settingsGrid[voice][pointer]]);
 };
 if (pointer == 1)
{
   lcd.print(keyString[settingsGrid[voice][pointer]]);
}
if (pointer >= 2)
{
    lcd.print(settingsGrid[voice][pointer]);
lcd.print("      ");
}
   }
   
//ENTER DATA
while (digitalRead(selectButton) == HIGH)
 {
 switch (pointer)
 {
 case 0:
    settingsGrid[voice][pointer] = (analogRead(2)/31.5);
     lcd.setCursor(2,6);
   lcd.print(modeString[settingsGrid[voice][pointer]]);
   break;
  case 1:
 settingsGrid[voice][pointer] = (analogRead(2)/86);
      lcd.setCursor(2,9);
 lcd.print(keyString[settingsGrid[voice][pointer]]);
   break;
case 2:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 3:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 4:
  settingsGrid[voice][pointer] = (((analogRead(2)/8)*10)+50);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 5:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 6:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
      lcd.setCursor(2,9);
      lcd.print(settingsGrid[voice][pointer]);
      lcd.print("   ");
break;
case 7:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 8:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
  case 9:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
 }
 }
  //NOTE SELECT, INITIALIZE PLAY, ADSR LOOP?
while (digitalRead(playButton) == HIGH)
{
 // digitalWrite(blinker, HIGH);

//INITIALIZE VOX
if (active == false)
{
   NotePlayer[0].begin(9);
   NotePlayer[1].begin(2);
   NotePlayer[2].begin(6);
   NotePlayer[3].begin(45);
   active = true;
  //
}
 for (int CurrentVoice = 0; CurrentVoice <= numVoices; CurrentVoice++)
 {
    if( (long)( millis() - (lastTime[CurrentVoice])+settingsGrid[CurrentVoice][Length] ) >= 0)
    {
      //digitalWrite(blinker, HIGH);
      lastTime[CurrentVoice] = millis();
 if (random(256) > settingsGrid[CurrentVoice][Odds])
   {
     int ModeSig = settingsGrid[CurrentVoice][Mode];
  int SelectNote = random ((((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12));
  {
  if ((bitRead(settingsGrid[CurrentVoice][Mode], SelectNote)) ==1)
   {
   PlayNote = (SelectNote + settingsGrid[CurrentVoice][Key] + settingsGrid[CurrentVoice][Bottom]);
  }
       if (PlayNote > (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12))
  {
    PlayNote = PlayNote - (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12);
  }
  }
 
  //digitalWrite(blinker, HIGH);
  NotePlayer[CurrentVoice].play(Notes[PlayNote], settingsGrid[CurrentVoice][Length] );
  } 
 }
 }
}
}
10  Using Arduino / Project Guidance / Re: Mega 2560 r3 and polyphonic tones on: April 03, 2013, 11:34:21 pm
Hokay,

I moved the initialization of the noteplayers into the main loop and now it doesn't lock up with all of them enabled,
...but I get no tone. Maybe I need to make an LED pin to show me how far it's getting in the loop.

//INITIALIZE VOX
if (active == false)
{
     NotePlayer[0].begin(9);
   NotePlayer[1].begin(2);
   NotePlayer[2].begin(6);
   NotePlayer[3].begin(45);
   active = true;
}
 








Code:
/*
TONETOY_0000
*/
#include <SoftwareSerial.h>
#include <serLCD.h>
#include <SPI.h>
 #include <Tone.h>
 
 //spi slave select
 const int slaveSelectPin = 53;

//Declare scale
//number of voices

//pin 31 is select button
int selectButton = 31;

int playButton = 30;

int PlayNote;

int numVoices = 4;
//declare tone array!


Tone NotePlayer[4];
int menuUpdate = 100;
long menuRefresh = millis();

//noteplayers on/off
boolean active = false;

#define scaleC 0
#define scaleC# 1
#define scaleD 2
#define scaleD# 3
#define scaleE 4
#define scaleF 5
#define scaleF# 6
#define scaleG 7
#define scaleG# 8
#define scaleA 9
#define scaleA# 10
#define scaleB 11
// Set pin to the LCD's rxPin
int pin = 18;
 serLCD lcd(pin);
 // main menu string 10 options
 int menuOptions = 10;
 int Mode = 0;
 int Key = 1;
 int Top = 2;
 int Bottom = 3;
 int Length = 4;
 int Odds = 5;
 int Attack = 6;
 int Decay = 7;
 int Sustain = 8;
 int Release = 9;
 char* menuString[]={"Mode ", "Key     ", "Top     ", "Bottom  ", "Length  ",
"Odds    ", "Attack  ","Decay   ","Sustain ","Release "};
//mode menu 33 modes
 char* modeString[]={
   "Major       ",
   "Minor       ",
   "Adonai      ",
   "Algerian    ",
   "Altered     ",
   "Augmented   ",
   "Blues       ",
   "Chromatic   ",
   "Arabic      ",
   "Enigmatic   ",
   "HalfDim     ",
   "Bebop       ",
   "HarmMaj     ",
   "HarmMin     ",
   "Hirajoshi   ",
   "HuGypsy     ",
   "HuMinor     ",
   "Insen       ",
   "Iwato       ",
   "Locrian     ",
   "Lydian      ",
   "Hemitonic   ",
   "Mixolydian  ",
   "NeaMajor    ",
   "NeaMinor    ",
   "Octatonic   ",
   "Persian     ",
   "Phrygian    ",
   "Prometheus  ",
   "Slendro     ",
   "Tritone     ",
   "UkrDorian   ",
   "WholeTone   "
 };
   //Keys submenu 12 keys
   char* keyString[]={"C       ", "CS       ", "D       ", "DS      ", "E      ", "F      ", "FS     ", "G      ", "GS      ", "A       ", "AS       ", "B        " };
   
   
   //main parameter holder array
   int settingsGrid[4][10] = {
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
   };





   
   
   
   
   
   
   
   
   //mode codes
   int modeCode[] = {
    2773,
    2906,
    3670,
    2937,
    3498,
    2457,
    2418,
    4095,
    3289,
    3243,
    2922,
    3449,
    2777,
    2905,
    3170,
    2875,
    2873,
    3162,
    2840,
    3434,
    2742,
    3352,
    2774,
    3413,
    3417,
    3510,
    3305,
    3290,
    2726,
    2642,
    3250,
    2869,
    2730
   };
   //key offsets
   int keyOffset[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
   //NOTES
   int Notes[] = {
NOTE_B0,
NOTE_C1,
NOTE_CS1,
NOTE_D1,
NOTE_DS1,
NOTE_E1,
NOTE_F1, 
NOTE_FS1,
NOTE_G1,
NOTE_GS1,
NOTE_A1,
NOTE_AS1,
NOTE_B1,
NOTE_C2,
NOTE_CS2,
NOTE_D2,
NOTE_DS2,
NOTE_E2,
NOTE_F2,
NOTE_FS2,
NOTE_G2,
NOTE_GS2,
NOTE_A2,
NOTE_AS2,
NOTE_B2,
NOTE_C3,
NOTE_CS3,
NOTE_D3,
NOTE_DS3,
NOTE_E3,
NOTE_F3,
NOTE_FS3,
NOTE_G3,
NOTE_GS3,
NOTE_A3,
NOTE_AS3,
NOTE_B3,
NOTE_C4,
NOTE_CS4,
NOTE_D4,
NOTE_DS4,
NOTE_E4,
NOTE_F4,
NOTE_FS4,
NOTE_G4,
NOTE_GS4,
NOTE_A4,
NOTE_AS4,
NOTE_B4,
NOTE_C5,
NOTE_CS5,
NOTE_D5,
NOTE_DS5,
NOTE_E5,
NOTE_F5,
NOTE_FS5,
NOTE_G5,
NOTE_GS5,
NOTE_A5,
NOTE_AS5,
NOTE_B5,
NOTE_C6,
NOTE_CS6,
NOTE_D6,
NOTE_DS6,
NOTE_E6,
NOTE_F6,
NOTE_FS6,
NOTE_G6,
NOTE_GS6,
NOTE_A6,
NOTE_AS6,
NOTE_B6,
NOTE_C7,
NOTE_CS7,
NOTE_D7,
NOTE_DS7,
NOTE_E7,
NOTE_F7,
NOTE_FS7,
NOTE_G7,
NOTE_GS7,
NOTE_A7,
NOTE_AS7,
NOTE_B7,
NOTE_C8,
NOTE_CS8,
NOTE_D8,
NOTE_DS8
 };
   
   //timing stuff
   long lastTime[4] = {0,0,0,0};


void setup()
{

 
  pinMode(playButton, INPUT);
  pinMode(selectButton, INPUT);
lcd.clear();
//slave select spi
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();
}
 
void loop()
{

{
   if( (long)( millis() - (menuRefresh)+menuUpdate ) >= 0)
   menuRefresh = millis();
lcd.setCursor(1, 1);
lcd.print("Voice");
lcd.setCursor(1, 8);
int voice = (analogRead(1)/256);
  lcd.print((voice+1));
 
 
  lcd.setCursor(2,1);
  int pointer = (analogRead(2)/103);
  lcd.print(menuString[pointer]);
if (pointer == 0)
 {
   
   lcd.print(modeString[settingsGrid[voice][pointer]]);
 };
 
if (pointer == 1)
{
   lcd.print(keyString[settingsGrid[voice][pointer]]);
}
if (pointer >= 2)
{
 
  lcd.print(settingsGrid[voice][pointer]);
lcd.print("      ");
};

//ENTER DATA

while (digitalRead(selectButton) == HIGH)
 {
 switch (pointer)
 {
 case 0:
 
   settingsGrid[voice][pointer] = (analogRead(2)/31.5);
     lcd.setCursor(2,6);
   lcd.print(modeString[settingsGrid[voice][pointer]]);
   break;
 
 case 1:
 settingsGrid[voice][pointer] = (analogRead(2)/86);
      lcd.setCursor(2,9);
 lcd.print(keyString[settingsGrid[voice][pointer]]);
   break;

case 2:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 3:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 4:
  settingsGrid[voice][pointer] = (((analogRead(2)/8)*10)+50);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 5:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 6:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
      lcd.setCursor(2,9);
      lcd.print(settingsGrid[voice][pointer]);
      lcd.print("   ");
break;
case 7:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 8:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
  case 9:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
 }
 }
 //NOTE SELECT, INITIALIZE PLAY, ADSR LOOP?
while (digitalRead(playButton) == HIGH)

//INITIALIZE VOX
if (active == false)
{
     NotePlayer[0].begin(9);
   NotePlayer[1].begin(2);
   NotePlayer[2].begin(6);
   NotePlayer[3].begin(45);
   active = true;
}
 
 {for (int CurrentVoice = 0; CurrentVoice <= numVoices; CurrentVoice++)
 
 if( (long)( millis() - (lastTime[CurrentVoice])+settingsGrid[CurrentVoice][Length] ) <= 0)
 if (random(256) > settingsGrid[CurrentVoice][Length])
 {
 int ModeSig = settingsGrid[CurrentVoice][Mode];
  int SelectNote = random ((((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12));
  if ((bitRead(settingsGrid[CurrentVoice][Mode], SelectNote)) ==1)
  {
   PlayNote = (SelectNote + settingsGrid[CurrentVoice][Key] + settingsGrid[CurrentVoice][Bottom]);
  }
  if (PlayNote > (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12))
  {
    PlayNote = PlayNote - (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12);
  }
 //  lcd.setCursor(1,1);
 //  lcd.print(PlayNote);
   
//NotePlayer[CurrentVoice].stop();
NotePlayer[CurrentVoice].play(Notes[PlayNote], settingsGrid[CurrentVoice][Length] );
 }
 
 }
 
 }
 
 
}

11  Using Arduino / Project Guidance / Re: Tone library on Mega 2560 r3 on: April 03, 2013, 05:00:57 pm
you may need to edit the .cpp; I'm having issues with this library as well, but this advice got it to load:

https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

(scroll down)
12  Using Arduino / Project Guidance / Mega 2560 r3 and polyphonic tones on: April 03, 2013, 04:41:50 pm
Hi, I've been working on this project on and off for a few years give or take, and finally have some hardware together:

mega 2560
serLCD
SPI pots
2 analog inputs, 2 digital inputs

I want to make a device that allows user entry of parameters for a polyphonic tone player. Musical mode, key, scale, etc; then 'play' to hear polyphony. I enable my tone player array as follows:

   NotePlayer[0].begin(9);
   NotePlayer[1].begin(2);
//   NotePlayer[2].begin(6);
//   NotePlayer[3].begin(45);

(serLCD is connected to TX pin 18)

if I enable the last two, the whole thing goes dead. No LCD, no nothing. If I leave them off, it works, and I get some response from the two enabled pins. Is this the limit? I keep reading about 6 available voices and how to avoid timer conflicts; am I just hitting a wall? I ultimately want to route the audio signals to analog filters controlled by SPI potentiometers, and wonder what pitfalls await me should I ever get that far.

Code includes much kludge, I just want the voices out so I can work on the analog electronics and polish it once it sings.

Code:
/*
TONETOY_0000
*/
#include <SoftwareSerial.h>
#include <serLCD.h>
#include <SPI.h>
 #include <Tone.h>
 
 //spi slave select
 const int slaveSelectPin = 53;

//Declare scale
//number of voices

//pin 31 is select button
int selectButton = 31;

int playButton = 30;

int PlayNote;

int numVoices = 4;
//declare tone array!
Tone NotePlayer[4];
int menuUpdate = 100;
long menuRefresh = millis();

#define scaleC 0
#define scaleC# 1
#define scaleD 2
#define scaleD# 3
#define scaleE 4
#define scaleF 5
#define scaleF# 6
#define scaleG 7
#define scaleG# 8
#define scaleA 9
#define scaleA# 10
#define scaleB 11
// Set pin to the LCD's rxPin
int pin = 18;
 serLCD lcd(pin);
 // main menu string 10 options
 int menuOptions = 10;
 int Mode = 0;
 int Key = 1;
 int Top = 2;
 int Bottom = 3;
 int Length = 4;
 int Odds = 5;
 int Attack = 6;
 int Decay = 7;
 int Sustain = 8;
 int Release = 9;
 char* menuString[]={"Mode ", "Key     ", "Top     ", "Bottom  ", "Length  ",
"Odds    ", "Attack  ","Decay   ","Sustain ","Release "};
//mode menu 33 modes
 char* modeString[]={
   "Major       ",
   "Minor       ",
   "Adonai      ",
   "Algerian    ",
   "Altered     ",
   "Augmented   ",
   "Blues       ",
   "Chromatic   ",
   "Arabic      ",
   "Enigmatic   ",
   "HalfDim     ",
   "Bebop       ",
   "HarmMaj     ",
   "HarmMin     ",
   "Hirajoshi   ",
   "HuGypsy     ",
   "HuMinor     ",
   "Insen       ",
   "Iwato       ",
   "Locrian     ",
   "Lydian      ",
   "Hemitonic   ",
   "Mixolydian  ",
   "NeaMajor    ",
   "NeaMinor    ",
   "Octatonic   ",
   "Persian     ",
   "Phrygian    ",
   "Prometheus  ",
   "Slendro     ",
   "Tritone     ",
   "UkrDorian   ",
   "WholeTone   "
 };
   //Keys submenu 12 keys
   char* keyString[]={"C       ", "CS       ", "D       ", "DS      ", "E      ", "F      ", "FS     ", "G      ", "GS      ", "A       ", "AS       ", "B        " };
   
   
   //main parameter holder array
   int settingsGrid[4][10] = {
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
     {random(33), random(12), (random(4)+4), random(4), random(1023),random(256), random(256),random(256),random(256),random(256)},
   };





   
   
   
   
   
   
   
   
   //mode codes
   int modeCode[] = {
    2773,
    2906,
    3670,
    2937,
    3498,
    2457,
    2418,
    4095,
    3289,
    3243,
    2922,
    3449,
    2777,
    2905,
    3170,
    2875,
    2873,
    3162,
    2840,
    3434,
    2742,
    3352,
    2774,
    3413,
    3417,
    3510,
    3305,
    3290,
    2726,
    2642,
    3250,
    2869,
    2730
   };
   //key offsets
   int keyOffset[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
   //NOTES
   int Notes[] = {
NOTE_B0,
NOTE_C1,
NOTE_CS1,
NOTE_D1,
NOTE_DS1,
NOTE_E1,
NOTE_F1, 
NOTE_FS1,
NOTE_G1,
NOTE_GS1,
NOTE_A1,
NOTE_AS1,
NOTE_B1,
NOTE_C2,
NOTE_CS2,
NOTE_D2,
NOTE_DS2,
NOTE_E2,
NOTE_F2,
NOTE_FS2,
NOTE_G2,
NOTE_GS2,
NOTE_A2,
NOTE_AS2,
NOTE_B2,
NOTE_C3,
NOTE_CS3,
NOTE_D3,
NOTE_DS3,
NOTE_E3,
NOTE_F3,
NOTE_FS3,
NOTE_G3,
NOTE_GS3,
NOTE_A3,
NOTE_AS3,
NOTE_B3,
NOTE_C4,
NOTE_CS4,
NOTE_D4,
NOTE_DS4,
NOTE_E4,
NOTE_F4,
NOTE_FS4,
NOTE_G4,
NOTE_GS4,
NOTE_A4,
NOTE_AS4,
NOTE_B4,
NOTE_C5,
NOTE_CS5,
NOTE_D5,
NOTE_DS5,
NOTE_E5,
NOTE_F5,
NOTE_FS5,
NOTE_G5,
NOTE_GS5,
NOTE_A5,
NOTE_AS5,
NOTE_B5,
NOTE_C6,
NOTE_CS6,
NOTE_D6,
NOTE_DS6,
NOTE_E6,
NOTE_F6,
NOTE_FS6,
NOTE_G6,
NOTE_GS6,
NOTE_A6,
NOTE_AS6,
NOTE_B6,
NOTE_C7,
NOTE_CS7,
NOTE_D7,
NOTE_DS7,
NOTE_E7,
NOTE_F7,
NOTE_FS7,
NOTE_G7,
NOTE_GS7,
NOTE_A7,
NOTE_AS7,
NOTE_B7,
NOTE_C8,
NOTE_CS8,
NOTE_D8,
NOTE_DS8
 };
   
   //timing stuff
   long lastTime[4] = {0,0,0,0};


void setup()
{
   NotePlayer[0].begin(9);
   NotePlayer[1].begin(2);
//   NotePlayer[2].begin(6);
//   NotePlayer[3].begin(45);
 
  pinMode(playButton, INPUT);
  pinMode(selectButton, INPUT);
lcd.clear();
//slave select spi
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();
}
 
void loop()
{
   if( (long)( millis() - (menuRefresh)+menuUpdate ) >= 0)
   menuRefresh = millis();
lcd.setCursor(1, 1);
lcd.print("Voice");
lcd.setCursor(1, 8);
int voice = (analogRead(1)/256);
  lcd.print((voice+1));
 
 
  lcd.setCursor(2,1);
  int pointer = (analogRead(2)/103);
  lcd.print(menuString[pointer]);
if (pointer == 0)
 {
   
   lcd.print(modeString[settingsGrid[voice][pointer]]);
 };
 
if (pointer == 1)
{
   lcd.print(keyString[settingsGrid[voice][pointer]]);
}
if (pointer >= 2)
{
 
  lcd.print(settingsGrid[voice][pointer]);
lcd.print("      ");
};

//ENTER DATA

while (digitalRead(selectButton) == HIGH)
 {
 switch (pointer)
 {
 case 0:
 
   settingsGrid[voice][pointer] = (analogRead(2)/31.5);
     lcd.setCursor(2,6);
   lcd.print(modeString[settingsGrid[voice][pointer]]);
   break;
 
 case 1:
 settingsGrid[voice][pointer] = (analogRead(2)/86);
      lcd.setCursor(2,9);
 lcd.print(keyString[settingsGrid[voice][pointer]]);
   break;

case 2:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 3:
  settingsGrid[voice][pointer] = (analogRead(2)/128);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 4:
  settingsGrid[voice][pointer] = (((analogRead(2)/8)*10)+50);
        lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 5:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 6:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
      lcd.setCursor(2,9);
      lcd.print(settingsGrid[voice][pointer]);
      lcd.print("   ");
break;
case 7:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
break;
case 8:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
  case 9:
 settingsGrid[voice][pointer] = (analogRead(2)/4);
       lcd.setCursor(2,9);
  lcd.print(settingsGrid[voice][pointer]);
  lcd.print("   ");
 }
 }
 //NOTE SELECT, PLAY, ADSR LOOP?
while (digitalRead(playButton) == HIGH)
 {for (int CurrentVoice = 0; CurrentVoice <= numVoices; CurrentVoice++)
 
 if( (long)( millis() - (lastTime[CurrentVoice])+settingsGrid[CurrentVoice][Length] ) >= 0)
 if (random(256) > settingsGrid[CurrentVoice][Length])
 {
 int ModeSig = settingsGrid[CurrentVoice][Mode];
  int SelectNote = random ((((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12));
  if ((bitRead(settingsGrid[CurrentVoice][Mode], SelectNote)) ==1)
  {
   PlayNote = (SelectNote + settingsGrid[CurrentVoice][Key] + settingsGrid[CurrentVoice][Bottom]);
  }
  if (PlayNote > (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12))
  {
    PlayNote = PlayNote - (((settingsGrid[CurrentVoice][Top])-(settingsGrid[CurrentVoice][Bottom]))*12);
  }
//   lcd.setCursor(1,1);
//   lcd.print(PlayNote);
   
//NotePlayer[CurrentVoice].stop();
NotePlayer[CurrentVoice].play(Notes[PlayNote], settingsGrid[CurrentVoice][Length] );
   
 
 }
 
 }
 
 
}

13  Using Arduino / Audio / Re: Tone library music mode/key explorer... on: March 05, 2012, 04:40:42 pm
another thought on ADSR, this one doesn't compile yet but I'm kludging slowly away at it. Got the LCDs today so I'm making measurements for an enclosure and working a little further on the circuit. I think I'll go with a small board that is not a shield in order to keep things a little less noisy.

Code:
startTime[0] = lastTime[currentVoice];

endTime[0] = startTime[0] + attackLength[currentADSRfunction];
while (millis() <= endTime[0])
{
  ENVlevel[currentADSRfunction] = 255 * (millis() - startTime[0]) / (endTime[0] - startTime[0]);
}
startTime[1] = lastTime[currentVoice] + endTime[0];
endTime[1] = startTime[1] + decayLength[currentADSRfunction];
while (millis() <= endTime[1])
{
 ENVlevel[currentADSRfunction] = (([currentADSRfunction] - (255 + (sustainLevel[currentADSRfunction] - 255)) * ((millis() - startTime[1]) / (endTime[1] - startTime[1])));
 //this is screwed up^^^
}
startTime[2] = lastTime[currentVoice] + endTime[1];
endTime[2] = startTime[2] + decayLength[currentADSRfunction];
while (millis() =< endTime[2])
{
 ENVlevel[currentADSRfunction] = sustainLevel[currentADSRfunction];
}
startTime[3] = lastTime[currentVoice] + endTime[2];
endTime[3] = startTime[3] + decayLength[currentADSRfunction];
while (millis() =< endTime[3])
{
 ENVlevel = sustainLevel[currentADSRfunction] - ((sustainLevel[currentADSRfunction]) * (millis() - startTime[3]) / (endTime[3] - startTime[3]));
}
else if
//if (time > Lasttime + noteLength [currentVoice])
//setup and play a note...
14  Using Arduino / Audio / Re: Tone library music mode/key explorer... on: March 03, 2012, 11:00:07 pm
Here's a rough sketch for some thinking about envelopes; this would happen in the loop if I get a TRUE return on a given tone isPlaying()

Code:
   
    delta = (255/ attackLength[currentADSRfunction]);
   
    end_time1 = Lasttime[CurrentVoice] + attackLength[currentADSRfunction];
   
    while (millis() < end_time1)
{
    end_time2 = millis() + 1;
    while (millis() < end_time2)
    ENVlevel[currentADSRfunction]; =  ENVlevel[currentADSRfunction] + delta;
}
    delta = (255 - sustainLevel[CurrentADSRfunction]/decayLength[currentADSRfunction]);
    end_time1 = millisec() + decayLength[currentADSRfunction];
    while (millis() < end_time1)
{
    end_time2 = millis() + 1;
    while (millis() < end_time2)
    ENVlevel[currentADSRfunction]; =  ENVlevel[currentADSRfunction] - delta;
}
   
    end_time1 = millisec() + sustainLength[currentADSRfunction];
    while (millis() < end_time1)
{
    end_time2 = millis() + 1;
    while (millis() < end_time2)
    ENVlevel[currentADSRfunction]; = sustainLevel[CurrentADSRfunction];
}

    delta = (sustainLevel[CurrentADSRfunction]/releaseLength[currentADSRfunction]);
    end_time1 = millisec() + releaseLength[currentADSRfunction];
    while (millis() < end_time1)
{
    end_time2 = millis() + 1;
    while (millis() < end_time2)
    ENVlevel[currentADSRfunction]; =  ENVlevel[currentADSRfunction] - delta;
}
   
   
15  Using Arduino / Audio / Re: Tone library music mode/key explorer... on: March 03, 2012, 10:14:14 pm
I'll post a video if you'd like. I can't say that it works correctly though, but it does seem to follow the key signatures and note widths.

I'm trying to work in ADSR figures now,I think this FOR loop (nested within the loop that handles the values for each tone channel) should handle the generation of the ADSR values, now for the hard part...
Code:

    for (currentADSRfunction = 0; currentADSRfunction <=1; currentADSRfunction++)
    {
    ADSRtotal[currentADSRfunction] =
    (
    attack[currentADSRfunction]+
    decay[currentADSRfunction]+
    sustain[currentADSRfunction]+
    release[currentADSRfunction]
    );
   
    attackLength[currentADSRfunction] =
    ((NoteLength [CurrentVoice] * attack[currentADSRfunction])/ADSRtotal[currentADSRfunction]);
    decayLength[currentADSRfunction] =
     ((NoteLength [CurrentVoice] * decay[currentADSRfunction])/ADSRtotal[currentADSRfunction]);
    sustainLength[currentADSRfunction] =
    ((NoteLength [CurrentVoice] * sustain[currentADSRfunction])/ADSRtotal[currentADSRfunction]);
    releaseLength[currentADSRfunction] =
    ((NoteLength [CurrentVoice] * release[currentADSRfunction])/ADSRtotal[currentADSRfunction]);
Pages: [1] 2 3