Guest User

alsa linux kernel freeze

a guest
Nov 2nd, 2012
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include <alsa/asoundlib.h>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.   struct _snd_pcm *rec_pcm = 0;
  6.  
  7.   const char *dev = (argc > 1) ? argv[1] : "default";
  8.   int mode = 0;
  9.  
  10.   int err = snd_pcm_open(&rec_pcm, dev, SND_PCM_STREAM_CAPTURE, mode);
  11.   if (err < 0)
  12.   {
  13.     return 1;
  14.   }
  15.  
  16.   snd_pcm_hw_params_t *hw_params;
  17.   if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0)
  18.   {
  19.     return 1;
  20.   }
  21.                
  22.   if ((err = snd_pcm_hw_params_any (rec_pcm, hw_params)) < 0)
  23.   {
  24.     return 1;
  25.   }
  26.  
  27.   snd_pcm_format_t fmt = SND_PCM_FORMAT_S16_LE;
  28.   if ((err = snd_pcm_hw_params_set_format (rec_pcm, hw_params, fmt)) < 0)
  29.   {
  30.     return 1;
  31.   }
  32.  
  33.   int sample_rate = 8000;
  34.   if ((err = snd_pcm_hw_params_set_rate (rec_pcm, hw_params, sample_rate, 0)) < 0)
  35.   {
  36.     return 1;
  37.   }
  38.  
  39.   int channels = 1;
  40.   if ((err = snd_pcm_hw_params_set_channels (rec_pcm, hw_params, channels)) < 0)
  41.   {
  42.     return 1;
  43.   }
  44.    
  45.   if ((err = snd_pcm_hw_params (rec_pcm, hw_params)) < 0)
  46.   {
  47.     return 1;
  48.   }
  49.   snd_pcm_hw_params_free(hw_params);
  50.  
  51.   snd_pcm_prepare(rec_pcm);
  52.   snd_pcm_start(rec_pcm);
  53.  
  54.   snd_pcm_drop(rec_pcm);
  55.   snd_pcm_prepare(rec_pcm);
  56.   snd_pcm_start(rec_pcm);
  57.  
  58.   snd_pcm_drop(rec_pcm);
  59.   snd_pcm_hw_free(rec_pcm);
  60.   snd_pcm_close(rec_pcm);
  61. }
Add Comment
Please, Sign In to add comment