Disclaimer: I'm no kernel expert, so what I say could be completely wrong.

But, it seems to me there's a potential race condition in the empeg_audio2.c driver. I'm not sure if the kernel will let multiple threads, or multiple processes enter audio_write at the same time. Equally, I'm not sure if the player would even try to do this. I do know that when I stuck some code in the middle of the dev->head twiddling stuff, I had a similar problem (but only at the end of tracks). When I moved all the dev->head twiddling stuff together, and put my stuff after it, the problem appeared to go away, or at least reduce in frequency.

So, my question is, is it possible for multiple player threads to call audio_write at the same time?

Or alternatively, have I completely misunderstood, and am spouting a load of nonsense?

Richard.