How to approximate the sample rate? I have a simple program that captures audio from an audio device. I have configured a nominal sample rate of 48000Hz and a buffer size of 1 millisecond. The audio sub system should execute my capture code with approximately 1000Hz.

My assumption is that the audio clock (LRCLK) is not running at exactly 48000Hz. Using this 1kHz-callback from the audio system I want to approximate the actual sampling frequency relativ to another clock. Currently I use the system clock of my workstation as a reference. I plan to use a network clock.

For my very first experiment I used a simple moving average with a period of 1000 but there is still very much jitter. Sometimes the average jumps by 2Hz which seems much to me.

What is the proper way to go here?

Many thanks!
In my experience, sound card sampling clocks vary by as much as 10 Hz from one card to another, even between computers of the same make and model. I have never seen much jitter, but I haven't especifically looked for it.

Note, however, that it is essentially impossible to know the true sampling rate, unless you have access to an atomic clock. What you can do is approximate the difference relative to a clock that you designate as your reference.

A simple experiment is to generate a single-tone signal, then receive it and find its frequency. Say your reference is the transmitter and it's operating at 48,000 samples per second. Feed the transmitter a sequence 0, 1, 0, -1, 0, .... This will produce a sine wave of nominal frequency 12,000 Hz. In the receiver, you sample this signal for a relatively long time (to have good frequency resolution) and use the DFT to determine its frequency to be, say, $f_2$. Then, you can calculate $$\Delta=\frac{12000}{f_2}$$ which is the factor by which the receiver's clock is faster than the transmitter's. Of course, this is only one of many possible approaches.