Use another approach for infinite loop:
1) Set a global flag;
2) In spu.c, check the flag and go with the loop, it works for songs that loop;
3) For the songs that does not loop, check the samples, if it's silence for a few seconds, consider it ends and let it end;
4) For the songs that loop, it will know it's not silence in the checking, and if it's not silence for like 15 seconds, consider it a loop song, and don't check silence anymore.
For now it works well.