audio: move repeating code to a function