remove code duplication

Removing the code duplication also reduces the calls to alsa.