I think you need to have some sort of digital potentiometer, that way you can control the resistance in the gain circuit.