I would be thinking how to do it in the analogue domain, then transfering the method into digital code.
One way is to take the output of the microphone into a variable-gain amplifier (you'll need some sort of amp since mics are generally low-level devices)
If the output of the amp is rectified and used for the gain control input of the amp, then that voltage is just what you want.
There would need to be a method to achieve a decay over time for that voltage, otherwise once a loud sound had been recieved, the gain would be minimum and nothing else would happen. Also it might be useful to have some damping in the response - a short sound should have less effect than a prolonged one.
In the professional world the (BBC-derived) PPM has very closely defined response characteristics, including its attack and decay, frequency response and 'law'. Doubtless that would be possible, but not necessary.
So you could use an ADC, fast enough to do audio so about 50kHz sample-rate.
For each sample, if the top bit is set, then it's negative so you could ignore it, or take the twos-compliment. If the next-to-top bit is set, then increment a counter, otherwise leave it be. Separately over time it can be decremented.
Then that counter can be output as a voltage to drive the amplifier gain, and we already have a PWM on board.
So now we only need some maths to control the 'law' of the system.
If we used a 32-bit counter, then we can just count the leading zeros - a logarithmic 32-step meter output! Either drive an LED bargraph, or put it into a graphic of a meter on a screen.
As for the ADC, do we really need to go further than a simple comparator, with its output connected to a GPIO input? Maybe a diode-capacitor-resistor as a sort of sample-and-hold.