diff options
author | Kurt Korbatits <kurt.korbatits@nokia.com> | 2009-09-30 04:53:37 (GMT) |
---|---|---|
committer | Kurt Korbatits <kurt.korbatits@nokia.com> | 2009-09-30 04:53:37 (GMT) |
commit | f4bcf5c9fd51ed1923239ea1ad0d78bcd3d56f62 (patch) | |
tree | e149c3d355882cec80031b7bc0927ee1a9375809 /src/multimedia | |
parent | 8c3bf71e6fcbcfb21b9574e25cfdb00614a0c68d (diff) | |
download | Qt-f4bcf5c9fd51ed1923239ea1ad0d78bcd3d56f62.zip Qt-f4bcf5c9fd51ed1923239ea1ad0d78bcd3d56f62.tar.gz Qt-f4bcf5c9fd51ed1923239ea1ad0d78bcd3d56f62.tar.bz2 |
Fixed error in notify() signal and totalTime() in QAudioInput and
QAudioOutput.
-The notify() signal was not firing the correct number of times.
-The totalTime() on wince was incorrect (unit test).
Reviewed-by:Justin McPherson
Diffstat (limited to 'src/multimedia')
-rw-r--r-- | src/multimedia/audio/qaudioinput_alsa_p.cpp | 11 | ||||
-rw-r--r-- | src/multimedia/audio/qaudioinput_alsa_p.h | 1 | ||||
-rw-r--r-- | src/multimedia/audio/qaudioinput_win32_p.cpp | 12 | ||||
-rw-r--r-- | src/multimedia/audio/qaudioinput_win32_p.h | 1 | ||||
-rw-r--r-- | src/multimedia/audio/qaudiooutput_alsa_p.cpp | 13 | ||||
-rw-r--r-- | src/multimedia/audio/qaudiooutput_alsa_p.h | 1 | ||||
-rw-r--r-- | src/multimedia/audio/qaudiooutput_win32_p.cpp | 33 | ||||
-rw-r--r-- | src/multimedia/audio/qaudiooutput_win32_p.h | 1 |
8 files changed, 62 insertions, 11 deletions
diff --git a/src/multimedia/audio/qaudioinput_alsa_p.cpp b/src/multimedia/audio/qaudioinput_alsa_p.cpp index 0192468..46c4392 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.cpp +++ b/src/multimedia/audio/qaudioinput_alsa_p.cpp @@ -57,6 +57,8 @@ QT_BEGIN_NAMESPACE //#define DEBUG_AUDIO 1 +static const int minimumIntervalTime = 50; + QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): settings(audioFormat) { @@ -248,6 +250,7 @@ bool QAudioInputPrivate::open() qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()"; #endif timeStamp.restart(); + elapsedTimeOffset = 0; int dir; int err=-1; @@ -531,7 +534,10 @@ int QAudioInputPrivate::periodSize() const void QAudioInputPrivate::setNotifyInterval(int ms) { - intervalTime = ms; + if(ms >= minimumIntervalTime) + intervalTime = ms; + else + intervalTime = minimumIntervalTime; } int QAudioInputPrivate::notifyInterval() const @@ -579,8 +585,9 @@ bool QAudioInputPrivate::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; diff --git a/src/multimedia/audio/qaudioinput_alsa_p.h b/src/multimedia/audio/qaudioinput_alsa_p.h index a1cc738..5583ea0 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.h +++ b/src/multimedia/audio/qaudioinput_alsa_p.h @@ -117,6 +117,7 @@ private: QTimer* timer; QTime timeStamp; + qint64 elapsedTimeOffset; int intervalTime; char* audioBuffer; int bytesAvailable; diff --git a/src/multimedia/audio/qaudioinput_win32_p.cpp b/src/multimedia/audio/qaudioinput_win32_p.cpp index 31441ae..d4226f5 100644 --- a/src/multimedia/audio/qaudioinput_win32_p.cpp +++ b/src/multimedia/audio/qaudioinput_win32_p.cpp @@ -59,6 +59,8 @@ QT_BEGIN_NAMESPACE static CRITICAL_SECTION waveInCriticalSection; +static const int minimumIntervalTime = 50; + QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): settings(audioFormat) { @@ -226,6 +228,7 @@ bool QAudioInputPrivate::open() period_size = buffer_size/2; #endif timeStamp.restart(); + elapsedTimeOffset = 0; wfx.nSamplesPerSec = settings.frequency(); wfx.wBitsPerSample = settings.sampleSize(); wfx.nChannels = settings.channels(); @@ -297,6 +300,7 @@ bool QAudioInputPrivate::open() return false; } timeStampOpened.restart(); + elapsedTimeOffset = 0; totalTimeValue = 0; errorState = QAudio::NoError; deviceState = QAudio::ActiveState; @@ -473,7 +477,10 @@ int QAudioInputPrivate::periodSize() const void QAudioInputPrivate::setNotifyInterval(int ms) { - intervalTime = ms; + if(ms >= minimumIntervalTime) + intervalTime = ms; + else + intervalTime = minimumIntervalTime; } int QAudioInputPrivate::notifyInterval() const @@ -524,8 +531,9 @@ bool QAudioInputPrivate::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; diff --git a/src/multimedia/audio/qaudioinput_win32_p.h b/src/multimedia/audio/qaudioinput_win32_p.h index 3363b6a..26c470d 100644 --- a/src/multimedia/audio/qaudioinput_win32_p.h +++ b/src/multimedia/audio/qaudioinput_win32_p.h @@ -109,6 +109,7 @@ private: int bytesAvailable; int intervalTime; QTime timeStamp; + qint64 elapsedTimeOffset; QTime timeStampOpened; qint64 totalTimeValue; bool pullMode; diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.cpp b/src/multimedia/audio/qaudiooutput_alsa_p.cpp index cfd3c55..0d37d61 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; @@ -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; diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.h b/src/multimedia/audio/qaudiooutput_alsa_p.h index 63fe348..6d4177d 100644 --- a/src/multimedia/audio/qaudiooutput_alsa_p.h +++ b/src/multimedia/audio/qaudiooutput_alsa_p.h @@ -134,6 +134,7 @@ private: QByteArray m_device; int bytesAvailable; QTime timeStamp; + qint64 elapsedTimeOffset; char* audioBuffer; snd_pcm_t* handle; snd_async_handler_t* ahandler; diff --git a/src/multimedia/audio/qaudiooutput_win32_p.cpp b/src/multimedia/audio/qaudiooutput_win32_p.cpp index aea3a3f..bb61f41 100644 --- a/src/multimedia/audio/qaudiooutput_win32_p.cpp +++ b/src/multimedia/audio/qaudiooutput_win32_p.cpp @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE static CRITICAL_SECTION waveOutCriticalSection; +static const int minimumIntervalTime = 50; + QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): settings(audioFormat) { @@ -221,6 +223,7 @@ bool QAudioOutputPrivate::open() audioBuffer = new char[buffer_size]; timeStamp.restart(); + elapsedTimeOffset = 0; wfx.nSamplesPerSec = settings.frequency(); wfx.wBitsPerSample = settings.sampleSize(); @@ -261,6 +264,7 @@ bool QAudioOutputPrivate::open() totalTimeValue = 0; timeStampOpened.restart(); + elapsedTimeOffset = 0; errorState = QAudio::NoError; if(pullMode) { @@ -316,7 +320,10 @@ int QAudioOutputPrivate::bufferSize() const void QAudioOutputPrivate::setNotifyInterval(int ms) { - intervalTime = ms; + if(ms >= minimumIntervalTime) + intervalTime = ms; + else + intervalTime = minimumIntervalTime; } int QAudioOutputPrivate::notifyInterval() const @@ -420,7 +427,6 @@ void QAudioOutputPrivate::feedback() bool QAudioOutputPrivate::deviceReady() { if(pullMode) { - int i = 0; int chunks = bytesAvailable/period_size; #ifdef DEBUG_AUDIO qDebug()<<"deviceReady() avail="<<bytesAvailable<<" bytes, period size="<<period_size<<" bytes"; @@ -430,6 +436,22 @@ bool QAudioOutputPrivate::deviceReady() if(totalTimeValue == 0) startup = true; + bool full=false; + EnterCriticalSection(&waveOutCriticalSection); + if(waveFreeBlockCount==0) full = true; + LeaveCriticalSection(&waveOutCriticalSection); + if (full){ +#ifdef DEBUG_AUDIO + qDebug() << "Skipping data as unable to write"; +#endif + if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime ) { + emit notify(); + elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; + timeStamp.restart(); + } + return true; + } + if(startup) waveOutPause(hWaveOut); int input = period_size*chunks; @@ -451,7 +473,7 @@ bool QAudioOutputPrivate::deviceReady() } LeaveCriticalSection(&waveOutCriticalSection); - } else if(i < 0) { + } else if(l < 0) { bytesAvailable = bytesFree(); errorState = QAudio::IOError; } @@ -459,8 +481,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(); } @@ -468,7 +491,7 @@ bool QAudioOutputPrivate::deviceReady() } qint64 QAudioOutputPrivate::clock() const -{ +{ if(deviceState != QAudio::ActiveState) return 0; diff --git a/src/multimedia/audio/qaudiooutput_win32_p.h b/src/multimedia/audio/qaudiooutput_win32_p.h index 5c08bf4..bcf8e1e 100644 --- a/src/multimedia/audio/qaudiooutput_win32_p.h +++ b/src/multimedia/audio/qaudiooutput_win32_p.h @@ -109,6 +109,7 @@ private: bool resuming; int bytesAvailable; QTime timeStamp; + qint64 elapsedTimeOffset; QTime timeStampOpened; qint32 buffer_size; qint32 period_size; |