bondagit / aes67-linux-daemon

AES67 Linux Daemon with configuration WebUI
GNU General Public License v3.0
372 stars 82 forks source link

hard coded 44100hz #161

Closed cloudcastsystemsau closed 6 months ago

cloudcastsystemsau commented 6 months ago

hi @bondagit,

i've noticed in the timer process function when computing the tic count there is a hardcoded 44100.

 if(ui32R < 4 * self->m_ui32SamplingRate / 44100) // to avoid using timestamps outside 80us of theoretical time
            {
                ui64CurrentTICCount = ui64Q + 1; // we add 1 because ui64Q is the count for the previous frame
                //iTICCountUpdateMethod = 1;
            }
            else if(ui32R > self->m_ui32FrameSize - 4 * self->m_ui32SamplingRate / 44100)
            {
                ui64CurrentTICCount = ui64Q + 1 + 1; // we add 1 because ui64Q is the count for the previous frame
                //iTICCountUpdateMethod = 2;
            }

are you able to explain why there is a hardcoded 44100 which i assume is 44.1 khz?

bondagit commented 6 months ago

In that piece of code the next tick count is computed. There is a tick every TICFrameSizeAt1FS * ui32nFS / m_ui32SamplingRate. With TICFrameSizeAt1FS = 48 and _mui32SamplingRate = 48000 -> ui32nFS = 1 we have a tick every 1ms and _mui32FrameSize = 48. The next tick count is corrected depending on the offset from the PTP clock. ui64Q is the offset in number of frames (in number of 100us ticks) with _mui32FrameSize as frame size, while ui32R is the rest of the previous division. The frame size _mui32FrameSize depends on the sample rate, see manager.c:355, so self->m_ui32SamplingRate / 44100 is used to get the frame size factor.