]> git.alsa-project.org Git - alsa-utils.git/commitdiff
alsaloop: Support "Playback Pitch 1000000" rate shift
authorPavel Hofman <pavel.hofman@ivitera.com>
Sun, 24 Oct 2021 08:31:55 +0000 (10:31 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 28 Oct 2021 10:32:37 +0000 (12:32 +0200)
Linux 5.15 will introduce a new control element "Playback Pitch 1000000"
(commit 6fec018 ("usb: gadget: u_audio.c: Adding Playback Pitch ctl for
sync playback") which provides feedback mechanism for playback direction
of USB Audio Gadget. The control operates in the same way as the
existing control element "Capture Pitch 1000000".

This patch adds support for this feature.

Signed-off-by: Pavel Hofman <pavel.hofman@ivitera.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
alsaloop/pcmjob.c

index 9a61e4ab0f080088c59d6f43e0fe70f849785a6f..ef0c3ddf54fb56e2a68c659e95b1569f001137d4 100644 (file)
@@ -1064,6 +1064,7 @@ static int set_rate_shift(struct loopback_handle *lhandle, double pitch)
                snd_ctl_elem_value_set_integer(lhandle->ctl_rate_shift, 0, pitch * 100000);
                err = snd_ctl_elem_write(lhandle->ctl, lhandle->ctl_rate_shift);
        } else if (lhandle->ctl_pitch) {
+               // 'Playback/Capture Pitch 1000000' requires reciprocal to pitch
                snd_ctl_elem_value_set_integer(lhandle->ctl_pitch, 0, (1 / pitch) * 1000000);
                err = snd_ctl_elem_write(lhandle->ctl, lhandle->ctl_pitch);
        } else {
@@ -1241,7 +1242,10 @@ static int openctl(struct loopback_handle *lhandle, int device, int subdevice)
                                                lhandle->prateshift_name);
                                exit(EXIT_FAILURE);
                        }
-               }
+               } else
+                       openctl_elem(lhandle, device, subdevice, "Playback Pitch 1000000",
+                                       &lhandle->ctl_pitch);
+               set_rate_shift(lhandle, 1);
                if (lhandle->loopback->controls)
                        goto __events;
                return 0;
@@ -1388,7 +1392,7 @@ int pcmjob_init(struct loopback *loop)
        loop->id = strdup(id);
        if (loop->sync == SYNC_TYPE_AUTO && (loop->capt->ctl_rate_shift || loop->capt->ctl_pitch))
                loop->sync = SYNC_TYPE_CAPTRATESHIFT;
-       if (loop->sync == SYNC_TYPE_AUTO && loop->play->ctl_rate_shift)
+       if (loop->sync == SYNC_TYPE_AUTO && (loop->play->ctl_rate_shift || loop->play->ctl_pitch))
                loop->sync = SYNC_TYPE_PLAYRATESHIFT;
 #ifdef USE_SAMPLERATE
        if (loop->sync == SYNC_TYPE_AUTO && loop->src_enable)