Scientists have worked out how some of the largest whales in the ocean produce their haunting and complex songs.