Improves thread-safety #1572

Further improvements of thread safety, however, there are still issues in most public functions such as setPositionMS, setVolume, getIsPlaying, getIsPaused, getPositionMS, setPan, setSpeed, setLoop and FFT-related functions.