2
我正在尝试使用ALSA的异步回调功能,以便我可以在应用程序级别提供暂停和恢复功能。但函数async_add_pcm_handler()
返回一个错误(返回-38更具体)。Alsa异步回调
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函数的定义。你能指出可能的错误吗?
您可以拨打_const的char * snd_strerror(INT的差错编号)_摆脱你的错误代码的消息,可以帮助(HTTP ://www.alsa-project.org/alsa-doc/alsa-lib/group___error.html#gd174fcc147831046749051725762dd69) – 2012-02-09 05:38:06
@JoachimIsaksson描述为“Function not Implemented”。任何如何使用异步alsa回调不建议反正移植等。还有其他方法,以便我可以在应用程序级别实现paus/resume功能。 – nagavamsikrishna 2012-02-09 05:53:25
那么,你成功了吗? – pavelkolodin 2012-03-22 08:33:46