Singing is most likely there to attract females as well as establish territory. We know that there's a difference between singing and calling - bird calls are there to alarm other birds, as well as other animals. It's a response to danger, most often coming in the form of a predator.