pcm: introduce pcm_frame_diff and pcm_frame_diff2 helpers

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2020-10-13 20:10:49 +02:00
parent a6c8ac0c85
commit 6d06fcc285
4 changed files with 30 additions and 40 deletions

View file

@ -1170,6 +1170,26 @@ static inline void sw_set_period_event(snd_pcm_sw_params_t *params, int val)
#define PCMINABORT(pcm) (((pcm)->mode & SND_PCM_ABORT) != 0)
static inline snd_pcm_sframes_t pcm_frame_diff(snd_pcm_uframes_t ptr1,
snd_pcm_uframes_t ptr2,
snd_pcm_uframes_t boundary)
{
if (ptr1 < ptr2)
return ptr1 + (boundary - ptr2);
else
return ptr1 - ptr2;
}
static inline snd_pcm_sframes_t pcm_frame_diff2(snd_pcm_uframes_t ptr1,
snd_pcm_uframes_t ptr2,
snd_pcm_uframes_t boundary)
{
snd_pcm_sframes_t r = ptr1 - ptr2;
if (r >= (snd_pcm_sframes_t)boundary / 2)
return boundary - r;
return r;
}
#ifdef THREAD_SAFE_API
/*
* __snd_pcm_lock() and __snd_pcm_unlock() are used to lock/unlock the plugin