Skip to content

Commit ce05208

Browse files
t123yhperexg
authored andcommitted
alsaloop: Support "Capture Pitch 1000000" rate shift
In Linux 5.14, a new feedback mechanism for USB Audio Gadget is introduced (commit e89bb428), along with a new control element "Capture Pitch 1000000". This patch adds support for this feature. Note that this property seems to be the reverse of PCM Rate Shift, so we have to take reciprocal of pitch. Signed-off-by: Yunhao Tian <[email protected]> Signed-off-by: Jaroslav Kysela <[email protected]>
1 parent 2b9bfac commit ce05208

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

alsaloop/alsaloop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct loopback_handle {
122122
unsigned int ctl_pollfd_count;
123123
snd_ctl_elem_value_t *ctl_notify;
124124
snd_ctl_elem_value_t *ctl_rate_shift;
125+
snd_ctl_elem_value_t *capt_pitch;
125126
snd_ctl_elem_value_t *ctl_active;
126127
snd_ctl_elem_value_t *ctl_format;
127128
snd_ctl_elem_value_t *ctl_rate;

alsaloop/pcmjob.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,10 +1060,15 @@ static int set_rate_shift(struct loopback_handle *lhandle, double pitch)
10601060
{
10611061
int err;
10621062

1063-
if (lhandle->ctl_rate_shift == NULL)
1063+
if (lhandle->ctl_rate_shift) {
1064+
snd_ctl_elem_value_set_integer(lhandle->ctl_rate_shift, 0, pitch * 100000);
1065+
err = snd_ctl_elem_write(lhandle->ctl, lhandle->ctl_rate_shift);
1066+
} else if (lhandle->capt_pitch) {
1067+
snd_ctl_elem_value_set_integer(lhandle->capt_pitch, 0, (1 / pitch) * 1000000);
1068+
err = snd_ctl_elem_write(lhandle->ctl, lhandle->capt_pitch);
1069+
} else {
10641070
return 0;
1065-
snd_ctl_elem_value_set_integer(lhandle->ctl_rate_shift, 0, pitch * 100000);
1066-
err = snd_ctl_elem_write(lhandle->ctl, lhandle->ctl_rate_shift);
1071+
}
10671072
if (err < 0) {
10681073
logit(LOG_CRIT, "Cannot set PCM Rate Shift element for %s: %s\n", lhandle->id, snd_strerror(err));
10691074
return err;
@@ -1204,6 +1209,8 @@ static int openctl(struct loopback_handle *lhandle, int device, int subdevice)
12041209
&lhandle->ctl_notify);
12051210
openctl_elem(lhandle, device, subdevice, "PCM Rate Shift 100000",
12061211
&lhandle->ctl_rate_shift);
1212+
openctl_elem(lhandle, device, subdevice, "Capture Pitch 1000000",
1213+
&lhandle->capt_pitch);
12071214
set_rate_shift(lhandle, 1);
12081215
openctl_elem(lhandle, device, subdevice, "PCM Slave Active",
12091216
&lhandle->ctl_active);
@@ -1289,6 +1296,9 @@ static int closeit(struct loopback_handle *lhandle)
12891296
if (lhandle->ctl_rate_shift)
12901297
snd_ctl_elem_value_free(lhandle->ctl_rate_shift);
12911298
lhandle->ctl_rate_shift = NULL;
1299+
if (lhandle->capt_pitch)
1300+
snd_ctl_elem_value_free(lhandle->capt_pitch);
1301+
lhandle->capt_pitch = NULL;
12921302
if (lhandle->ctl)
12931303
err = snd_ctl_close(lhandle->ctl);
12941304
lhandle->ctl = NULL;
@@ -1334,7 +1344,7 @@ int pcmjob_init(struct loopback *loop)
13341344
snprintf(id, sizeof(id), "%s/%s", loop->play->id, loop->capt->id);
13351345
id[sizeof(id)-1] = '\0';
13361346
loop->id = strdup(id);
1337-
if (loop->sync == SYNC_TYPE_AUTO && loop->capt->ctl_rate_shift)
1347+
if (loop->sync == SYNC_TYPE_AUTO && (loop->capt->ctl_rate_shift || loop->capt->capt_pitch))
13381348
loop->sync = SYNC_TYPE_CAPTRATESHIFT;
13391349
if (loop->sync == SYNC_TYPE_AUTO && loop->play->ctl_rate_shift)
13401350
loop->sync = SYNC_TYPE_PLAYRATESHIFT;

0 commit comments

Comments
 (0)