How to lower volume on microphone input before outputting through headphones? (Using a DSP)
Using a DSP or a Raspberry Pi to limit the sound level from a pair of headphones seems to be overkill. All that you are trying to do is to impose an upper limit on the sound level, which is exactly what a simple analog AGC (automatic gain control) circuit does. Have a look at this Maxim Microphone amplifier with AGC MAX9814. This single chip does almost everything you need, although it will not drive headphones directly, you will need a small headphone amplifier such as a MAX9820. It should be possible to build this circuit onto a PCB of about 3 x 2 cm, it can be battery powered, and a small coin cell should last several months.