Director Seth MacFarlane was looking for songs to use in his new comedy film, “Ted,” that would match the film’s “energy.”

That wasn’t an easy task, given that the R-rated film is about a grown man (Mark Wahlberg) whose closest friend is his childhood teddy bear come to life. And that teddy bear just happens to love crude humor and raunchy parties.

That’s some kind of energy.

Luckily for MacFarlane, his cousin, Tim Mercer of Portland, used to be in a heavy pop-rock band in New York called Daphne.

A few years ago, Mercer wrote and recorded some songs with Daphne that MacFarlane thought would be perfect for raucous, lewd party scenes centered around a stuffed animal.

“I needed music that could be believably played when (Wahlberg) and his teddy bear are partying it up, songs that were appropriately energetic. So it was either going to be Anne Murray or Tim,” said MacFarlane, who does the voice of Ted in the film, in a phone interview.

In case you’ve never seen the adult-oriented, animated TV shows that MacFarlane creates — most notably “Family Guy” and “American Dad” on Fox — be assured he was kidding about Anne Murray.

MacFarlane said even though Mercer is his cousin, and they were close growing up, he listened to a lot of music before picking Mercer’s tracks.

He said he was looking for songs that weren’t big hits and wouldn’t cost a fortune to use.

Mercer’s songs fit that bill.

“I think they listened to, like, 150 songs, then Seth said, ‘My cousin Tim is a musician,’” said Mercer. “I sent them nine songs, and they used four.”

“Ted” opened nationally on June 29 and has gotten mostly good reviews, along with an “R” rating for crude language and situations.

For Mercer, 41, the placement of his songs in a major film comes at a good time. He’s trying to build up his Portland-based record label, Mercer Records, which now consists of just his own music.

Part of the label’s mission is raising money for charities. Mercer said about 75 percent of the money raised from sales of Mercer Records songs will go to specified charities, while about 25 percent will go to the artist and a small amount will go to the label to cover costs.

While launching his record label, Mercer also tends bar at Flatbread Co. on Portland’s waterfront.

He played with Daphne from about 1997 to 2008, before moving to Maine when his father, Peter Mercer, who was a minister at First Parish Church in Saco, fell ill. His father has recovered, but Mercer decided to stay in Maine.

One of Mercer’s songs with Daphne, “Sin,” is on the “Ted” soundtrack album, so sales from that song will go to the soundtrack’s label, Universal Republic.

The three songs used in various scenes as background music are property of Mercer Records, so sales from those will go to Mercer’s label, and some proceeds will go to charity.

Of those songs, “Find Myself Again,” is played during a scene where Wahlberg’s girlfriend, played by Mila Kunis, walks in to find him and Ted on a couch with four women. The other tunes, “Crush” and “Isabelle,” are mostly heard in party scenes.

From sales of “Crush,” money will be donated to the Womanifest Destiny Project on Mount Desert Island, a scholarship program for high school seniors, said Mercer.

From sales of “Isabelle” and “Find Myself Again,” about 75 percent will be donated to the Doug Flutie Jr. Foundation for Autism. Those tunes, and other songs earmarked for other charities, are for sale online at mercerrecords.com.

MacFarlane and Mercer grew up about an hour away from each other in Connecticut, and saw each other often. MacFarlane said he and Mercer have always been “kindred spirits” when it comes to creativity, and have a shared sense of humor.

So it makes sense that he would pick Mercer’s music for this project.

“It was an idea I had for an animated series some time ago, and when it came time for me to make a movie, I felt the premise could work,” said MacFarlane. “It’s an adult fairy tale.”

Staff Writer Ray Routhier can be contacted at 791-6454 or at:

[email protected]