如果是capture的话,只需要修改:
a. SND_PCM_STREAM_PLAYBACK -> SND_PCM_STREAM_CAPTURE
if ((err = snd_pcm_open (&capture_handle, argv[1], SND_PCM_STREAM_CAPTURE, 0)) < 0) { fprintf (stderr, "cannot open audio device %s (%s)\n", argv[1], snd_strerror (err)); exit (1); }
b. snd_pcm_writei -> snd_pcm_readi
for (i = 0; i < 10; ++i) { if ((err = snd_pcm_readi (capture_handle, buf, 128)) != 128) { fprintf (stderr, "read from audio interface failed (%s)\n", snd_strerror (err)); exit (1); } }