Arduino running slow after many calls to large arrays- Better way to handle?

I'm attempting to chain an Arduino to a musty stone wall in a dungeon and make force it play for me Still Alive, just so I know it's still alive in there. I'm attempting do it with asynchronous 2-channel polyphony two rotary axes facing captured opera singers (one for the bassline and one for the melody), so the functions that call each play() command to play the right note need to be non-blocking for the asynchronous part. I'm using the Tone library (not the one that comes w/ the IDE) so that's step one. The other part is what I described. I made a test implementation that is supposedly non-blocking, however, it's slowing down the Arduino to a slow and painful crawl (I guess I DID chain it to the wall...), and I think it's my inefficient use of arrays, but I don't know a better way to do it. Input? My code that does the crunching below.

bool isTunePlaying = true;
  int tone1index = 0;
  int tone1delay;
  
  while(isTunePlaying)  {
    if(!tone1.isPlaying())  {
      tone1delay = (double(note_duration[tone1index])/double(divisions))*60/double(tempo)*1000;
      if(note_midi[tone1index] == 0) tone1.play(0, tone1delay);
      else  tone1.play(midifrequencies[(note_midi[tone1index])-21], tone1delay);
      tone1index++;
    }
    
    if((sizeof(note_duration)/sizeof(int)) == tone1index) isTunePlaying = 0;

I'm using the Tone library (not the one that comes w/ the IDE) so that's step one.

So, you are using the other one, huh? You like mysteries, I presume, since you haven't told us which tone library you are using.

The size of the array has nothing to do with the time it takes to access an element in the array, or to perform calculations using that element.

You really will need to do a better job of describing your problem.

that is supposedly non-blocking,

while() is NOT a non-blocking statement.

So, you are using the other one, huh? You like mysteries, I presume, since you haven't told us which tone library you are using.

This is the library. I thought there was only the one.

You really will need to do a better job of describing your problem.

Heh, sorry about that. I was typing it out quickly, as the renegade cat-murdering PICs were onto me, and I thought I had it explained. Silly Me. The Arduino will make the beep at the correct tune for the correct time, but hangs for a second after doing so, then goes on to the next note and repeats the process.

while() is NOT a non-blocking statement.

I know that it's not non-blocking, that's not the part of the code I'm calling non-blocking. It's the way it plays the tune each time it executes the while() block that's non-blocking. If I were to add a second part in the while() block, it should play as well as the first part, even if one part were independent from the other. (which is the case with Still Alive- the bassline is a simple 1-bar verse that is repeated and only slightly changed. The other part moves independently.)

Dr_Quigley: I'm attempting do it with ... two rotary axes facing captured opera singers ...

Wow. Just wow.

    if((sizeof(note_duration)/sizeof(int)) == tone1index) isTunePlaying = 0;

When is this condition ever going to change?

I thought there was only the one.

That's why you were careful to explain that you were not using the one that came with the Arduino IDE, I guess.

If you put each { on its own line, and use Tools + Auto Format, you will see that you did not provide all of the while loop.

I know that it's not non-blocking, that's not the part of the code I'm calling non-blocking. It's the way it plays the tune each time it executes the while() block that's non-blocking. If I were to add a second part in the while() block, it should play as well as the first part, even if one part were independent from the other. (which is the case with Still Alive- the bassline is a simple 1-bar verse that is repeated and only slightly changed. The other part moves independently.)

Perhaps from the point of view of a musician this "explanation" makes sense. I'm not a musician. I can't even play the radio.

From the point of view of a programmer, the collection of words above, arranged in that order, is NULL content.

Post all of your code if you really want help.

Serial.print() can be used to debug loops like this.

If I were to add a second part in the while() block, it should play as well as the first part, even if one part were independent from the other.

Translating your requirements a bit you want to do two or more things "at once". This is where the so-called "blink without delay" idea comes into its own. We had a thread about it recently here, and I adapted it here:

http://gammon.com.au/blink

Have a read of that. Basically you keep track of time (like a musician does) and when a certain amount of time elapses you do something else. Think of it, in music terms, that if one hand is playing a crotchet, and one a quaver, then whichever one finishes first, that hand does something else (the next thing in the music). You don't have each hand play a note and hold it, doing nothing, until the note ends.