nxlooper: add loopback of compressed audio data.

Signed-off-by: qiaohaijiao1 <qiaohaijiao1@xiaomi.com>
This commit is contained in:
qiaohaijiao1 2023-01-31 14:42:32 +08:00 committed by Xiang Xiao
parent b0da60e498
commit 3648ddce0f
3 changed files with 18 additions and 15 deletions

View File

@ -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

View File

@ -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)

View File

@ -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:
*