Move helper function into #ifdef

The function only got called if sound support was enabled, so move it
into that particular #ifdef to avoid an unused function warning.