524 totalFrames = 0; |
524 totalFrames = 0; |
525 audioBuffer = 0; |
525 audioBuffer = 0; |
526 internalBufferSize = default_buffer_size; |
526 internalBufferSize = default_buffer_size; |
527 clockFrequency = AudioGetHostClockFrequency() / 1000; |
527 clockFrequency = AudioGetHostClockFrequency() / 1000; |
528 errorCode = QAudio::NoError; |
528 errorCode = QAudio::NoError; |
529 stateCode = QAudio::StopState; |
529 stateCode = QAudio::StoppedState; |
530 |
530 |
531 intervalTimer = new QTimer(this); |
531 intervalTimer = new QTimer(this); |
532 intervalTimer->setInterval(1000); |
532 intervalTimer->setInterval(1000); |
533 connect(intervalTimer, SIGNAL(timeout()), SIGNAL(notify())); |
533 connect(intervalTimer, SIGNAL(timeout()), SIGNAL(notify())); |
534 } |
534 } |
734 } |
734 } |
735 |
735 |
736 void QAudioInputPrivate::stop() |
736 void QAudioInputPrivate::stop() |
737 { |
737 { |
738 QMutexLocker lock(&mutex); |
738 QMutexLocker lock(&mutex); |
739 if (stateCode != QAudio::StopState) { |
739 if (stateCode != QAudio::StoppedState) { |
740 audioThreadStop(); |
740 audioThreadStop(); |
741 audioBuffer->flush(true); |
741 audioBuffer->flush(true); |
742 |
742 |
743 errorCode = QAudio::NoError; |
743 errorCode = QAudio::NoError; |
744 stateCode = QAudio::StopState; |
744 stateCode = QAudio::StoppedState; |
745 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
745 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
746 } |
746 } |
747 } |
747 } |
748 |
748 |
749 void QAudioInputPrivate::reset() |
749 void QAudioInputPrivate::reset() |
750 { |
750 { |
751 QMutexLocker lock(&mutex); |
751 QMutexLocker lock(&mutex); |
752 if (stateCode != QAudio::StopState) { |
752 if (stateCode != QAudio::StoppedState) { |
753 audioThreadStop(); |
753 audioThreadStop(); |
754 |
754 |
755 errorCode = QAudio::NoError; |
755 errorCode = QAudio::NoError; |
756 stateCode = QAudio::StopState; |
756 stateCode = QAudio::StoppedState; |
757 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
757 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
758 } |
758 } |
759 } |
759 } |
760 |
760 |
761 void QAudioInputPrivate::suspend() |
761 void QAudioInputPrivate::suspend() |
763 QMutexLocker lock(&mutex); |
763 QMutexLocker lock(&mutex); |
764 if (stateCode == QAudio::ActiveState || stateCode == QAudio::IdleState) { |
764 if (stateCode == QAudio::ActiveState || stateCode == QAudio::IdleState) { |
765 audioThreadStop(); |
765 audioThreadStop(); |
766 |
766 |
767 errorCode = QAudio::NoError; |
767 errorCode = QAudio::NoError; |
768 stateCode = QAudio::SuspendState; |
768 stateCode = QAudio::SuspendedState; |
769 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
769 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
770 } |
770 } |
771 } |
771 } |
772 |
772 |
773 void QAudioInputPrivate::resume() |
773 void QAudioInputPrivate::resume() |
774 { |
774 { |
775 QMutexLocker lock(&mutex); |
775 QMutexLocker lock(&mutex); |
776 if (stateCode == QAudio::SuspendState) { |
776 if (stateCode == QAudio::SuspendedState) { |
777 audioThreadStart(); |
777 audioThreadStart(); |
778 |
778 |
779 errorCode = QAudio::NoError; |
779 errorCode = QAudio::NoError; |
780 stateCode = QAudio::ActiveState; |
780 stateCode = QAudio::ActiveState; |
781 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
781 QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); |
810 int QAudioInputPrivate::notifyInterval() const |
810 int QAudioInputPrivate::notifyInterval() const |
811 { |
811 { |
812 return intervalTimer->interval(); |
812 return intervalTimer->interval(); |
813 } |
813 } |
814 |
814 |
815 qint64 QAudioInputPrivate::totalTime() const |
815 qint64 QAudioInputPrivate::processedUSecs() const |
816 { |
816 { |
817 return totalFrames * 1000000 / audioFormat.frequency(); |
817 return totalFrames * 1000000 / audioFormat.frequency(); |
818 } |
818 } |
819 |
819 |
820 qint64 QAudioInputPrivate::clock() const |
820 qint64 QAudioInputPrivate::elapsedUSecs() const |
821 { |
821 { |
822 if (stateCode == QAudio::StopState) |
822 if (stateCode == QAudio::StoppedState) |
823 return 0; |
823 return 0; |
824 |
824 |
825 return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); |
825 return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); |
826 } |
826 } |
827 |
827 |
873 QMutexLocker lock(&mutex); |
873 QMutexLocker lock(&mutex); |
874 if (stateCode == QAudio::ActiveState) { |
874 if (stateCode == QAudio::ActiveState) { |
875 audioDeviceStop(); |
875 audioDeviceStop(); |
876 |
876 |
877 errorCode = QAudio::IOError; |
877 errorCode = QAudio::IOError; |
878 stateCode = QAudio::StopState; |
878 stateCode = QAudio::StoppedState; |
879 QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); |
879 QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); |
880 } |
880 } |
881 } |
881 } |
882 |
882 |
883 void QAudioInputPrivate::startTimers() |
883 void QAudioInputPrivate::startTimers() |