Ed Sheeran has told the High Court he does not "borrow" ideas from unknown songwriters without credit.
The singer-songwriter has been accused by two other songwriters of copying parts of his 2017 hit Shape Of You.
Sami Chokri and Ross O'Donoghue's barrister suggested Sheeran treated lesser-known songwriters differently from famous ones.
Sheeran denied this, telling the court he had cleared parts of songs with "lots" of unknown artists.
Shape of You was number one for 14 weeks in the UK in 2017, becoming the best-selling song of the year around the world.
Chokri and O'Donoghue claim the song's "Oh I" hook is "strikingly similar" to part of their track Oh Why, which was released by Chokri under the name Sami Switch in 2015.
On Friday, their barrister Andrew Sutcliffe QC claimed Sheeran "borrows ideas and throws them into his songs, sometimes he will acknowledge it but sometimes he won't".
But Sheeran denied the claim that he is a "magpie" who lifts other people's work without acknowledgment, pointing out that he has often shared credit with lesser-known artists, including Shivers and Visiting Hours, and a song that sampled an "unknown composer's" work from Buffy The Vampire Slayer.
"All those examples are not famous artists that we've cleared songs with and that's what I have to say on that," he told the court.
Sheeran created Shape of You with co-writers Steve Mac - real name Steven McCutcheon - and Snow Patrol's Johnny McDaid, both of whom were also in court.
After its release, Sheeran added the team behind TLC's 1999 single No Scrubs to the song's writing credits after some commentators pointed out similarities.
On Monday, Mr Sutcliffe told the star: "The evidence is overwhelming that at the time of writing Shape of You, your songwriting process involved collecting ideas."
Sheeran replied: "You say it's overwhelming, I don't agree with that."
In written evidence, the singer said the contested element of Shape of You was "very short", and the relevant parts of both songs were "entirely commonplace".
He said: "Even so, if I had heard Oh Why at the time and had referenced it, I would have taken steps to clear it."
He added: "I have always tried to be completely fair in crediting anyone who makes any contribution to any song I write.
"I do refer to other works on occasion when I write, as do many songwriters. If there is a reference to another work, I notify my team so that steps can be taken to obtain clearance.
"I have been as scrupulous as I possibly can and have even given credits to people who I believe may have been no more than a mere influence for a songwriting element. This is because I want to treat other songwriters fairly."
Dressed in a sharp black suit, Ed Sheeran is firm, determined and just a little bit irritated on the stand as lawyers for Chokri and O'Donoghue deconstruct his songwriting process, looking for hints that he might take inspiration from outside sources.
Sheeran testifies that he mostly works in collaboration with other writers, and that it's often hard to identify who has written each individual part of a song once it's finished.
Referencing his Shape of You co-writer Johnny McDaid, he says: "My and Johnny's writing partnership is very much like a game of tennis. He'll say something and I'll say something back. We're quite quick when we go back and forth."
Asked repeatedly whether he is responsible for the chorus to his 2015 song Photograph, Sheeran replies tersely: "I honestly couldn't tell you. I don't know. We wrote the song together." It's a phrase he returns to several times throughout the morning's questioning.
Photograph is relevant because it was the subject of a separate copyright claim from Martin Harrington and Thomas Leonard, who wrote Matt Cardle's 2011 single Amazing. The duo were eventually given a share of the song's royalties and a £4m lump sum in an out-of-court settlement.
Sheeran says he settled the claim because it was a "nuisance" and "more trouble than it was worth". Asked why he would pay out such a "substantial" sum instead of taking the case to court, he says he did so on the advice of his lawyers.
Mr Sutcliffe said Sheeran had known about Chokri before Shape Of You was written because the grime artist had tweeted Sheeran directly, and the singer had given a shout out to Sami Switch on stage in 2011. But Sheeran replied: "This isn't stuff that's true."
Chokri had also appeared on YouTube channel SBTV at around the same time as Sheeran, who described its founder Jamal Edwards as his "best friend".
But he said the music entrepreneur, who died last month, didn't share songs like Oh Why with him. Instead, the pair would "talk about football, talk about his mum, talk about theatre", he said.
Sheeran was also asked about his role as a talent-spotter for his own label Gingerbread Man Records. He denied being aware of Oh Why, saying he had just signed Jamie Lawson to the label and "wasn't looking for anyone else" to work with.
The musician told the court he quit social media in 2015, adding that for "the whole of 2016" he was "off" social media and was using a "flip phone from Tesco".
In May 2018, Sheeran and his co-writers issued proceedings asking the High Court to declare they had not infringed Chokri and O'Donoghue's copyright.
The pair then issued a counter claim for copyright infringement. The trial is expected to continue for about three weeks.