Inspired from Audio programming book (Lazzarini)