[Csnd] Median over fixed number of values / writing a tuning aid

Hey hey,
I'm writing a kind of tuner to help me design waveguide based instruments, since these may, depending n the settings, drift from the desired frequency. There are enough pitch trackers. My idea:
play a static note at the tuner and wait until the detected frequency stays within a certain range for a few detected values.

So, I'd need to set it up to calculate the deviance over perhaps ten values, before I start measuring for real. Depending on the output of the tuner, I'd adjust the pitch of the note, until I am within a certain margin of tolerance.

Any ideas on that? Has anyone done that or perhaps even written a complete tuner of that kind?

The whole procedure, as I see it, I'd start my example notes at a desired pitch, find the adjustment value, write it to a table and move on, until the whole desired pitch range has been covered. I would use MIDI notes, i.e. measure according to an equal temperament 12-tone scale. In the end, there would be a lookup table.

Any help or hints are appreciated.

Best wishes,

Jeanette