Personal trainer here (so I get through a lot of gym clothes!)
You need a sports detergent like Halo. Ecozone do one that is okay...ish and there are a couple of Spanish ones from a brand called Asevi which are alright too. I usually also chuck in a capful of either laundry disinfectant (I never got on with Dettol, but others have recommended it so it's worth a try) or cheapo vodka.
Most things I wash at 30 the first time, just to test the fabrics, and subsequently at 40 or 50. 30 isn't enough, even with the sports detergents. And you need to run a full programme, not a quick wash.
The most important bit: no fabric conditioner. Ever, ever, ever. It ruins technical fabrics (which are actually closer to plastics than fabric, really). And don't tumble dry either.
Lastly, if you've got stuff where the sweat smell is already 'baked in' (sorry) you might have to chuck and get new; once it's in it can be difficult to get out. You could try soaking in Napisan or similar, or white vinegar, and see how you go.
If you're after new gym clothing I can recommend Lululemon and Nobull; both seem to wash well and don't acquire that slightly odd musty smell that some sports clothing seems to get after a while. They're not cheap but they're tough and they will last.