rendered paste bodyif ( (err= snd_pcm_open( &playback_handle, argv[1], SND_PCM_STREAM_PLAYBACK, 0 ))<0) {
fprintf( stderr, "cannot open audio device %s (%s)\n", argv[1],snd_strerror( err ) );
exit( 1 );
}
printf( argv[1] );
if ( ( err=snd_pcm_hw_params_malloc( &hw_params ) )<0 )
{
fprintf( stderr,"cannot allocate hardware parameter structure (%s)\n",snd_strerror( err ) );
exit( 1 );
}
if (( err= snd_pcm_hw_params_any( playback_handle, hw_params))<0 ){
fprintf( stderr," cannot initialize hardware parameter structure (%s)\n", snd_strerror( err ) );
}
if ( ( err=snd_pcm_hw_params_set_access( playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED ) )<0 )
{
fprintf( stderr,"cannot set access type (%s)\n",snd_strerror( err ) );
exit( 1 );
}
if ( ( err=snd_pcm_hw_params_set_format( playback_handle, hw_params, SND_PCM_FORMAT_S16_LE ) )<0 )
{
fprintf( stderr,"cannot set sample format (%s)\n",snd_strerror( err ) );
exit( 1 );
}
unsigned int rate=8000;
int value=0;
if ( ( err=snd_pcm_hw_params_set_rate_near( playback_handle, hw_params, &rate,&value ) )<0 )
{
fprintf( stderr,"cannot set sample rate (%s)\n",snd_strerror( err ) );
exit( 1 );
}
if ( ( err=snd_pcm_hw_params_set_channels( playback_handle, hw_params, 1 ) )<0 )
{
fprintf( stderr,"cannot set channel count (%s)\n",snd_strerror( err ) );
exit( 1 );
}
snd_pcm_uframes_t frames=512;
snd_pcm_uframes_t periodsize=frames;
int dir=0;
dir=0;
snd_pcm_uframes_t bufsize;
bufsize=8192;
periodsize=bufsize/PERIODS;
bufsize=4*periodsize;
if ( ( err=snd_pcm_hw_params_set_buffer_size_near( playback_handle, hw_params, &bufsize ) )<0 )
{
fprintf( stderr,"cannot set buffer size (%s)\n",snd_strerror( err ) );
exit( 1 );
}
if ( ( err=snd_pcm_hw_params_set_period_size_near( playback_handle, hw_params, &periodsize,&dir ) )<0 )
{
fprintf( stderr,"cannot set period size (%s)\n",snd_strerror( err ) );
exit( 1 );
}
if ( ( err=snd_pcm_hw_params_get_period_size( hw_params, &periodsize,&dir ) )<0 )
{
fprintf( stderr,"cannot get period size (%s)\n",snd_strerror( err ) );
exit( 1 );
}
if ( ( err=snd_pcm_hw_params_get_buffer_size( hw_params, &bufsize ) )<0 )
{
fprintf( stderr,"cannot get buffer size (%s)\n",snd_strerror( err ) );
exit( 1 );
}
printf( "bufsize=%d period size=%d\r\n", bufsize, periodsize );
if ( ( err=snd_pcm_hw_params_set_periods( playback_handle, hw_params, PERIODS,0 ) )<0 )
{
fprintf( stderr,"cannot set periods (%s)\n",snd_strerror( err ) );
exit( 1 );
}
if ( ( err=snd_pcm_hw_params( playback_handle, hw_params ) )<0 )
{
fprintf( stderr,"cannot set hw params (%s)\n",snd_strerror( err ) );
exit( 1 );
}
snd_pcm_hw_params_free( hw_params );
//software parms
snd_pcm_sw_params_t* sw_params;
snd_pcm_sw_params_malloc( &sw_params );
if (( err=snd_pcm_sw_params_current( playback_handle, sw_params ))<0 )
{
fprintf( stderr,"cannot get current sw params (%s)\n",snd_strerror( err ) );
};
if (( err=snd_pcm_sw_params_set_start_threshold( playback_handle, sw_params, bufsize ))<0 )
{
fprintf( stderr,"cannot set threshold (%s)\n",snd_strerror( err ) );
};
if (( err=snd_pcm_sw_params_set_avail_min( playback_handle, sw_params, periodsize ))<0 )
{
fprintf( stderr,"cannot set threshold (%s)\n",snd_strerror( err ) );
};
if (( err=snd_pcm_sw_params_set_xfer_align( playback_handle, sw_params, 1 ))<0 )
{
fprintf( stderr,"cannot set threshold (%s)\n",snd_strerror( err ) );
};
if ( ( err=snd_pcm_sw_params( playback_handle, sw_params ) )<0 )
{
fprintf( stderr,"cannot set sw params (%s)\n",snd_strerror( err ) );
exit( 1 );
}
snd_pcm_sw_params_free( sw_params );
if ( ( err=snd_pcm_prepare( playback_handle ) )<0 )
{
fprintf( stderr,"cannot prepare audio interface (%s)\n",snd_strerror( err ) );
exit( 1 );
}