The O Antiphons developed from an ancient custom in the Church going back to the seventh or eighth century. There are seven of these special antiphons, and their texts spring from the Old Testament Hebrew Scriptures, the Prophetic and Wisdom Books. They are found in the Liturgy of the Hours, or Breviary, which clerics, some religious orders, and some lay people use for daily prayer.
The O Antiphons are short prayers recited before and after the Magnificat, the great prayer of Mary used during Vespers, evening prayer, beginning on December 17, seven days before the Vigil of Christmas (December 24). The seventh and last antiphon is sung during Vespers of December 23. They are called the "O Antiphons" because they all begin with the letter-word "O" for they address Jesus by one of His Old Testament titles. They are fervent prayers asking Him to come to us.
Remember that Advent is about the many ways in which the Lord comes. He came at Bethlehem in the fullness of time and so, in the liturgical year, he comes to us sacramentally. He will also come again at the end of the word, as Judge of the living and the dead. Christ comes to us also in the consecration of bread and wine by the priest at Holy Mass and, in a special way, perhaps the most profound way, in a good Holy Communion. He comes in the person of the priest, who is alter Christus, another Christ. He also comes in the person of our neighbor, especially those who are in need of the spiritual and corporal works of mercy. Christ comes in many ways and, during Advent, John the Baptist has been reminding us in the liturgy to "make straight His paths".
There is a little-known fact about the order of these ancient O Antiphons. This is not apparent in English, but it can be seen clearly in the official language of the Roman Catholic Church: Latin. The Latin versions of each of the titles of the Messiah: Sapientia (Wisdom), Adonai (Lord), Radix (Root), Clavis (Key), Oriens (Dawn), Rex (King), and Emmanuel (Emmanuel). Take the first letters of each of the titles and write them backwards, thus counting down the days of the feast: EROCRAS or "ero cras." This means in Latin "I will be (here) tomorrow".
The song "O Come, O Come, Emmanuel" is simply a slightly modified sung version of the seven O Antiphons.