62 struct sched_param sched;
63 sched.sched_priority = 50;
64 int res = sched_setscheduler( 0, SCHED_FIFO, &sched );
65 sched_getparam( 0, &sched );
67 __ERRORLOG(
"Can't set realtime scheduling for ALSA Driver" );
69 __INFOLOG( QString(
"Scheduling priority = %1" ).arg( sched.sched_priority ) );
75 __ERRORLOG( QString(
"Cannot prepare audio interface for use: %1" )
76 .arg( snd_strerror ( err ) ) );
80 __INFOLOG( QString(
"nFrames: %1" ).arg( nFrames ) );
81 short pBuffer[ nFrames * 2 ];
86 int nTimeoutInMilliseconds = 100;
92 for (
int i = 0; i < nFrames; ++i ) {
93 pBuffer[ i * 2 ] = ( short )( pOut_L[ i ] * 32768.0 );
94 pBuffer[ i * 2 + 1 ] = ( short )( pOut_R[ i ] * 32768.0 );
100 nTimeoutInMilliseconds ) ) < 1 ) {
108 ___ERRORLOG( QString(
"timeout after [%1] milliseconds" )
109 .arg( nTimeoutInMilliseconds ) );
111 ___ERRORLOG( QString(
"Error while waiting for playback stream: %1" )
112 .arg( snd_strerror( err ) ) );
120 if ( ( err = snd_pcm_writei( pDriver->
m_pPlayback_handle, pBuffer, nFrames ) ) < 0 ) {
121 ___ERRORLOG( QString(
"Error while writing playback stream: %1" )
122 .arg( snd_strerror( err ) ) );
127 ___INFOLOG(
"Successfully recovered from error. Attempt to write buffer again." );
128 if ( ( err = snd_pcm_writei( pDriver->
m_pPlayback_handle, pBuffer, nFrames ) ) < 0 ) {
129 ___ERRORLOG( QString(
"Unable to write playback stream again: %1" )
130 .arg( snd_strerror( err ) ) );
134 __ERRORLOG( QString(
"Can't recover from XRUN: %1" )
135 .arg( snd_strerror( err ) ) );
139 __ERRORLOG( QString(
"Can't recover from XRUN: %1" )
140 .arg( snd_strerror( err ) ) );
155 void **pHints, **pHint;
157 if ( snd_device_name_hint( -1,
"pcm", &pHints) < 0) {
158 ERRORLOG(
"Couldn't get device hints" );
162 for ( pHint = pHints; *pHint !=
nullptr; pHint++) {
163 const char *sName = snd_device_name_get_hint( *pHint,
"NAME"),
164 *sIOID = snd_device_name_get_hint( *pHint,
"IOID");
166 if ( sIOID && QString( sIOID ) !=
"Output") {
170 QString sDev = QString( sName );
172 free( (
void *)sName );
175 free( (
void *)sIOID );
177 result.push_back( sDev );
179 snd_device_name_free_hint( pHints );
226 SND_PCM_STREAM_PLAYBACK,
227 SND_PCM_NONBLOCK ) ) < 0 ) {
228 ERRORLOG( QString(
"Cannot open audio device [%1] (non-blocking): %2" )
230 .arg( snd_strerror( err ) ) );
236 SND_PCM_STREAM_PLAYBACK,
237 SND_PCM_NONBLOCK ) ) < 0 ) {
238 ERRORLOG( QString(
"Cannot open default audio device [%1] (non-blocking) either: %2" )
240 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
243 WARNINGLOG( QString(
"Using ALSA device [%1] instead." )
247 ERRORLOG( QString(
"Unable to close non-blocking playback stream of audio device [%1]: %2" )
249 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
255 SND_PCM_STREAM_PLAYBACK, 0 ) ) < 0 ) {
256 ERRORLOG( QString(
"Cannot open audio device [%1] (blocking): %2" )
258 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
262 snd_pcm_hw_params_t *hw_params;
263 snd_pcm_hw_params_alloca( &hw_params );
264 if ( hw_params ==
nullptr ) {
265 ERRORLOG(
"error in snd_pcm_hw_params_alloca" );
270 ERRORLOG( QString(
"error in snd_pcm_hw_params_any: %1" )
271 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
278 SND_PCM_ACCESS_RW_INTERLEAVED ) ) < 0 ) {
279 ERRORLOG( QString(
"error in snd_pcm_hw_params_set_access: %1" )
280 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
286 SND_PCM_FORMAT_S16_LE ) ) < 0 ) {
287 ERRORLOG( QString(
"error in snd_pcm_hw_params_set_format: %1" )
288 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
298 hw_params, nChannels ) ) < 0 ) {
299 ERRORLOG( QString(
"error in snd_pcm_hw_params_set_channels: %1" )
300 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
311 unsigned nPeriods = 2;
316 ERRORLOG( QString(
"error in snd_pcm_hw_params_set_periods_near: %1" )
317 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
320 INFOLOG( QString(
"nPeriods: %1" ).arg( nPeriods ) );
328 ERRORLOG( QString(
"error in snd_pcm_hw_params_set_period_size_near: %1" )
329 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
335 ERRORLOG( QString(
"error in snd_pcm_hw_params: %1" )
336 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
340 snd_pcm_hw_params_get_rate( hw_params, &
m_nSampleRate,
nullptr );
342 INFOLOG( QString(
"*** PERIOD SIZE: %1" ).arg( period_size ) );
358 pthread_attr_init( &attr );