Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_BUFFER_SIZE
- #define _USE_GET_PERIODS
- #define ALSA_PCM_NEW_HW_PARAMS_API
- #include <alsa/asoundlib.h>
- int main( int argc, char **argv )
- {
- int rc;
- snd_pcm_t *handle;
- snd_pcm_hw_params_t *params;
- unsigned int val, val2;
- int dir=0;
- snd_pcm_uframes_t frames;
- /* Oeffen PCM Device für Playback */
- rc = snd_pcm_open( &handle, "default",
- SND_PCM_STREAM_PLAYBACK, 0 );
- if ( rc<0 ) {
- fprintf( stderr, "unable to open device: %s\n",
- snd_strerror( rc ));
- exit( 1 );
- }
- /* Lege ein Hardware-Parameters Objekt an */
- snd_pcm_hw_params_alloca( ¶ms );
- /* Setze Default-Werte ein */
- snd_pcm_hw_params_any(handle, params);
- /* Gewünschte Params einsetzen ... */
- /* Interleave Mode */
- snd_pcm_hw_params_set_access(handle, params,
- SND_PCM_ACCESS_RW_INTERLEAVED);
- /* Signed 16-bit little endian format */
- snd_pcm_hw_params_set_format(handle, params,
- SND_PCM_FORMAT_S16_LE );
- /* 2-Kanaele (stereo) */
- snd_pcm_hw_params_set_channels(handle, params, 2);
- /* 44.100 Hz */
- val = 44100;
- snd_pcm_hw_params_set_rate_near(handle,
- params, &val, &dir);
- /* Schreibe params in Treiber */
- rc = snd_pcm_hw_params( handle, params );
- if ( rc<0 ) {
- fprintf( stderr, "unable to set hw parameters: %s\n",
- snd_strerror( rc ));
- exit( 1 );
- }
- /* Zeige Informationen über PCM Interface an */
- printf( "PCM Handle name: '%s'\n",
- snd_pcm_name( handle ));
- snd_pcm_hw_params_get_buffer_time( params, &val, &dir );
- printf( "buffer time: %d mu-Sekunden\n", val );
- #ifdef _USE_BUFFER_SIZE
- snd_pcm_hw_params_get_buffer_size( params, (snd_pcm_uframes_t *)&val);
- printf( "buffer size: %d frames\n", val );
- #endif
- #ifdef _USE_GET_PERIODS
- snd_pcm_hw_params_get_periods( params,
- &val, &dir );
- printf( "periods per buffer: %d frames\n", val );
- #endif
- snd_pcm_close( handle );
- return 0;
- }
Add Comment
Please, Sign In to add comment