From left to right: R1 and R2 are used for a mid reference voltage and C6 + C7 stabilyze the voltage for the positive input of the operational amplifier. IC2 is the ultrasonic sensor. The signal pass through C11 (decoupling) and R6 to the negative input of the IC1 (MCP6021 not MCP6001 as in the image) The signal in greatly amplified and then sent to the second stage used as rectifier. Here the voltage is smoothed by R7 and C13 and R8 bring the signal to zero when there's no sound in the air.The GP4 of the PIC12LF1822 sample the signal that will be used to generate a signal amplitude proportional to the incoming volume level. From the ouput of IC1 the signal is sent to GP0 of IC4 and this signal is used to count the impulse and then divided via softtware. A PWM creates the output signal and the duty cycle of this PWM is used to regulate the overall volume. The push button generates an interrupt when pressed and the timings on how this button is pressed discriminates ifwe have done a single press to turn on the device, a long presso to turn off or a single press when it is on to change the volume or a doulbe click to change the number of the frequency division. SJ1 and SJ2 are open when in program mode and must be shartened after programmed.
Here you can download the compiled HEX file
Here the bill of material. Unfortunately some components are no more produced but they can be easily replaced with other form factor. I.e. the sensor can be replaced with the SPU0410LR5H-QB-7
This is the source code that can be compiled with MPLAB from www.microchip.com