inspired from Audio programming book (Lazzarini)