我正在尝试使用 ALSA 的异步回调功能,以便可以在应用程序级别提供暂停和恢复功能。但是该函数async_add_pcm_handler()
返回一个错误(更具体地返回 -38)。
rc = snd_pcm_open(&handle, (char*)"default",SND_PCM_STREAM_PLAYBACK, 0);
snd_pcm_hw_params_alloca(¶ms);
snd_pcm_hw_params_any(handle, params);
snd_pcm_hw_params_set_format(handle, params,SND_PCM_FORMAT_S16_LE);
snd_pcm_hw_params_set_channels(handle, params, 1);
val = 22050;
snd_pcm_hw_params_set_rate_near(handle, params,&val, &dir);
frames=128;
snd_pcm_hw_params_set_period_size_near(handle,params, &frames, &dir);
snd_pcm_hw_params(handle, params);
snd_pcm_hw_params_get_period_size(params, &frames,&dir);
size = frames * 2;
pcmfile=fopen("output.pcm","rb");
fseek(pcmfile,0,SEEK_SET);
buffer=(char*)malloc(size);
memset(buffer,0,size);
if(snd_async_add_pcm_handler(&pcm_callback, handle, MyCallback, NULL) != 0) {
printf("handler not successful\n");
}
while(!feof(pcmfile)){
returnvalue=fread(buffer,sizeof(char),size,pcmfile);
snd_pcm_writei(handle, buffer, frames);
}
以上是我正在使用的一段代码,并定义了函数 MyCallback。你能指出我可能的错误吗?