2

アプリケーション レベルで一時停止および再開機能を提供できるように、ALSA の非同期コールバック機能を使用しようとしています。しかし、関数async_add_pcm_handler()はエラーを返します (より具体的には -38 を返します)。

rc = snd_pcm_open(&handle, (char*)"default",SND_PCM_STREAM_PLAYBACK, 0);
snd_pcm_hw_params_alloca(&params);
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 が定義されています。間違いの可能性を教えてください。

4

1 に答える 1