Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <alsa/asoundlib.h>
- int main(int argc, char *argv[])
- {
- struct _snd_pcm *rec_pcm = 0;
- const char *dev = (argc > 1) ? argv[1] : "default";
- int mode = 0;
- int err = snd_pcm_open(&rec_pcm, dev, SND_PCM_STREAM_CAPTURE, mode);
- if (err < 0)
- {
- return 1;
- }
- snd_pcm_hw_params_t *hw_params;
- if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0)
- {
- return 1;
- }
- if ((err = snd_pcm_hw_params_any (rec_pcm, hw_params)) < 0)
- {
- return 1;
- }
- snd_pcm_format_t fmt = SND_PCM_FORMAT_S16_LE;
- if ((err = snd_pcm_hw_params_set_format (rec_pcm, hw_params, fmt)) < 0)
- {
- return 1;
- }
- int sample_rate = 8000;
- if ((err = snd_pcm_hw_params_set_rate (rec_pcm, hw_params, sample_rate, 0)) < 0)
- {
- return 1;
- }
- int channels = 1;
- if ((err = snd_pcm_hw_params_set_channels (rec_pcm, hw_params, channels)) < 0)
- {
- return 1;
- }
- if ((err = snd_pcm_hw_params (rec_pcm, hw_params)) < 0)
- {
- return 1;
- }
- snd_pcm_hw_params_free(hw_params);
- snd_pcm_prepare(rec_pcm);
- snd_pcm_start(rec_pcm);
- snd_pcm_drop(rec_pcm);
- snd_pcm_prepare(rec_pcm);
- snd_pcm_start(rec_pcm);
- snd_pcm_drop(rec_pcm);
- snd_pcm_hw_free(rec_pcm);
- snd_pcm_close(rec_pcm);
- }
Add Comment
Please, Sign In to add comment