Uh oh! Once I get started on an analog design, I just can’t stop tweaking! I took that envelope follower circuit and added an inverting amplifier to its input. This let me eliminate the DC offset voltage and also increase the amplitude of the signal before it gets “followed”. The response is much better! I also now use both amplifiers in the eight pin DIP. The second one is a unity gain non-inverting amp, just to bring the output impedance way down so that the ADC can handle it. The AVR likes no more than about 2kΩ of impedance on its analog inputs.
Analog designs do this. They slowly get bigger and bigger as you realize that you can make the signal just a little bit better/cleaner/niftier. Be careful!
Also, I made one of the classic C mistakes in the software filter: an “=” in the place of a “==”. Mock me, if you must. I’m not ashamed.