rewrote pitch detection code to make it better