Miley Cyrus is thankful her drug mishap made Pharrell Williams want to work with her.

The 19-year-old singer - who was caught on camera smoking the psychedelic drug salvia in December 2010 - is grateful for the highly publicised incident because it made hip-hop producer Pharell Williams want to make a record with her in order to set her ''free''.

The former Disney star told Marie Claire magazine: ''It was magic. Pharrell said, 'Don't be offended because this is how I talk, but [I thought], That b***h is actually living.

''She's not sitting there with her Momager's chain on her door. I want to free that b***h. I want her out of her cage'.''

The 'Hannah Montana' actress - who is engaged to 'Hunger Games' star Liam Hemsworth - said the pair had a magical time in the recording studio and Pharrell has since become like a brother to her.

Miley gushed: ''I'd never worked like that before. I was talking to him like he was an older brother, and everything I said was going onto the track...

''I got in there with Pharrell, and it was magic. Oh, dude, I'm so happy.''

The teen singing sensation added that the N.E.R.D. rapper has always been a fan of her talent.

Miley said: ''Pharrell saw me dancing to Madonna songs on YouTube when I was young and said, 'I see something in her'.''

The singer is pleased a positive outcome has come out of the controversial video which threatened to ruin her career.

She lamented at the time of the incident: ''I'm not perfect. I made a mistake... I'm disappointed in myself for disappointing my fans.''