From 3648ddce0fae816cacb45ca5bac3db50a94e0f1d Mon Sep 17 00:00:00 2001 From: qiaohaijiao1 <qiaohaijiao1@xiaomi.com> Date: Tue, 31 Jan 2023 14:42:32 +0800 Subject: [PATCH] nxlooper: add loopback of compressed audio data. Signed-off-by: qiaohaijiao1 <qiaohaijiao1@xiaomi.com> --- include/system/nxlooper.h | 10 +++++----- system/nxlooper/nxlooper.c | 12 +++++++----- system/nxlooper/nxlooper_main.c | 11 ++++++----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/include/system/nxlooper.h b/include/system/nxlooper.h index becbea97d..40811c39f 100644 --- a/include/system/nxlooper.h +++ b/include/system/nxlooper.h @@ -161,9 +161,9 @@ int nxlooper_setdevice(FAR struct nxlooper_s *plooper, FAR const char *device); /**************************************************************************** - * Name: nxlooper_loopraw + * Name: nxlooper_loopback * - * nxlooper_loopraw() tries to record and then play the raw data using the + * nxlooper_loopback() tries to record and then play the raw data using the * Audio system. If a device is specified, it will try to use that * device. * @@ -183,9 +183,9 @@ int nxlooper_setdevice(FAR struct nxlooper_s *plooper, * ****************************************************************************/ -int nxlooper_loopraw(FAR struct nxlooper_s *plooper, - uint8_t nchannels, uint8_t bpsamp, - uint32_t samprate, uint8_t chmap); +int nxlooper_loopback(FAR struct nxlooper_s *plooper, int format, + uint8_t nchannels, uint8_t bpsamp, + uint32_t samprate, uint8_t chmap); /**************************************************************************** * Name: nxlooper_stop diff --git a/system/nxlooper/nxlooper.c b/system/nxlooper/nxlooper.c index 6694b9966..f5c695354 100644 --- a/system/nxlooper/nxlooper.c +++ b/system/nxlooper/nxlooper.c @@ -961,13 +961,14 @@ int nxlooper_stop(FAR struct nxlooper_s *plooper) #endif /* CONFIG_AUDIO_EXCLUDE_STOP */ /**************************************************************************** - * Name: nxlooper_loopraw + * Name: nxlooper_loopback * - * nxlooper_loopraw() tries to record and then play the raw data using the + * nxlooper_loopback() tries to record and then play the data using the * Audio system. If a device is specified, it will try to use that * device. * Input: * plooper Pointer to the initialized Looper context + * format format * nchannels channel num * bpsampe bit width * samprate sample rate @@ -982,9 +983,9 @@ int nxlooper_stop(FAR struct nxlooper_s *plooper) * ****************************************************************************/ -int nxlooper_loopraw(FAR struct nxlooper_s *plooper, - uint8_t nchannels, uint8_t bpsamp, - uint32_t samprate, uint8_t chmap) +int nxlooper_loopback(FAR struct nxlooper_s *plooper, int format, + uint8_t nchannels, uint8_t bpsamp, + uint32_t samprate, uint8_t chmap) { struct mq_attr attr; struct sched_param sparam; @@ -1059,6 +1060,7 @@ int nxlooper_loopraw(FAR struct nxlooper_s *plooper, cap_desc.caps.ac_controls.hw[0] = samprate ? samprate : 48000; cap_desc.caps.ac_controls.b[3] = samprate >> 16; cap_desc.caps.ac_controls.b[2] = bpsamp ? bpsamp : 16; + cap_desc.caps.ac_subtype = format; ret = ioctl(plooper->recorddev_fd, AUDIOIOC_CONFIGURE, (unsigned long)&cap_desc); if (ret < 0) diff --git a/system/nxlooper/nxlooper_main.c b/system/nxlooper/nxlooper_main.c index b92b7d1b2..0915abeec 100644 --- a/system/nxlooper/nxlooper_main.c +++ b/system/nxlooper/nxlooper_main.c @@ -124,7 +124,7 @@ static const struct mp_cmd_s g_nxlooper_cmds[] = #endif { "loopback", - "channels bpsamp samprate chmap", + "channels bpsamp samprate format chmap", nxlooper_cmd_loopback, NXLOOPER_HELP_TEXT("Audio loopback test") }, @@ -196,18 +196,19 @@ static const int g_nxlooper_cmd_count = sizeof(g_nxlooper_cmds) / static int nxlooper_cmd_loopback(FAR struct nxlooper_s *plooper, char *parg) { int ret; + int format = AUDIO_FMT_PCM; int channels = 0; int bpsamp = 0; int samprate = 0; int chmap = 0; - sscanf(parg, "%d %d %d %d", &channels, &bpsamp, - &samprate, &chmap); + sscanf(parg, "%d %d %d %d %d", &channels, &bpsamp, + &samprate, &chmap, &format); /* Try to loopback raw data with settings specified */ - ret = nxlooper_loopraw(plooper, channels, bpsamp, - samprate, chmap); + ret = nxlooper_loopback(plooper, format, channels, bpsamp, + samprate, chmap); /* nxlooper_loopraw returned values: *