Wandsworth Prison is not a place I ever thought I would willingly return to. I was last there four years ago, visiting my son Charlie, who had just been given 16 months for violent disorder following the university fees protests. Whether they deserve to be there or not, seeing your child in a prison grey tracksuit is not something I would recommend to any parent. It was a deeply depressing experience.

And yet, earlier this month, I found myself in Wandsworth again, singing Vivaldi's "Gloria" in a modest-sized room with 20 prisoners. This time around, it was an uplifting and inspiring experience. My wife, Polly [Samson, the writer] and I were there as supporters of the Liberty Choir, directed by an amazing Italian-American woman, MJ Paranzino.

We started with "Down by the Riverside", and afterwards one of the inmates told us he had heard this sung on the radio recorded at the Charleston church, in South Carolina, in tribute to the nine people who had been killed there in June.

The idea of the Liberty Choir is that volunteers from MJ's community choirs – there are four at the moment, based in Balham, Notting Hill, Brighton, and Hastings – come into Wandsworth Prison to form a choir with prisoners who are nearing the end of their sentences. About 20 community singers commit themselves to a two-hour session for eight weeks. The same number of prisoners sign up for the programme, too – and there is a long waiting list to join.

There might be some people who believe that prisoners deserve only punishment. But it is in everyone's interests for those behind bars to be offered alternative paths – exposed to education, given new ambitions – to help them escape the self-destructive cycles that cause people to return to prison again and again.

Gilmour rehearsing with the Liberty Choir in Clapham (Ben Mueller-Brown)

This is what makes society a safer place. It is also what Justice Secretary Michael Gove is promoting with his "through the gate" policy of reintegration, which has been embraced by both Wandsworth's former governor, Kenny Brown, a great early supporter of the Liberty Choir, and the new governor Ian Bickers, along with the prison chaplain Tim Bryan.

HMP Wandsworth is not a place that immediately makes you want to burst into song. While Charlie, was there, he did his best to shield us from the grim reality of the situation. But the sad truth is that for many people prison can be a damaging and dehumanising experience.

As the recent inspector's report on Wandsworth reveals, cuts to funding have put the prison, and those inside it, in a desperate situation. It's not just that men are being left for as long as 23 hours a day in single cells. People are dying. In the past 18 months alone, six people at Wandsworth have taken their own lives.

There are many different organisations that come into prisons, but the Liberty Choir is unusual. First, it is ongoing – week in, week out – and that reliability alone makes it worth supporting.

I am not normally a man of many words. Music is, more often than not, the vehicle for my emotions. It is as necessary to me as breathing, so I know the power that it has. Singing in a choir gives you a sense of elation, and learning about harmony is a powerful and potentially transformational tool. What I really like about this programme is that prisoners are exposed to a different community of people within the prison and when they come out – and this dual aspect of it is the brilliant thing – they are encouraged to join MJ's choirs in the external community. The Liberty Choir doesn't just give prisoners a voice; it offers them a community, too.

The Liberty Choir with David Gilmour front row second left and his wife Polly Samson to his left. Phil Manzanera, the former Roxy Music man who has produced Gilmour's new album on which the choir perform, is front row, centre (Ben Mueller-Brown)

I first heard about the Liberty Choir when one of the two founders – Ginny Dougary, also MJ's partner – contacted Polly to see if we might be interested in supporting their initiative. But it was our son, Charlie, who persuaded us that it would be really worthwhile. He had chosen to go back into Wandsworth Prison to attend a concert performed by the Liberty Choir for the singing prisoners' family and friends. After the concert, he phoned us, enormously excited.

The choir, he said, was something rare: a small pocket of humanity and decency within the brutal prison environment. Such a programme can save lives, not just because of music's therapeutic effect. By encouraging inmates to do something as human and vulnerable as singing, those in positions of power are forced to come to terms with their humanity, too.

Charlie had gone in with two guys who had been in the Liberty Choir at Wandsworth and were now members and supporters of MJ's choir in Balham. He is still in touch with one of them, and he has maintained friendships with a lot of the people he was in prison with. So Polly and I really do get to see things from a different perspective than we would otherwise have done.

What you get loud and clear is that people on the inside are the same as people on the outside. There is no essential difference with most people. It's mainly down to luck and circumstance.

It was Polly's idea to have the Liberty Choir perform on my single "Rattle That Lock". She is the main lyricist on the album of the same name that's coming out next month, as with my other albums. The words of the chorus – "Rattle that lock, lose those chains" – are not supposed to be taken literally. It's about having the courage to be free, in your spirit, whoever you are and wherever you are. Don't disappear under a cloud of apathy – take some sort of action.

In Pink Floyd I used choirs – it's part of the musical palette – most famously, the children's choir, on "Another Brick in the Wall, Part II". But also right back to the album Atom Heart Mother in 1969. There is something magical that happens when people sing together in harmony or in unison. It allows you to escape yourself, to become part of a bigger picture.

I've never been in a proper choir myself, but when I was a schoolboy I used to practise singing harmonies with a group of half-a-dozen boys at morning assembly. It played a valuable part in my musical education and remains one of my few positive memories of school.

The first step towards the recording of "Rattle That Lock" was when I went to rehearse with the south London choir in the hall of Ravenstone Primary School in Balham. My old friend and co-producer of the album, Phil Manzanera of Roxy Music, also came along to sing.

David Gilmour with the choir's co-founder, MJ Paranzino (Ben Mueller-Brown)

We knew MJ was a powerhouse from our first meeting with her but seeing her in action was a transformative experience. It was a big group – about 150 people in the room – and it was inspiring, fantastic, actually – to see the kind but firm way that MJ dealt with them. She got the other members of the choir to support the ex-prisoners in the group, and the singing was both moving and surprisingly skilful. The repertoire was mixed, as it was in the prison, but also ambitious. Polly found it hard to believe my enthusiasm. It almost made her laugh – both the thought of me taking part and the fact that I really want to do it again.

During a break we had a meeting with the Liberty Choir members – both the volunteers and the ex-offenders – to talk about the recording. I was very struck by the enthusiasm of the ex-prisoners. The choir was obviously something that was very good for them, helping bring them into contact with different people and a different sort of life, in a positive way.

A few weeks later, we had our recording session at the Church of the Holy Spirit, off Clapham Common. MJ had the choir fully prepared. She knew exactly what she was doing and the choir absolutely nailed it.

I had met some of the guys at the previous choir session, but I wouldn't have been able to tell who were the ex-offenders and who were the community choir members – which is as it should be because they are all community choir members now.