Guest User

Untitled

a guest
Jan 12th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. #define _USE_BUFFER_SIZE
  2. #define _USE_GET_PERIODS
  3.  
  4. #define ALSA_PCM_NEW_HW_PARAMS_API
  5.  
  6. #include <alsa/asoundlib.h>
  7.  
  8. int main( int argc, char **argv )
  9. {
  10.     int rc;
  11.     snd_pcm_t *handle;
  12.     snd_pcm_hw_params_t *params;
  13.     unsigned int val, val2;
  14.     int dir=0;
  15.     snd_pcm_uframes_t frames;
  16.  
  17.     /* Oeffen PCM Device für Playback */
  18.     rc = snd_pcm_open( &handle, "default",
  19.             SND_PCM_STREAM_PLAYBACK, 0 );
  20.     if ( rc<0 ) {
  21.         fprintf( stderr, "unable to open device: %s\n",
  22.                 snd_strerror( rc ));
  23.         exit( 1 );
  24.     }
  25.  
  26.     /* Lege ein Hardware-Parameters Objekt an */
  27.     snd_pcm_hw_params_alloca( &params );
  28.  
  29.     /* Setze Default-Werte ein */
  30.     snd_pcm_hw_params_any(handle, params);
  31.  
  32.     /* Gewünschte Params einsetzen ... */
  33.  
  34.     /* Interleave Mode */
  35.     snd_pcm_hw_params_set_access(handle, params,
  36.             SND_PCM_ACCESS_RW_INTERLEAVED);
  37.  
  38.     /* Signed 16-bit little endian format */
  39.     snd_pcm_hw_params_set_format(handle, params,
  40.             SND_PCM_FORMAT_S16_LE );
  41.  
  42.     /* 2-Kanaele (stereo) */
  43.     snd_pcm_hw_params_set_channels(handle, params, 2);
  44.  
  45.     /* 44.100 Hz */
  46.     val = 44100;
  47.     snd_pcm_hw_params_set_rate_near(handle,
  48.             params, &val, &dir);
  49.  
  50.     /* Schreibe params in Treiber */
  51.     rc = snd_pcm_hw_params( handle, params );
  52.     if ( rc<0 ) {
  53.         fprintf( stderr, "unable to set hw parameters: %s\n",
  54.                 snd_strerror( rc ));
  55.         exit( 1 );
  56.     }
  57.  
  58.     /* Zeige Informationen über PCM Interface an */
  59.     printf( "PCM Handle name: '%s'\n",
  60.             snd_pcm_name( handle ));
  61.  
  62.    
  63.     snd_pcm_hw_params_get_buffer_time( params, &val, &dir );
  64.     printf( "buffer time: %d mu-Sekunden\n", val );
  65.  
  66. #ifdef _USE_BUFFER_SIZE
  67.     snd_pcm_hw_params_get_buffer_size( params, (snd_pcm_uframes_t *)&val);
  68.     printf( "buffer size: %d frames\n", val );
  69. #endif
  70. #ifdef _USE_GET_PERIODS
  71.     snd_pcm_hw_params_get_periods( params,
  72.             &val, &dir );
  73.     printf( "periods per buffer: %d frames\n", val );
  74. #endif
  75.  
  76.     snd_pcm_close( handle );
  77.     return 0;
  78. }
Add Comment
Please, Sign In to add comment