I always have music playing in the background during my D&D sessions, and it's never random or generic.
Over the years, I've built up (and continue to) a big library of looping instrumentals I have set up in an audio program. I use an old SONAR edition, but I suppose Audacity would do as a free alternative. Prior to a session, I choose between 10-20 songs that I think might be used. Afterwards, I simply select a song and start it, and it loops automatically where I set it up.
I actively try to use the same piece of music in the same situations. Iconic, named towns get their own themes (we're up to 4), as do iconic, recurring places (we're up to 7). Situations, like relaxing and tension, also get their own unique song. Half of my set-up songs are for battles against particular groups.
Since I need my songs to loop seamlessly in the background, 90% of them come from video games. A select few others are from movie soundtracks or other sources. Coincidentally (or not), I got most of the songs from RPGs. Oh, and most of the songs are unknow to my players (and often to me!) outside of the game. I once had a Final Fantasy maniac among my players, and he'd be able to name half of the campaign's soundtrack.
Some themes have really stuck with my players.
[ame="http://www.youtube.com/watch?v=LUDwM79ZXr4"]
Fire Emblem: Path of Radiance - The Enemy Draws Near[/ame]
Used for encounters mainly composed of enemy rank-and-file soldiers.
[ame="http://www.youtube.com/watch?v=JOnc3n9l4wI"]
Dirge of Cerberus - Messenger of the Dark[/ame]
Battles where the center of attention is an enemy mage.
[ame="http://www.youtube.com/watch?v=TcP0Fq9Hjlk"]
Record of Lodoss War - Road of Dragons[/ame]
I intended to use this song as a prelude to battles against skeletons, but I messed up and let it play through a whole battle. It stuck, and I used it for the battles themselves afterwards.
[ame="http://www.youtube.com/watch?v=CBSNskL7lzQ"]
Final Fantasy XI - Black Coffin[/ame]
When a prolonged tense situation occurs, this song loops in the background.
[ame="http://www.youtube.com/watch?v=UeaeAp4Q3I4"]
Final Fantasy XII - The Barheim Passage[/ame]
A few times over the campaign, the players had sneaky mountain night missions, and I used this theme.
[ame="http://www.youtube.com/watch?v=YDSRYS1vjHo"]
Final Fantasy XI - Battalia Downs[/ame]
Any hideout, especially after an action-packed day.
[ame="http://www.youtube.com/watch?v=uNqamxkWkCk"]
Final Fantasy XII - A Land of Memories[/ame]
Good town songs are really hard to come by (unlike battle songs!), and this one had just the right amount of nostalgia for a city critical to the plot.
[ame="http://www.youtube.com/watch?v=aoiwkFzqmF0"]
World of Warcraft - Dun Morogh[/ame]
Generic travelling. Frequently used right after a battle, so it's almost become an end-of-battle tune.
[ame="http://www.youtube.com/watch?v=U-bQwgkvthE"]
Final Fantasy XII - The Tomb of Raithwall[/ame]
Catacombs.
And finally...
[ame="http://www.youtube.com/watch?v=tSLuB7RM1aY&fmt=18"]
Final Fantasy Advent Children - Battle in the Forgotten City[/ame]
Now I had known that one for awhile, and I knew exactly where it would fit. When I listen to it, it feels thunder-y and electrical, and also ominous. At some point in the campaign, the critical-to-the-plot city was to be spontaneously invaded by an overwhelming number of air elementals, making any attempt to get out of a secure building extremely hazardous.
Well my players got pumped for battle as soon as they heard it, and they soon started tapping the beat until it was their turn. They looked forward to encounters with elementals for the length of the whole invasion and were saddened by the song's subsequent departure.
Unfortunately, I have not found a way to realiably and seamlessly switch to another song just for a quick jingle, so when I put a song on, it usually stays for a few minutes. However, the few times I have been able to make timely switches have been memorable.
The only thing I regret is not having a more dedicated audio program. All I want is a list of songs I can play from the start with a click or two and have them loop seamlessly at the exact times I choose. The closest program I found is
Mixere, but it makes looped songs play from the beginning of the loop.