move audio analysis code into separate function