From 0a7be12efadd9b61a205626751a3282e80243a69 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 6 Jun 2014 22:52:44 +0200 Subject: [PATCH] Fixes around audio "on remote computer" * Better options to debug * Fixes as of n2, https://dev.vatsim-germany.org/boards/22/topics/1792?r=1802#message-1802 * Doxygen --- samples/blackcore/tool.cpp | 16 ++++++++++++++++ src/blackcore/context_audio_impl.cpp | 4 ++++ src/blackmisc/audiodevice.cpp | 12 ++++++------ src/blackmisc/audiodevice.h | 25 +++++++++++-------------- src/blacksound/soundgenerator.cpp | 19 ++++++++++++++++++- src/blacksound/soundgenerator.h | 3 +++ 6 files changed, 58 insertions(+), 21 deletions(-) diff --git a/samples/blackcore/tool.cpp b/samples/blackcore/tool.cpp index 54160e0d1..3bbe7e15e 100644 --- a/samples/blackcore/tool.cpp +++ b/samples/blackcore/tool.cpp @@ -3,6 +3,8 @@ #include "blackmisc/indexvariantmap.h" #include "blackmisc/avallclasses.h" #include "blackmisc/pqallquantities.h" +#include "blacksound/soundgenerator.h" + #include #include #include @@ -54,6 +56,7 @@ namespace BlackMiscTest qDebug() << "x .. to exit 0 .. settings"; qDebug() << "1 .. ATC booked 2 .. ATC online"; qDebug() << "3 .. Aircrafts in range 4 .. my aircraft 5 .. voice rooms"; + qDebug() << "6 .. vatlib audio devices 7 .. Qt audio devices"; qDebug() << "-------------"; qDebug() << "oe . redirect enabled od . disable redirect"; qDebug() << "-------------"; @@ -101,6 +104,19 @@ namespace BlackMiscTest qDebug() << "voice rooms"; qDebug() << audioContext->getComVoiceRooms(); } + else if (line.startsWith("6")) + { + qDebug() << "-------------"; + qDebug() << "vatlib audio devices"; + qDebug() << audioContext->getAudioDevices(); + } + else if (line.startsWith("7")) + { + qDebug() << "-------------"; + qDebug() << "Qt audio devices"; + BlackSound::CSoundGenerator::printAllQtSoundDevices(); + } + else if (line.startsWith("oe")) { applicationContext->setOutputRedirectionLevel(IContextApplication::RedirectAllOutput); diff --git a/src/blackcore/context_audio_impl.cpp b/src/blackcore/context_audio_impl.cpp index 138f1cebb..2d05f06b2 100644 --- a/src/blackcore/context_audio_impl.cpp +++ b/src/blackcore/context_audio_impl.cpp @@ -164,10 +164,14 @@ namespace BlackCore { Q_ASSERT(this->m_voice); if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, com1.toQString(), com2.toQString()); + + // volumes qint32 vol1 = com1.getVolumeOutput(); qint32 vol2 = com2.getVolumeOutput(); this->m_voice->setRoomOutputVolume(IVoice::COM1, vol1); this->m_voice->setRoomOutputVolume(IVoice::COM2, vol2); + + // enable / disable in the same step this->m_voice->switchAudioOutput(IVoice::COM1, com1.isEnabled()); this->m_voice->switchAudioOutput(IVoice::COM2, com2.isEnabled()); } diff --git a/src/blackmisc/audiodevice.cpp b/src/blackmisc/audiodevice.cpp index 61c318f06..e30266f2f 100644 --- a/src/blackmisc/audiodevice.cpp +++ b/src/blackmisc/audiodevice.cpp @@ -17,7 +17,7 @@ namespace BlackMisc */ CAudioDevice::CAudioDevice() : m_type(Unknown), m_deviceIndex(invalidDeviceIndex()), - m_deviceName(""), m_hostName(CAudioDevice::hostName()) + m_deviceName(""), m_hostName(CAudioDevice::computerHostName()) { // void } @@ -27,7 +27,7 @@ namespace BlackMisc */ CAudioDevice::CAudioDevice(DeviceType type, const qint16 index, const QString &name) : m_type(type), m_deviceIndex(index), - m_deviceName(name), m_hostName(CAudioDevice::hostName()) + m_deviceName(name), m_hostName(CAudioDevice::computerHostName()) { // void } @@ -35,10 +35,10 @@ namespace BlackMisc /* * Host name */ - QString CAudioDevice::hostName() + const QString &CAudioDevice::computerHostName() { - QHostInfo hostInfo = QHostInfo::fromName(QHostInfo::localHostName()); - return hostInfo.localHostName(); + static const QString hostName = QHostInfo::fromName(QHostInfo::localHostName()).localHostName(); + return hostName; } /* @@ -100,7 +100,7 @@ namespace BlackMisc if (this->m_hostName.isEmpty()) return m_deviceName; QString s(this->m_deviceName); s.append(" ["); - s.append(this->hostName()); + s.append(this->getHostName()); s.append("]"); return s; } diff --git a/src/blackmisc/audiodevice.h b/src/blackmisc/audiodevice.h index fe40cad20..afb327387 100644 --- a/src/blackmisc/audiodevice.h +++ b/src/blackmisc/audiodevice.h @@ -42,25 +42,25 @@ namespace BlackMisc */ CAudioDevice(); - //! \brief Constructor. + //! Constructor. CAudioDevice(DeviceType type, const qint16 index, const QString &getName); //! \copydoc CValueObject::toQVariant - virtual QVariant toQVariant() const override - { - return QVariant::fromValue(*this); - } + virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } - //! \brief Get the device index + //! Get the device index qint16 getIndex() const { return m_deviceIndex; } //! Get the device name const QString &getName() const { return m_deviceName; } - //! \brief Type + //! Host name + const QString &getHostName() const { return m_hostName; } + + //! Type DeviceType getType() const { return m_type; } - //! \brief Valid audio device object? + //! Valid audio device object? bool isValid() const { return m_deviceIndex >= -1 && !m_deviceName.isEmpty(); } //! \brief Equal operator == @@ -78,7 +78,7 @@ namespace BlackMisc //! \copydoc CValueObject::fromJson void fromJson(const QJsonObject &json) override; - //! \brief Register metadata + //! Register metadata static void registerMetadata(); //! \copydoc TupleConverter<>::jsonMembers() @@ -137,11 +137,8 @@ namespace BlackMisc QString m_hostName; private: - /*! - * \brief Own host name - * \return - */ - static QString hostName(); + //! Own host name + static const QString &computerHostName(); }; } // Audio diff --git a/src/blacksound/soundgenerator.cpp b/src/blacksound/soundgenerator.cpp index 334bdcb78..1d573a100 100644 --- a/src/blacksound/soundgenerator.cpp +++ b/src/blacksound/soundgenerator.cpp @@ -391,7 +391,6 @@ namespace BlackSound } } return qtDevice; - } CSoundGenerator *CSoundGenerator::playSignal(qint32 volume, const QList &tones, QAudioDeviceInfo device) @@ -500,4 +499,22 @@ namespace BlackSound // I cannot delete the file here, only after it has been played if (removeFileAfterPlaying) BlackMisc::CFileDeleter::addFileForDeletion(file); } + + void CSoundGenerator::printAllQtSoundDevices() + { + qDebug() << "output"; + foreach(QAudioDeviceInfo qd, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) + { + qDebug() << qd.deviceName(); + } + + qDebug() << "input"; + foreach(QAudioDeviceInfo qd, QAudioDeviceInfo::availableDevices(QAudio::AudioInput)) + { + qDebug() << qd.deviceName(); + } + + + } + } // namespace diff --git a/src/blacksound/soundgenerator.h b/src/blacksound/soundgenerator.h index e28e04bd9..4a63c55c2 100644 --- a/src/blacksound/soundgenerator.h +++ b/src/blacksound/soundgenerator.h @@ -190,6 +190,9 @@ namespace BlackSound */ static void playNotificationSound(qint32 volume, CNotificationSounds::Notification notification); + //! For debugging purposes + void static printAllQtSoundDevices(); + signals: /*! * \brief Device was closed