This line
int8_t numberOfSamples = sense.head - sense.tail;
or this one
numberOfSamples = writePointer - readPointer;
do not seem to work if samples are lost. In this case both pointers seem so point to the same location and the number of samples results to 0. But the FIFO is full.