[Solved] Tone(), seems that is working, but no sound

I’m very new with Arduino, but I’d like to learn faster. Sorry for my ignorance.

I compiled the following sketch

#include <avr/pgmspace.h>

const word song[] PROGMEM = {1318,187,1760,187,1318,187,1975,187,1318,187,1568,187,
1760,187,1318,187,2092,187,2349,187,1318,187,1975,187,2092,187,1318,187,1975,187,
1318,187,1760,187,1318,187,1568,187,1760,187,1318,187,2092,187,1318,187,2349,187,
1318,187,1975,187,2092,187,1975,187,1318,187,1760,187,1318,187,1975,187,1318,187,
1568,187,1760,750,0,0};

void setup(void)
{
  Serial.begin(9600);
  byte pntr = 0;
  word note;
  word duration;
  while (1){
    note = pgm_read_word_near(song + pntr);
    duration = pgm_read_word_near(song + pntr + 1);
    Serial.print(note);
    Serial.print("\t");
    Serial.print(duration);
    Serial.print("\t");
    Serial.println(pntr);
    if ((!note && !duration) || pntr > 255) break;
    tone(8, note, duration);
    pntr += 2;
    noTone(8);
  }
  noTone(8);
}
void loop(void)
{
  
}

The data seen over the serial monitor are pretty correct.
I can hear the click, but no sound is played.
If I load a standard example like toneMelody, then it plays nicely with a mediocre volume.

Am I missing something ?

I don't know the details of how tone() works, but I see a couple of potential problems...

Is the serial monitor showing you the correct-reasonable values for note & duration?

And just to make sure your if-statement isn't causing a break, send-out a little message right before tone() that says something like "Starting tone".

The 1st thing I suggest is removing noTone() because you're calling noTone() immediately after starting the tone.

I also don't see any timing or delays other than duration. duration tells the note how long to play, but it doesn't tell the next note when to play. So, I think you might be playing all of the notes in a few milliseconds as fast as your program can loop.

Good points.
So I suppose that the tone() is in a non blocking condition, therefore I should put a check whether the tone is playing or it's finished.
Something

tone(8,note,duration);
while (tone.isPlaying) {};

As mentioned here
In used noTone(), because I supposed was necessary to inform the system to release the timer in use.

When all else fails RTFM tone() - Arduino Reference.

It says on the first line:-

Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified, otherwise the wave continues until a call to noTone().

So indeed you are stopping the tone almost as soon as it begins.

Also what is this about putting an infinite loop in the setup function. That code should go in the loop function, that is what the loop function is for.

Sorry for my ignorance. I still have a long learning period.
I solved as follow

#include <avr/pgmspace.h>

const word song[] PROGMEM = {
880,375,659,46,880,187,1046,375,0,187,880,375,0,187,1046,375,\
1046,187,1318,375,0,187,1046,375,0,187,1318,375,1046,46,1318,187,\
0,187,784,375,0,187,1046,375,784,46,1046,187,1318,750,0,375
};

byte lngt = sizeof(song);

void setup(void)
{
  Serial.begin(9600);  // just for debugging
}

void loop(void)
{
 byte lngt = sizeof(song);
 byte pntr = 0;
  word note;
  word duration;
  while (1){
    note = pgm_read_word_near(song + pntr);
    duration = pgm_read_word_near(song + pntr + 1);
    if ((!note && !duration) || pntr > lngt) break;
    if (note)
    {
      tone(8, note);
    }
    delay(duration);
    pntr += 2;
  }
  noTone(8);
  while(1) ;
}

I’ve a bit of problem that after a second it starts to oscillate in high frequency. My layout uses only 560 Ohm in serie to 8 Ohm loudspeaker, the power is coming from the USB (just for test).
I’ll set as solved.