It’s important to remember that dogs are descended from wolves and wolves communicate by howling. So dogs come by howling and whining naturally, although not all dogs use this ability. It has possibly been diluted with domestication.
When wolves howl, the sound carries and they are able to communicate over very long distances. Howling can show location and can be a form of announcing one’s territory. A lost wolf can find its way back to its pack merely by recognizing the howls of its own family.
When your dog whines or howls when hearing a siren or even someone singing, there could be more than one reason. He/she could be announcing his presence, trying to make contact with what sounds like another dog’s call or answering that call.
Since dogs can hear sounds inaudible to humans, sirens and other such sounds do not cause pain.