ATtiny13 Melody player, store Array in Progmem.

So i got around to tuning it using my Guitar, my ears and a slight modification of the sketch which just sounds 2 notes 1 octave apart and when i decided that in my case i was nearly one and a half notes up, i was faced with either changing all the note values (which actually are the real interval values in uS referred to as midi-notes) or doing some multiplier thing... neither seemed like the way to go until i realized the cause being the internal clock just being a little faster than defined. So by adding #define F_CPU 1300000UL i was an awful lot closer, and then i actually ended up bringing the notes closer together just a tad, the compensation for the cycles used must have been excessive. (i had increased it up to 2X8 us per cycle, which brought the 'LOW E' below the one on my guitar, and the 'HIGH E' above it. ) In the end i decided on this

#define F_CPU 1290000UL  // increasing this value will lower the tuning
                        // this is chip specific the standard value is 1200000UL (1.2MHz)

#define PIEZOPIN 4
#define CORR 1 // negative us correction on delay (twice per cycle)
               // increase will increase distance between notes
#define POSCORR  0// positive correction on delay once per cycle 


#define TUNE M78  // set here the note to be tuned

#define QUART 4
#define EIGHTH 2
#define THREIGHTH 6
#define SIXTEENTH 1
#define THRSIX 3
#define HALF 8
#define WHOLE 16
#define THRQUART 12


#include "notes.h"


const uint8_t lengths[] PROGMEM = {0,WHOLE,THRQUART,HALF,THREIGHTH,QUART,THRSIX,EIGHTH,SIXTEENTH};


// rest =0, D=1, D#=2, E=3, F=4, F#=5, G=6, G#=7, A=8, A#=9, B=A, C=B, C#=C, D=D, D#=E, E=F.
// ls nibble = pitch , ms nibble = length

// const uint8_t melody[] PROGMEM = {0x31, 0xF1, 0x0};  octave 'E' used for tuning

//http://en.tapartoche.com/form/page-partition.php?miniature=7197.gif
const uint8_t melody[] PROGMEM = {0x0F, 115,     // set BPM 115
      0x03, 0x06, 0x17, 0x16, 0x18,            0x65, 0x65, 0x85, 0x85,                0xD4, 0xA7, 0x66, 0x68, 0xA6, 0x68,
      0x35,   14, 0xB5, 0xB5, 0x86, 0x58,      0x63, 0x05, 0x66, 0x88,                0xA5, 0xA5, 0xA5, 0xB6, 0xA8,
      0xA5, 0x85, 0x05, 0x86, 0xA8,            0xB5, 0xB5, 0xB5, 0xD6, 0xB8,          0xA3, 0x05, 0xD6, 0xD8,
      0xD5, 0xA6, 0x68, 0xD5, 0xA6, 0x68,      0x13, 0x06, 0x17, 0x16, 0x58,          0x83, 0xB5, 0x86, 0x58,
      0x63, 0x43,                              0x35, 0x66, 0x68, 0x65, 0x56, 0x68,    14, 0x83, 0x85, 0x07, 0x87,
      0x94, 14, 0xA7, 0xA7, 0xA7, 0xB7, 0xD7,    14, 0x83, 0x85, 0x97, 0x87,          0x64, 0x67, 0x67, 0x97, 0x87, 0x67,
      0x65, 0x55, 0x05, 0x06, 0xD8,            0xD3, 0x07, 0xD7, 0xA6, 0x68,          0x83, 0x05, 0x06, 0xD8, 
      0xD3, 0x07, 0xD7, 0xA6, 0x68,        0x83, 0x05, 0x15,         0x63, 0x05, 0x85,           0xA1,      
      0xB3, 0xD5, 0xF5,                    0x83, 0x05, 0xF5,    15, 105,   0xD3, 0xD6,    15, 90,   0xA8, 0xB6,   15, 70,    0x88,      
         0x63, 0x03,        
                                  0x0};  // and the terminating '0' 

uint8_t bpm=120; // standard initial value
bool connextnote=false;

void setup() {
  pinMode(PIEZOPIN,OUTPUT);
  digitalWrite(PIEZOPIN,LOW);
}

void loop() {
  static uint8_t count=0;  
  uint8_t note=pgm_read_byte_near(melody+count);
  if (!note) {
    count=0;
    return;  // straight back into it
  }
  if (note==0x0F) {  // BPM setting for following byte
    count++;
    bpm=pgm_read_byte_near(melody+count);
  } 
  else if (note==0x0E)  connextnote=true;  // connect the next note to it's successor
  else  play(note);
  count++;
}

void play(uint8_t note) {  
  uint8_t len = note & 0x0F; // ls nibble
  note=note>>4; // ms nibble
  uint16_t notelength=pgm_read_byte_near(lengths+len);
  notelength=BPMnote(notelength);
  if (!note) {
    delay(notelength);
    return;
  }
  uint16_t ms=millis();
  uint16_t notebreak=notelength/4;
  if (connextnote) {
    notebreak=BPMnote(1)/4;
    connextnote=false;
  }
  notelength=notelength-notebreak;
  while (((uint16_t) millis()-ms) < (notelength)) {
    digitalWrite(PIEZOPIN,HIGH);
    interval(note);
    if (POSCORR) delayMicroseconds(POSCORR);
    digitalWrite(PIEZOPIN,LOW);
    interval(note);
  }  
  if (notebreak) delay(notebreak);
}

uint16_t BPMnote(uint32_t nl) {
  nl=(nl*15000)/bpm;
  return (uint16_t) nl;
}


void interval(uint8_t type) {
  switch (type) {
    case 1: 
      delayMicroseconds(M64/2-CORR);
      return;
    case 2:
      delayMicroseconds(M65/2-CORR);
      return;
    case 3: 
      delayMicroseconds(M66/2-CORR);
      return;
    case 4:
      delayMicroseconds(M67/2-CORR);
      return;
    case 5: 
      delayMicroseconds(M68/2-CORR);
      return;
    case 6:
      delayMicroseconds(M69/2-CORR);
      return;
    case 7: 
      delayMicroseconds(M70/2-CORR);
      return;
    case 8:
      delayMicroseconds(M71/2-CORR);
      return;
    case 9: 
      delayMicroseconds(M72/2-CORR);
      return;
    case 10:
      delayMicroseconds(M73/2-CORR);
      return;
    case 11: 
      delayMicroseconds(M74/2-CORR);
      return;
    case 12:
      delayMicroseconds(M75/2-CORR);
      return;
    case 13: 
      delayMicroseconds(M76/2-CORR);
      return;
    case 14:
      delayMicroseconds(M77/2-CORR);
      return;
    case 15: 
      delayMicroseconds(M78/2-CORR);
      return;
  }
}

which includes the BPM adjusting option and a way to let the next note flow into the one that follows it adding up to 872 bytes, with a few notes to spare, and a few notes lengths and 150 bytes at 1 byte per note i am confident i can play most tunes i want to and soon when i leave the lights on in my car the French national anthem (i got the errors out that got in while copying the melody) will sound (i have a French car)