linux應用層下用C呼叫音訊驅動
阿新 • • 發佈:2019-01-05
static void audio_pause(void)
{
int err;
if (alsa_can_pause) {
if ((err = snd_pcm_pause(alsa_handler, 1)) < 0)
{
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPauseError, snd_strerror(err));
return;
}
mp_msg(MSGT_AO,MSGL_V,"alsa-pause: pause supported by hardware\n");
} else {
if ((err = snd_pcm_drop(alsa_handler)) < 0)
{
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmDropError, snd_strerror(err));
return;
}
}
}
static void audio_resume(void)
{
int err;
if (snd_pcm_state(alsa_handler) == SND_PCM_STATE_SUSPENDED) {
mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_ALSA_PcmInSuspendModeTryingResume);
while ((err = snd_pcm_resume(alsa_handler)) == -EAGAIN) sleep(1);
}
if (alsa_can_pause) {
if ((err = snd_pcm_pause(alsa_handler, 0)) < 0)
{
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmResumeError, snd_strerror(err));
return;
}
mp_msg(MSGT_AO,MSGL_V,"alsa-resume: resume supported by hardware\n");
} else {
if ((err = snd_pcm_prepare(alsa_handler)) < 0)
{
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPrepareError, snd_strerror(err));
return;
}
}
}
{
int err;
if (alsa_can_pause) {
if ((err = snd_pcm_pause(alsa_handler, 1)) < 0)
{
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPauseError, snd_strerror(err));
return;
}
mp_msg(MSGT_AO,MSGL_V,"alsa-pause: pause supported by hardware\n");
} else {
if ((err = snd_pcm_drop(alsa_handler)) < 0)
{
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmDropError, snd_strerror(err));
return;
}
}
}
static void audio_resume(void)
{
int err;
if (snd_pcm_state(alsa_handler) == SND_PCM_STATE_SUSPENDED) {
mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_ALSA_PcmInSuspendModeTryingResume);
while ((err = snd_pcm_resume(alsa_handler)) == -EAGAIN) sleep(1);
}
if (alsa_can_pause) {
if ((err = snd_pcm_pause(alsa_handler, 0)) < 0)
{
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmResumeError, snd_strerror(err));
return;
}
mp_msg(MSGT_AO,MSGL_V,"alsa-resume: resume supported by hardware\n");
} else {
if ((err = snd_pcm_prepare(alsa_handler)) < 0)
{
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPrepareError, snd_strerror(err));
return;
}
}
}