Chadbang,
I have finally realised the cause of my hearing music as I wake up - the birds outside my window. As they sing they set up a certain rythym (cadence), which my mind searches for and finds (matches) a melody which has the same timing. While they sing I hear their / my song.

The most glaring example of this is where I had written in my mind the most beautiful and perfect rap song. I awoke to find that it was caused by two crickets outside rubbing their fore legs back and forth.
Another time, a dream of flying saucers and their death rays were caused by a truck's flipper muffler idleing across the street.
Another time, I (unknowingly) slept by a babbling brook. I got absolutely no sleep that night.

The name of the motel? "The Babbling Brook Motel". I believe it was in Wyoming or Montana.
Are you sure that there are no extraneous noises causing your sleeplessness?