diff --git a/src/blacksound/soundgenerator.cpp b/src/blacksound/soundgenerator.cpp index eb5b53114..1ae6d6a30 100644 --- a/src/blacksound/soundgenerator.cpp +++ b/src/blacksound/soundgenerator.cpp @@ -44,7 +44,7 @@ namespace BlackSound void CSoundGenerator::stop(bool destructor) { - this->m_audioOutput->setVolume(0); + // this->m_audioOutput->setVolume(0); // Bug or feature, killing the applicaions volume? this->m_audioOutput->stop(); if (this->isOpen()) { @@ -234,34 +234,36 @@ namespace BlackSound } - void CSoundGenerator::playSignal(qint32 volume, const QList &tones, QAudioDeviceInfo device) + CSoundGenerator *CSoundGenerator::playSignal(qint32 volume, const QList &tones, QAudioDeviceInfo device) { - if (tones.isEmpty()) return; // that was easy - if (volume < 1) return; CSoundGenerator *generator = new CSoundGenerator(device, CSoundGenerator::defaultAudioFormat(), tones, CSoundGenerator::SingleWithAutomaticDeletion); - if (generator->singleCyleDurationMs() < 10) return; // unable to hear + if (tones.isEmpty()) return generator; // that was easy + if (volume < 1) return generator; + if (generator->singleCyleDurationMs() < 10) return generator; // unable to hear // top and clean uo when done generator->start(volume); + return generator; } - void CSoundGenerator::playSelcal(qint32 volume, const BlackMisc::Aviation::CSelcal &selcal, QAudioDeviceInfo device) + CSoundGenerator *CSoundGenerator::playSelcal(qint32 volume, const BlackMisc::Aviation::CSelcal &selcal, QAudioDeviceInfo device) { - if (volume < 1) return; - if (!selcal.isValid()) return; - QList frequencies = selcal.getFrequencies(); - Q_ASSERT(frequencies.size() == 4); - Tone t1(frequencies.at(0).value(CFrequencyUnit::Hz()), frequencies.at(1).value(CFrequencyUnit::Hz()), 1000); - Tone t2(0, 200); - Tone t3(frequencies.at(2).value(CFrequencyUnit::Hz()), frequencies.at(3).value(CFrequencyUnit::Hz()), 1000); QList tones; - tones << t1 << t2 << t3; - CSoundGenerator::playSignal(volume, tones, device); + if (selcal.isValid()) + { + QList frequencies = selcal.getFrequencies(); + Q_ASSERT(frequencies.size() == 4); + Tone t1(frequencies.at(0).value(CFrequencyUnit::Hz()), frequencies.at(1).value(CFrequencyUnit::Hz()), 1000); + Tone t2(0, 200); + Tone t3(frequencies.at(2).value(CFrequencyUnit::Hz()), frequencies.at(3).value(CFrequencyUnit::Hz()), 1000); + tones << t1 << t2 << t3; + } + return CSoundGenerator::playSignal(volume, tones, device); } - void CSoundGenerator::playSelcal(qint32 volume, const CSelcal &selcal, const CAudioDevice &audioDevice) + CSoundGenerator *CSoundGenerator::playSelcal(qint32 volume, const CSelcal &selcal, const CAudioDevice &audioDevice) { - CSoundGenerator::playSelcal(volume, selcal, CSoundGenerator::findClosestOutputDevice(audioDevice)); + return CSoundGenerator::playSelcal(volume, selcal, CSoundGenerator::findClosestOutputDevice(audioDevice)); } } // namespace diff --git a/src/blacksound/soundgenerator.h b/src/blacksound/soundgenerator.h index 8f04308ad..c197e5f71 100644 --- a/src/blacksound/soundgenerator.h +++ b/src/blacksound/soundgenerator.h @@ -76,11 +76,28 @@ namespace BlackSound */ CSoundGenerator(const QList &tones, PlayMode mode, QObject *parent = nullptr); + /*! + * \brief Constructor for dummy device + * \param device + * \param format + * \param parent + */ + CSoundGenerator(const QAudioDeviceInfo &device, const QAudioFormat &format, QObject *parent); + /*! * Destructor */ ~CSoundGenerator(); + /*! + * \brief Set volume + * \param volume 0..100 + */ + void setVolume(int volume) + { + this->m_audioOutput->setVolume(qreal(volume / 100.0)); + } + /*! * \brief Close device, buffer stays intact */ @@ -141,26 +158,29 @@ namespace BlackSound * \param volume 0-100 * \param tones list of tones * \param device device to be used + * \return */ - static void playSignal(qint32 volume, const QList &tones, QAudioDeviceInfo device = QAudioDeviceInfo::defaultOutputDevice()); + static CSoundGenerator *playSignal(qint32 volume, const QList &tones, QAudioDeviceInfo device = QAudioDeviceInfo::defaultOutputDevice()); /*! * \brief Play SELCAL tone * \param volume 0-100 * \param selcal * \param device device to be used + * \return * \see BlackMisc::Aviation::CSelcal */ - static void playSelcal(qint32 volume, const BlackMisc::Aviation::CSelcal &selcal, QAudioDeviceInfo device = QAudioDeviceInfo::defaultOutputDevice()); + static CSoundGenerator *playSelcal(qint32 volume, const BlackMisc::Aviation::CSelcal &selcal, QAudioDeviceInfo device = QAudioDeviceInfo::defaultOutputDevice()); /*! * \brief Play SELCAL tone * \param volume 0-100 * \param selcal * \param audioDevice device to be used + * \return * \see BlackMisc::Aviation::CSelcal */ - static void playSelcal(qint32 volume, const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::Voice::CAudioDevice &audioDevice); + static CSoundGenerator *playSelcal(qint32 volume, const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::Voice::CAudioDevice &audioDevice); /*! * \brief One cycle of tones takes t milliseconds @@ -193,7 +213,7 @@ namespace BlackSound private: QList m_tones; /*! tones to be played */ qint64 m_position; /*!< position in buffer */ - bool m_playMode; /*!< end data provisioning after playing all tones, play endless loop */ + PlayMode m_playMode; /*!< end data provisioning after playing all tones, play endless loop */ bool m_endReached; /*!< indicates end in combination with single play */ qint64 m_oneCycleDurationMs; /*!< how long is one cycle of tones */ QByteArray m_buffer; /*!< generated buffer for data */