Great movie songs have served varying purposes over the years. They can both set the scene and act as a theme song (“Fame,” “Falling Slowly” from “Once”), capture a mood (“Things Have Changed” from “The Wonder Boys”), serve up an emotional coda (“My Heart Will Go On” from “Titanic”) or even define a character (“Sooner or Later” from “Dick Tracy”).
But how does a single song capture a movie’s essence and bottle its spirit?

Punk rocker Patti Smith, who wrote the lullaby that features prominently in Darren Aronofsky’s “Noah,” “Mercy Is,” says the director “wanted a song that has a nostalgia for Eden, a time before the fall when man was in direct communication with God.”

For her first original film tune, she read the Psalms and the Song of Solomon to get a sense of the appropriate language. “It had to be a comforting and hopeful song, because it’s sung to a child before he goes to sleep,” she adds. “I didn’t want it to be archaic; it had to sit within the film’s own history.”

History plays a prominent role in “Selma,” about the Rev. Martin Luther King Jr.’s crusade for voting rights in Jim Crow-era Alabama. And yet rapper Common, who co-wrote “Glory” for the movie with John Legend, wanted the end-credits song to feel timeless.

“I feel that ‘Glory’ has the potential to be a song that people can relate to 30, even 100 years from now,” says Common, who plays James Bevel (an influential Nashville preacher) in the film, and immersed himself in the story to the point where he could musically convey “the DNA of Selma.”

In another fact-based historical drama, Angelina Jolie’s “Unbroken” — about Olympic runner and WWII POW Louis Zamperini — the strains of Coldplay’s acoustic guitars and Chris Martin’s vocals (in the song “Miracles”) catch viewers up to a contemporary coda to Zamperini’s life, shown through newsreel footage and epilogue cards.

“A big requirement for (Jolie) was, ‘If this song’s going to work, it has to feel organic, like it’s part of the fiber of the film,’ ” says Mike Knobloch, Universal’s president of film music. “If people feel like, ‘Wait a minute — somebody turned on the radio in 2014,’ then we’re going to have a problem.”

For songwriter Paul Williams, a great movie song acts as “a bridge to the emotion that we want you to feel about the scene.” For fellow tunesmith Diane Warren, “it’s a song that enhances the movie, that accentuates what’s going on and takes it to another level.”

Both are multiple Oscar nominees going back decades (and in Williams’ case, an Oscar win for “Evergreen,” from 1976’s “A Star Is Born”), and both are old hands at working musical magic for films as diverse as “The Muppet Movie” and “Armageddon.”

This year, Williams collaborated on two songs for the animated “The Book of Life” with Argentinian composer Gustavo Santaolalla: “The Apology Song” and “I Love You Too Much.”

“The idea of writing a song where a young bullfighter is making amends to the spirit of every bull that ever died is a magnificent idea, a challenge of spiritual magnitude,” Williams says. As for “I Love You Too Much,” “it’s so lovingly childlike. I would like to think that it’s elegant in its awkwardness.”

Warren’s “Grateful,” a power ballad that concludes “Beyond the Lights,” summarizes the journey of a young singer named Noni (Gugu Mbatha-Raw), whose career ambitions crash and rise again. “This is Noni’s song,” Warren says. “She’s gone through all this stuff, and she’s really who she is because of it. She literally finds her own voice.”

Another character who finds her own voice is Keira Knightley’s from the record-biz love story “Begin Again.” The film’s signature song, “Lost Stars,” sung on-screen by Knightley and Maroon 5’s Adam Levine, was co-penned by ex-New Radicals singer-songwriter Gregg Alexander (with Danielle Brisebois) after reading John Carney’s script. The film’s original title, “Can a Song Save Your Life?,” hints at what Carney and company were striving for.

“We were trying to come up with something that brought it all together,” Alexander says. “ ‘Lost Stars’ was the one that John seemed to connect with and champion the most.”

Alexander likened the effort to trying to write a “Purple Rain,” Prince’s title tune that inspired him as a musician early on. “It was one of those songs that (as a songwriter) happen maybe once a decade, where you want each line to say how you see the world or yourself in it.”

One of the year’s most infectious, and ironic, songs is “Everything Is Awesome” from “The Lego Movie,” initially heard on the radio by central character Emmet as he heads to work (and then sung in more complete form over the end titles by Tegan & Sara).

Songwriter Shawn Patterson (“Robot Chicken”) recalls his initial conversations with editor Chris McKay as including words like “poppy” and “catchy” along with the idea that teamwork is important and that Emmet is a happy-go-lucky guy who wants to be loved. “I sat at the piano, bouncing back and forth for a couple of weeks,” Patterson says with a laugh. “It just started falling together in phrases.”

For singer-songwriter Sia, the “Annie” remake offered a chance to augment an already classic musical-theater score that she adored as a little girl growing up in South Australia. (“I went to meet with director Will Gluck and burst into tears — in a business meeting!” she says with a hint of embarrassment.)

In the film, “Opportunity” (co-written by Greg Kurstin) is sung onscreen by Quvenzhane Wallis. “Will had the title and some rough lyrics,” Sia says. “A good movie song describes an emotional landscape in a scene. I tend to communicate as simply as possible when I’m trying to appeal to a broader audience. Simplification is the magic trick.”

In “Big Hero 6” — Disney’s kid-friendly origin story about a band of young, nerdy superheroes — Fall Out Boy’s scratchy anthem “Immortals” cranks up over a pivotal montage as the characters transform into their super selves, helping advance the plot within the movie.

The band chose not to explain what each character was doing — “like a Ninja Turtles song,” says bassist and lyricist Pete Wentz — but rather embody the message of the film. “The idea that the way you live on forever is through other people, which is what (protagonist) Hiro really needs to learn, was a big part of the lyrics.”

Another animated feature, “The Boxtrolls,” exposes important plot background with “The Boxtrolls Song,” written by “Monty Python” alumnus Eric Idle (with composer Dario Marianelli) for the film’s villain. Idle says he was asked “to write a song for Sir Ben Kingsley to sing in drag. Who could resist such a challenge?”

The music hall showstopper, infused with cheeky humor, establishes important backstory, and needed to tell “the awful warning tale of a snatched baby in order to stir up hatred for Boxtrolls,” says Idle. “I felt it should have a kind of banjo, central European, Kurt Weill feel to it.”

Lana Del Rey’s title song from Tim Burton’s “Big Eyes” serves as an internal monologue for Amy Adams’ misused protagonist, the painter Margaret Keane, whose husband has claimed credit for all her work. As she languishes around a grocery store, haunted by this disconnection from her art, Del Rey’s spectral, molten vocals sing of “big eyes and big lies.”

The song’s orchestral character kept Danny Elfman’s score in mind. “The stuff I do with Lana tends to be very filmic, anyway,” says Daniel Heath, the track’s co-writer and producer. “She’s got a very haunting voice, and it definitely belongs in a movie world.”

Lorde’s song “Yellow Flicker Beat” is both coda and bridge for “The Hunger Games: Mockingjay — Part 1.” As the story’s first of two acts fades to black, Lorde’s vocals cut through a capella, slowly climaxing into a moody, dance-floor anthem.

“I kept coming back to the idea that the end of this film is the point of no return for (Katniss),” says Lorde. “The song needed to have this very disturbed, dark intimacy, and also this explosive moment letting you know that she is about to go postal.”

And if you have a coda that also distills a film’s narrative, such as J. Ralph’s “Until the End” for the doc “Garnet’s Gold,” about a man’s quixotic search for hidden treasure, then you have the best of both worlds. Ralph says he and director Ed Perkins wanted music that captures Garnet’s life and the film’s complex range of emotions.

“I was extremely inspired by this story and the words and music came to me very quickly,” says Ralph of the song performed by Liza Minnelli and Wynton Marsalis during the film’s final scene and into the end credits. “Ultimately ‘Until the End’ would develop into the theme of the entire film. As no other dialogue or sound would be playing, the story’s resolution solely relies on the song and Garnet’s silent performance on screen, like in a classic silent film.”