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") {
167 free( (
void *)sIOID );
170 free( (
void *)sName );
176 const QString sDev = QString( sName );
178 free( (
void *)sName );
181 free( (
void *)sIOID );
183 result.push_back( sDev );
185 snd_device_name_free_hint( pHints );
232 SND_PCM_STREAM_PLAYBACK,
233 SND_PCM_NONBLOCK ) ) < 0 ) {
234 ERRORLOG( QString(
"Cannot open audio device [%1] (non-blocking): %2" )
236 .arg( snd_strerror( err ) ) );
242 SND_PCM_STREAM_PLAYBACK,
243 SND_PCM_NONBLOCK ) ) < 0 ) {
244 ERRORLOG( QString(
"Cannot open default audio device [%1] (non-blocking) either: %2" )
246 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
249 WARNINGLOG( QString(
"Using ALSA device [%1] instead." )
253 ERRORLOG( QString(
"Unable to close non-blocking playback stream of audio device [%1]: %2" )
255 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
261 SND_PCM_STREAM_PLAYBACK, 0 ) ) < 0 ) {
262 ERRORLOG( QString(
"Cannot open audio device [%1] (blocking): %2" )
264 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
268 snd_pcm_hw_params_t *hw_params;
269 snd_pcm_hw_params_alloca( &hw_params );
270 if ( hw_params ==
nullptr ) {
271 ERRORLOG(
"error in snd_pcm_hw_params_alloca" );
276 ERRORLOG( QString(
"error in snd_pcm_hw_params_any: %1" )
277 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
284 SND_PCM_ACCESS_RW_INTERLEAVED ) ) < 0 ) {
285 ERRORLOG( QString(
"error in snd_pcm_hw_params_set_access: %1" )
286 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
292 SND_PCM_FORMAT_S16_LE ) ) < 0 ) {
293 ERRORLOG( QString(
"error in snd_pcm_hw_params_set_format: %1" )
294 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
304 hw_params, nChannels ) ) < 0 ) {
305 ERRORLOG( QString(
"error in snd_pcm_hw_params_set_channels: %1" )
306 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
317 unsigned nPeriods = 2;
322 ERRORLOG( QString(
"error in snd_pcm_hw_params_set_periods_near: %1" )
323 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
326 INFOLOG( QString(
"nPeriods: %1" ).arg( nPeriods ) );
334 ERRORLOG( QString(
"error in snd_pcm_hw_params_set_period_size_near: %1" )
335 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
341 ERRORLOG( QString(
"error in snd_pcm_hw_params: %1" )
342 .arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
346 snd_pcm_hw_params_get_rate( hw_params, &
m_nSampleRate,
nullptr );
348 INFOLOG( QString(
"*** PERIOD SIZE: %1" ).arg( period_size ) );
364 pthread_attr_init( &attr );