mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
examples/fmsynth: Fix freaze when execute it in 2nd time
Fix a freaze BUG when the example is executed again after 1st execution.
This commit is contained in:
parent
2d6f5f230e
commit
2b4a25c8d5
4 changed files with 60 additions and 20 deletions
|
|
@ -68,7 +68,7 @@ static int configure_audio(int fd, int ch, int fs, int bps, int chmap)
|
|||
* name: create_audiomq
|
||||
****************************************************************************/
|
||||
|
||||
static mqd_t create_audiomq(int fd, int buf_num)
|
||||
static mqd_t create_audiomq(const char *mqname, int fd, int buf_num)
|
||||
{
|
||||
mqd_t ret;
|
||||
struct mq_attr attr;
|
||||
|
|
@ -78,8 +78,7 @@ static mqd_t create_audiomq(int fd, int buf_num)
|
|||
attr.mq_curmsgs = 0;
|
||||
attr.mq_flags = 0;
|
||||
|
||||
ret = mq_open(CONFIG_AUDIOUTILS_NXAUDIO_MSGQNAME,
|
||||
O_RDWR | O_CREAT, 0644, &attr);
|
||||
ret = mq_open(mqname, O_RDWR | O_CREAT, 0644, &attr);
|
||||
if (ret >= (mqd_t)0)
|
||||
{
|
||||
int rr;
|
||||
|
|
@ -147,14 +146,13 @@ static void free_audio_buffers(FAR struct nxaudio_s *nxaudio)
|
|||
|
||||
void fin_nxaudio(FAR struct nxaudio_s *nxaudio)
|
||||
{
|
||||
free_audio_buffers(nxaudio);
|
||||
ioctl(nxaudio->fd, AUDIOIOC_STOP, 0);
|
||||
ioctl(nxaudio->fd, AUDIOIOC_SHUTDOWN, 0);
|
||||
ioctl(nxaudio->fd, AUDIOIOC_UNREGISTERMQ, (unsigned long)nxaudio->mq);
|
||||
ioctl(nxaudio->fd, AUDIOIOC_RELEASE, 0);
|
||||
ioctl(nxaudio->fd, AUDIOIOC_SHUTDOWN, 0);
|
||||
free_audio_buffers(nxaudio);
|
||||
close(nxaudio->fd);
|
||||
mq_close(nxaudio->mq);
|
||||
mq_unlink(CONFIG_AUDIOUTILS_NXAUDIO_MSGQNAME);
|
||||
close(nxaudio->fd);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -163,10 +161,23 @@ void fin_nxaudio(FAR struct nxaudio_s *nxaudio)
|
|||
|
||||
int init_nxaudio(FAR struct nxaudio_s *nxaudio,
|
||||
int fs, int bps, int chnum)
|
||||
{
|
||||
return init_nxaudio_devname(nxaudio, fs, bps, chnum,
|
||||
CONFIG_AUDIOUTILS_NXAUDIO_DEVPATH,
|
||||
CONFIG_AUDIOUTILS_NXAUDIO_MSGQNAME);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* name: init_nxaudio_devname
|
||||
****************************************************************************/
|
||||
|
||||
int init_nxaudio_devname(FAR struct nxaudio_s *nxaudio,
|
||||
int fs, int bps, int chnum,
|
||||
const char *devname, const char *mqname)
|
||||
{
|
||||
struct ap_buffer_info_s buf_info;
|
||||
|
||||
nxaudio->fd = open(CONFIG_AUDIOUTILS_NXAUDIO_DEVPATH, O_RDWR | O_CLOEXEC);
|
||||
nxaudio->fd = open(devname, O_RDWR | O_CLOEXEC);
|
||||
if (nxaudio->fd >= 0)
|
||||
{
|
||||
if (ioctl(nxaudio->fd, AUDIOIOC_RESERVE, 0) < 0)
|
||||
|
|
@ -186,7 +197,7 @@ int init_nxaudio(FAR struct nxaudio_s *nxaudio,
|
|||
|
||||
/* Create message queue to communicate with audio driver */
|
||||
|
||||
nxaudio->mq = create_audiomq(nxaudio->fd, buf_info.nbuffers + 8);
|
||||
nxaudio->mq = create_audiomq(mqname, nxaudio->fd, buf_info.nbuffers + 8);
|
||||
|
||||
/* Create audio buffers to inject audio sample */
|
||||
|
||||
|
|
@ -218,6 +229,24 @@ int nxaudio_enqbuffer(FAR struct nxaudio_s *nxaudio,
|
|||
(unsigned long)(uintptr_t)&desc);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* name: nxaudio_pause
|
||||
****************************************************************************/
|
||||
|
||||
int nxaudio_pause(FAR struct nxaudio_s *nxaudio)
|
||||
{
|
||||
return ioctl(nxaudio->fd, AUDIOIOC_PAUSE, 0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* name: nxaudio_resume
|
||||
****************************************************************************/
|
||||
|
||||
int nxaudio_resume(FAR struct nxaudio_s *nxaudio)
|
||||
{
|
||||
return ioctl(nxaudio->fd, AUDIOIOC_RESUME, 0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* name: nxaudio_setvolume
|
||||
****************************************************************************/
|
||||
|
|
@ -252,6 +281,8 @@ int nxaudio_stop(FAR struct nxaudio_s *nxaudio)
|
|||
{
|
||||
struct audio_msg_s term_msg;
|
||||
|
||||
ioctl(nxaudio->fd, AUDIOIOC_STOP, 0);
|
||||
|
||||
term_msg.msg_id = AUDIO_MSG_STOP;
|
||||
term_msg.u.data = 0;
|
||||
mq_send(nxaudio->mq, (FAR const char *)&term_msg, sizeof(term_msg), 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue