Probably it's because of a timer... (what else does this timer trigger?)
A subroutine (or nested subroutine) from the main loop at some level should call what is essentially the 'music engine'. You'll find that the game should (through every loop) update the buffer to include the audio data in a timely fashion.
Regardless of anything else, whenever you run a script the main loop is still occurring at a fundamental level every frame that the game runs. If you want to control what audio is playing, the most direct method would be to send commands to the game's sound engine. (Which is basically what any music change commands in scripts, etc. would do anyhow)