You've gone through all the trouble of vacuuming the carpet, pretreating spots and giving heavy traffic area extra shampoo, but instead of a sweet-smelling carpet you're left with a musty sour smell. The problem may be that you've done too a good a job of saturating the carpet and the pad with cleaner. While the carpet may feel dry, the pad was wet and prone to mildew and mould.
Mix a solution of 1 cup white vinegar to 3 cups water. Shampoo the carpet again just using this mixture. Vinegar kills mould, mildew and removes odours. If you don't want to put the mixture in the carpet cleaner. Sponge it on.
Apply the vinegar solution to both sides of the carpet if the carpet is very smelly and you see signs of mildew or mould on the back. If that's the case remove the carpet from the room. Apply the vinegar solution to one side. Once that side is dry, turn the carpet over and apply to the other side. You may need a helper to move and turn the carpet. If it's a nice day outside, move the carpet out into the sun to dry.
Dry the carpet as quickly and thoroughly as possible. If weather permits, open the windows, turn on the fans and the heat if the weather is cool. Place portable fans on the floor directed downward to the carpet. Use space heaters to increase the temperature, but be careful that they're not placed directly on the carpet.
Sprinkle borax on carpet. Use enough so you can see the borax on the carpet but not so much the carpet is covered with borax. Borax kills mould.
Use a broom to push the borax down into the fibres of the carpet. A "street sweeper" style broom works well for this task.
Let stand overnight. Vacuum thoroughly.
Sprinkle baking soda on the carpet if the smell is mild. It absorbs odours. One cup of baking soda per 10 square feet should work.
Leave the baking soda on for at least 30 minutes up to overnight.
Vacuum the carpet to remove the baking soda.
If the pad has been soaked, it may have to be replaced to completely and permanently get rid of the odour.