Ok, I managed to get this things work.
I post here the solution in case someone had to do the same thing:
It was wrong to not send the header when repeating the signal, so the code now is :
void IRsend::sendSamsung(unsigned long data, int nbits,int repeat){
enableIROut(38);
mark(SAMSUNG_HDR_MARK);
space(SAMSUNG_HDR_SPACE);
//Invio il pre_data 0xE0E0 del protocollo http://lirc.sourceforge.net/remotes/samsung/AA59-00382A
unsigned long pre_data = 0xE0E0;
pre_data <<= 16;
for (int i = 0; i < 16; i++) {
if (pre_data & TOPBIT) {
mark(SAMSUNG_ONE_MARK);
space(SAMSUNG_ONE_SPACE);
}
else {
mark(SAMSUNG_ONE_MARK);
space(SAMSUNG_ZERO_SPACE);
}
pre_data <<= 1;
}
//Ora trasmetto il mio segnale
data = data << (32-nbits);
for (int i = 0; i < 16; i++) {
if (data & TOPBIT) {
mark(SAMSUNG_ONE_MARK);
space(SAMSUNG_ONE_SPACE);
}
else {
mark(SAMSUNG_ONE_MARK);
space(SAMSUNG_ZERO_SPACE);
}
data <<= 1;
}
//aggiungo il trail
mark(SAMSUNG_PTRAIL);
space(48962); //gap
}
note that i moved the gap here from the sketch.
It was a pointbreak find this legend to read lirc files : Technical Details
And I suggest also reading the blog of the library's creator, just google IRremote library and you should find him.
If I may help someone with this kind of project let me know, and thanks to johnwasser for finding that mistake