Fix a couple crashes on shutdown

AFAICT the "smoothness hackery" (`resampleBuffer[2 + numSamples] = resampleBuffer[2 + numSamples - 1];`) could go out of bounds when `(int)numSamples == grainSize * 4`, which is allowed.  I was getting a somewhat reproducible heap warning in debug, and after changing this I can't get it anymore, so... hopefully this was it.

Also fixes a crash in #2537, since it wasn't ever shutting down the emu thread when you went through the menu to exit, it seems.

-[Unknown]