If you have in your DSP audio settings for example HLE, but playback a DTM file with LLE settings enabled, it will eventually desync. You must have matching DSP settings before playing back the DTM file.

What steps will reproduce the problem?

Set DSP to LLE, then record a DTM file. Play for a bit, and stop recording the DTM file. Change audio setting back to HLE, and play back the DTM file you just created.

Which versions of Dolphin did you test on? Does using an older version of Dolphin solve your issue? If yes, which versions of Dolphin used to work?

Various versions, ran into the issue most recently with 4.0-8246 when encoding 007: Agent Under Fire, but I have had this issue happen to me while working on a TAS for Ed, Edd n Eddy: The Mis-Edventures which uses version 4.0-9199.