|
From: | Benny Alexandar |
Subject: | Re: [Discuss-gnuradio] Broadcast Receiver Audio Synchronization ( Delay locked loop for the two-clock problem) |
Date: | Wed, 9 Nov 2016 17:12:25 +0000 |
Hi Fons/Marc,
For Digital radio the audio data is received in compressed format. Using audio codec it is uncompressed. The uncompressed audio will be sent to audio sink with a block size of 24ms. Before sending these audio blocks are timestamped using PC microsecond
timer. To access the clock value of timer, I do a "direct" read of memory mapped hardware register (TSC) to avoid OS delays and jitter etc. So the logic is whenever an audio compressed frame arrives at the audio codec, it is timestamped with the current time
(Ti) and after uncompressed each audio frame blocks (24ms) is timestamped by adding 24ms ( Ti + ( frame_no * frame_duration ) ), where Ti is the start time and frame_no is the decoded uncompressed frames ranges from 0 to n and frame_duration is 24ms.
When these audio frames reaches the audio sink, it reads the current time (Tc) from same clock (TSC) and measure the elapsed time , diff = ( ( Tk + delay ) - Tc ), where Tk = ( Ti
+ ( frame_no * frame_duration ) ) and delay is 2 frame delay (48ms)
. Every time the audio sink call back happens (aftre streaming an aduio frame(24ms) interrupt happens) , the diff is calculated and accumulated. Ideally if the audio sink is sending at the "nominal sample rate" the delay should be constant. After some
N seconds this accumulated value is averaged by dividing by N sec. So I get the drift in sampling rate in terms of samples. Then all I need to do is slow down or speed up the sampling rate based on which side the drift is.
Is it possible to change the sample rate of ALSA by drift amount ?
-ben
[Prev in Thread] | Current Thread | [Next in Thread] |