diff options
Diffstat (limited to 'src/multimedia/audio/qaudiooutput_alsa_p.cpp')
-rw-r--r-- | src/multimedia/audio/qaudiooutput_alsa_p.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.cpp b/src/multimedia/audio/qaudiooutput_alsa_p.cpp index e8a3f5c..d814d97 100644 --- a/src/multimedia/audio/qaudiooutput_alsa_p.cpp +++ b/src/multimedia/audio/qaudiooutput_alsa_p.cpp @@ -57,6 +57,8 @@ QT_BEGIN_NAMESPACE //#define DEBUG_AUDIO 1 +static const int minimumIntervalTime = 50; + QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): settings(audioFormat) { @@ -271,6 +273,7 @@ bool QAudioOutputPrivate::open() qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()"; #endif timeStamp.restart(); + elapsedTimeOffset = 0; int dir; int err=-1; @@ -304,69 +307,69 @@ bool QAudioOutputPrivate::open() err = snd_pcm_hw_params_any( handle, hwparams ); if ( err < 0 ) { fatal = true; - errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_any: err = %1")).arg(err); + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_any: err = %1").arg(err); } if ( !fatal ) { err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 ); if ( err < 0 ) { fatal = true; - errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_rate_resample: err = %1")).arg(err); + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params_set_access( handle, hwparams, access ); if ( err < 0 ) { fatal = true; - errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_access: err = %1")).arg(err); + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_access: err = %1").arg(err); } } if ( !fatal ) { err = setFormat(); if ( err < 0 ) { fatal = true; - errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_format: err = %1")).arg(err); + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_format: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() ); if ( err < 0 ) { fatal = true; - errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_channels: err = %1")).arg(err); + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_channels: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 ); if ( err < 0 ) { fatal = true; - errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1")).arg(err); + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir); if ( err < 0 ) { fatal = true; - errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1")).arg(err); + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir); if ( err < 0 ) { fatal = true; - errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_period_time_near: err = %1")).arg(err); + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir); if ( err < 0 ) { fatal = true; - errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_periods_near: err = %1")).arg(err); + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err); } } if ( !fatal ) { err = snd_pcm_hw_params(handle, hwparams); if ( err < 0 ) { fatal = true; - errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params: err = %1")).arg(err); + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params: err = %1").arg(err); } } if( err < 0) { @@ -404,6 +407,8 @@ bool QAudioOutputPrivate::open() // Step 6: Start audio processing timer->start(period_time/1000); + timeStamp.restart(); + elapsedTimeOffset = 0; errorState = QAudio::NoError; totalTimeValue = 0; opened = true; @@ -500,7 +505,10 @@ int QAudioOutputPrivate::bufferSize() const void QAudioOutputPrivate::setNotifyInterval(int ms) { - intervalTime = ms; + if(ms >= minimumIntervalTime) + intervalTime = ms; + else + intervalTime = minimumIntervalTime; } int QAudioOutputPrivate::notifyInterval() const @@ -629,8 +637,9 @@ bool QAudioOutputPrivate::deviceReady() if(deviceState != QAudio::ActiveState) return true; - if(timeStamp.elapsed() > intervalTime && intervalTime > 50) { + if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) { emit notify(); + elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; timeStamp.restart(); } return true; @@ -641,7 +650,7 @@ qint64 QAudioOutputPrivate::clock() const if(!handle) return 0; - if(deviceState != QAudio::ActiveState) + if (deviceState == QAudio::StopState) return 0; snd_pcm_status_t* status; |