Return values for the static sound generator methods.

Fixed playMode attribute, method to set volume
This commit is contained in:
Klaus Basan
2014-02-03 18:56:25 +01:00
committed by Mathew Sutcliffe
parent ffb09c0d4a
commit 395603f932
2 changed files with 43 additions and 21 deletions

View File

@@ -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<CSoundGenerator::Tone> &tones, QAudioDeviceInfo device)
CSoundGenerator *CSoundGenerator::playSignal(qint32 volume, const QList<CSoundGenerator::Tone> &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<CFrequency> 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<CSoundGenerator::Tone> tones;
tones << t1 << t2 << t3;
CSoundGenerator::playSignal(volume, tones, device);
if (selcal.isValid())
{
QList<CFrequency> 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

View File

@@ -76,11 +76,28 @@ namespace BlackSound
*/
CSoundGenerator(const QList<Tone> &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<Tone> &tones, QAudioDeviceInfo device = QAudioDeviceInfo::defaultOutputDevice());
static CSoundGenerator *playSignal(qint32 volume, const QList<Tone> &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<Tone> 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 */