Ambient noise compensation on ADAU1701

Hello

I am trying to create an ambient noise compensation circuit in Sigma Studio for an ADAU1701. I need maintain a constant ration between the ambient noise microphone and the playback. I need to be able to modify to average the ambient noise values over a period of time and also need to be able to modify the ration between noise and signal. I have made a few designs but they are pretty unstable. Maybe somebody with experience could come to my rescue?

Thanks