Nothing is more exciting than to hear the tunes one has composed played for the first time by a 50-piece orchestra," wrote Charlie Chaplin in his autobiography. Perhaps because he was so multifaceted - a comic actor of extraordinary imagination, an untiring, perfectionist director, the co-founder of United Artists - it seems unfair that Chaplin had one more talent. But, though it is largely overlooked today, the creator of the Little Tramp was an accomplished musician who wrote soundtracks for nearly all of his films - although he wasn't always credited, as in the case of The Great Dictator, whose score he co-wrote. His music for Limelight won him an Oscar; Petula Clark even had a massive hit with Chaplin's This is My Song, a tune from A Countess from Hong Kong.

Chaplin's scores have a foot-tapping catchiness; they get stuck in your head and you find yourself whistling the tunes. His feel for music sprang from a childhood submerged in the songs and waltzes of the music hall. As a child, Chaplin worked on the stage as part of a clog-dancing troupe, the Eight Lancashire Lads, and later for the successful comedy company owned by impresario Fred Karno. He played the piano, and as a boy he had acquired a violin and a cello (strung in reverse, as he was left handed). As he could not read music, he played all his instruments by ear. He wrote in his autobiography that "since the age of 16 I had practised from four to six hours a day in my bedroom. Each week I took lessons from the theatre conductor or someone he recommended_ I had great ambitions to be a concert artist, or, failing that, to use it in a vaudeville act."

But why did Chaplin end up composing? The clinching factor was the introduction of sound to the movies. He conceived of his film City Lights as silent, but sound became an option while the movie was being made. According to Carl Davis, who conducts Chaplin's score of The Gold Rush in London on Saturday, "he made an astonishing decision - to keep City Lights a 'silent' film, that is, without dialogue. But he took advantage of the new technology to write and record a score, and sound effects too. That is when the idea of Chaplin as composer evolved."

This arrangement must have suited the talkies-resistant Chaplin down to the ground. Before the introduction of sound, Chaplin had himself selected the music to be played in cinemas with his films. But the invention of the recorded soundtrack gave him absolute control - a concept that was of prime importance to Chaplin in his film-making. Sound allowed him to create an ultimate artwork, complete in every way. Nothing would be left to chance; everything would now be perfectly, ineffably, Chaplin. The technique was so successful that later Chaplin went back to his earlier silent movies and rereleased them with soundtracks - which is how the The Gold Rush, originally made in 1925, acquired its score in 1942.

Because Chaplin could not read music, when it came to writing soundtracks his hums and improvisations had to be taken down and orchestrated by collaborators. "His assistants had a terrible time," says Davis. "It must have been torture. He was very, very moody." Chaplin himself wrote about this process: "Sometimes a musician would get pompous with me, and I would cut him short: 'Whatever the melody is, the rest is just a vamp.' After putting music to one or two pictures I began to look at a conductor's score with a professional eye and to know whether a composition was over-orchestrated or not. If I saw a lot of notes in the brass and woodwind section I would say: 'That's too black in the brass,' or 'too busy in the woodwinds'."

Chaplin's early experience of music hall also informed the way he worked with music. As he said in a 1952 radio interview: "I use music as a counterpoint, and I learned that from the Fred Karno Company. For instance if they had squalid surroundings with a lot of comedy tramps working in it, they would have very beautiful, boudoir music, something of the 18th century, very lush and grandiose, and it would be satirical, a counterpoint."

That technique is certainly evident in The Gold Rush, particularly in the famous scene in which the Little Tramp and a gold prospector are stuck in a remote, snowbound hut without food. It is Thanksgiving Day, and the Tramp comes up with the idea of boiling his boot for dinner. Says Davis: "The boot is produced, and Chaplin handles it as if he is a maitre d' at the Savoy. He carves it exquisitely as if it is a gourmet dish, a roast rib of beef. The nails are treated as if they are elegant little bones; the shoelaces are like delicate spaghetti. To support this performance he gives us the music of a palm court trio - of just the sort you could hear at the Savoy. The humour lies in the contrast between the elegance of the performance and the music, and the scene of desolation and despair."

In his autobiography Chaplin wrote, "Musical arrangers rarely understood this [technique]. They wanted the music to be funny. But I would explain that I wanted no competition, I wanted the music to express sentiment." It does, and sentimentality too. In The Gold Rush, Chaplin has invited his heartthrob, Georgia, to New Year's Eve dinner (Georgia herself has a charming love theme, adapted from a piece of Brahms piano music). Georgia accepted the invitation only as a joke, and she doesn't show up. Instead she celebrates with her friends in the local dance hall. The strains of Auld Lang Syne just reach the Little Tramp's hut, where the table lies set and the candles are burnt down.

Chaplin's celebrity existence in prewar California brought him into contact with a starry collection of classical musicians, by whom he seems to have been much admired. There is 1930s film footage of him improvising duets with the composer and pianist Germaine Tailleferre. He was friendly with composer Hanns Eisler (and had a sticky time at a press conference after the release of 1947's Monsieur Verdoux, when he was asked to respond to allegations that Eisler was a communist). He was photographed with the great violinist Yascha Heifetz, and he was on dining terms with Horowitz, Rachmaninov and Schoenberg.

Stravinsky was struck with the idea of making a film with Chaplin; over dinner Chaplin invented a surrealist scenario, involving a decadent nightclub that would include a depiction of Christ's crucifixion. Stravinsky was shocked - he regarded the idea as sacrilegious. Chaplin soon lost interest in the thought.

"Composers had a very strange idea of how they might work with Chaplin," says Davis. "Schoenberg, for instance, thought he could write a score first and have Chaplin write the scenes around it. But it is natural that these great artists should have been attracted to Charlie. He was one of them. His scores, within the boundaries that he set himself, are perfect. I would not change a note of them."

 The Gold Rush, with a live score conducted by Carl Davis, will be screened at the Royal Festival Hall, London SE1 (020-7960 4242), on Saturday.