Problem with reading from PROGMEM array

Hello,

I'm currently writing a program that reads an array of times and frequencies to play a song using a buzzer. However, I'm having some trouble reading data from the array, which is stored in PROGMEM. Here is the code:

const uint16_t m1durs[] PROGMEM = {
0,0,0,0,0,0,0,227,240,467,480,707,720,947,.......,95280,95399,95520,96887,
}


m1size = sizeof(melody1) / sizeof(pgm_read_word_near(&melody1[0]));
Serial.println(m1size);
 
placeholderduration = pgm_read_word_near(&m1durs[m1size-1]);
Serial.println(placeholderduration);

As you can see, I'm trying to read the last value in the array. However, while m1size prints out correctly (~940 numbers), placeholderduration prints out a value of around 31000--far from the actual value that should be read.

This weird behavior didn't occur with a different array I had used earlier, though, so I'm really at a loss. Is there something I'm doing wrong?

Did you use "#include <avr/pgmspace.h>" earlier in the code?

Also, which IDE are you using? Shortly above IDE 1.5 (I think it is 1.5.6 and up), the PROGMEM usage changes.

The last values are too large for uint16_t (max 65535). You need uint32_t.

m1size = sizeof(melody1) / sizeof(pgm_read_word_near(&melody1[0]));

What is that pgm_read_word_near doing there? Completely useless, throw it away!

oqibidipo:
The last values are too large for uint16_t (max 65535). You need uint32_t.

m1size = sizeof(melody1) / sizeof(pgm_read_word_near(&melody1[0]));

What is that pgm_read_word_near doing there? Completely useless, throw it away!

Oh, that makes a lot of sense. I can't believe I missed that >.<

So you're saying I can just do

m1size = sizeof(melody1) / sizeof(melody1[0]);

or... something else?

P0ke:
So you're saying I can just do

m1size = sizeof(melody1) / sizeof(melody1[0]);

Exactly.