[PATCH 9/9] ASoC: SOF: ipc4-pcm: add delay function support

Péter Ujfalusi peter.ujfalusi at linux.intel.com
Thu Feb 2 10:31:28 CET 2023



On 01/02/2023 14:44, Jaroslav Kysela wrote:
> On 01. 02. 23 13:32, Peter Ujfalusi wrote:
> 
>> +static snd_pcm_sframes_t sof_ipc4_pcm_delay(struct snd_soc_component
>> *component,
>> +                        struct snd_pcm_substream *substream)
>> +{
> 
> ...
> 
>> +
>> +    /*
>> +     * Handle 32-bit counter wrap around, which would happen
>> +     * for a 48khz 2ch stream in 24.855 hours
>> +     */
>> +    link_ptr = tmp_ptr & UINT_MAX;
>> +
>> +    host_ptr = substream->runtime->status->hw_ptr;
>> +
>> +    if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
>> +        return host_ptr - link_ptr;
>> +
>> +    return link_ptr - host_ptr;
> 
> I don't think that this calculation is fine for the wrap point. The
> hw_ptr is in range 0..pcm_boundary not UINT_MAX.

That is true. Our link counter is u64 (and it is counting the bytes, not
a real DMA position) so I can
tmp_ptr %= substream->runtime->boundary;

then handle the wrap of both later.

> Also, you should consider the underrun/overrun situations.

>The simple substraction is not enough to handle this correctly.

Yes, you are right. I will send v2 right away(ish)

Thanks,
Péter


More information about the Alsa-devel mailing list