[PATCH 1/2] alsaloop: Renamed field capt_pitch to ctl_pitch
Renaming capt_pitch to ctl_pitch to respect the naming style of snd_ctl_elem_value_t fields in loopback_handle. Also making the variable name suitable for planned support of playback pitch.
Signed-off-by: Pavel Hofman pavel.hofman@ivitera.com --- alsaloop/alsaloop.h | 2 +- alsaloop/pcmjob.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/alsaloop/alsaloop.h b/alsaloop/alsaloop.h index 7a98ef3..a5539ef 100644 --- a/alsaloop/alsaloop.h +++ b/alsaloop/alsaloop.h @@ -122,7 +122,7 @@ struct loopback_handle { unsigned int ctl_pollfd_count; snd_ctl_elem_value_t *ctl_notify; snd_ctl_elem_value_t *ctl_rate_shift; - snd_ctl_elem_value_t *capt_pitch; + snd_ctl_elem_value_t *ctl_pitch; snd_ctl_elem_value_t *ctl_active; snd_ctl_elem_value_t *ctl_format; snd_ctl_elem_value_t *ctl_rate; diff --git a/alsaloop/pcmjob.c b/alsaloop/pcmjob.c index 13fa595..7b47c40 100644 --- a/alsaloop/pcmjob.c +++ b/alsaloop/pcmjob.c @@ -1063,9 +1063,9 @@ static int set_rate_shift(struct loopback_handle *lhandle, double pitch) if (lhandle->ctl_rate_shift) { 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->capt_pitch) { - snd_ctl_elem_value_set_integer(lhandle->capt_pitch, 0, (1 / pitch) * 1000000); - err = snd_ctl_elem_write(lhandle->ctl, lhandle->capt_pitch); + } else if (lhandle->ctl_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 { return 0; } @@ -1252,7 +1252,7 @@ static int openctl(struct loopback_handle *lhandle, int device, int subdevice) openctl_elem(lhandle, device, subdevice, "PCM Rate Shift 100000", &lhandle->ctl_rate_shift); openctl_elem(lhandle, device, subdevice, "Capture Pitch 1000000", - &lhandle->capt_pitch); + &lhandle->ctl_pitch); set_rate_shift(lhandle, 1); openctl_elem(lhandle, device, subdevice, "PCM Slave Active", &lhandle->ctl_active); @@ -1338,9 +1338,9 @@ static int closeit(struct loopback_handle *lhandle) if (lhandle->ctl_rate_shift) snd_ctl_elem_value_free(lhandle->ctl_rate_shift); lhandle->ctl_rate_shift = NULL; - if (lhandle->capt_pitch) - snd_ctl_elem_value_free(lhandle->capt_pitch); - lhandle->capt_pitch = NULL; + if (lhandle->ctl_pitch) + snd_ctl_elem_value_free(lhandle->ctl_pitch); + lhandle->ctl_pitch = NULL; if (lhandle->ctl) err = snd_ctl_close(lhandle->ctl); lhandle->ctl = NULL; @@ -1386,7 +1386,7 @@ int pcmjob_init(struct loopback *loop) snprintf(id, sizeof(id), "%s/%s", loop->play->id, loop->capt->id); id[sizeof(id)-1] = '\0'; loop->id = strdup(id); - if (loop->sync == SYNC_TYPE_AUTO && (loop->capt->ctl_rate_shift || loop->capt->capt_pitch)) + 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) loop->sync = SYNC_TYPE_PLAYRATESHIFT;
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 --- alsaloop/pcmjob.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/alsaloop/pcmjob.c b/alsaloop/pcmjob.c index 7b47c40..59ca0ff 100644 --- a/alsaloop/pcmjob.c +++ b/alsaloop/pcmjob.c @@ -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)
On 24. 10. 21 10:31, Pavel Hofman wrote:
Renaming capt_pitch to ctl_pitch to respect the naming style of snd_ctl_elem_value_t fields in loopback_handle. Also making the variable name suitable for planned support of playback pitch.
Signed-off-by: Pavel Hofman pavel.hofman@ivitera.com
Applied both patches. Thank you.
Jaroslav
participants (2)
-
Jaroslav Kysela
-
Pavel Hofman