mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 15:45:42 +08:00
Sound generator: allow periods of silence between tones
This commit is contained in:
committed by
Mathew Sutcliffe
parent
489de7642b
commit
7b0dff1af5
@@ -4,6 +4,9 @@
|
|||||||
#include <qendian.h>
|
#include <qendian.h>
|
||||||
#include <QAudioOutput>
|
#include <QAudioOutput>
|
||||||
|
|
||||||
|
using namespace BlackMisc::Aviation;
|
||||||
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
|
|
||||||
namespace BlackSound
|
namespace BlackSound
|
||||||
{
|
{
|
||||||
CSoundGenerator::CSoundGenerator(const QAudioFormat &format, const QList<Tone> &tones, bool singlePlay, QObject *parent)
|
CSoundGenerator::CSoundGenerator(const QAudioFormat &format, const QList<Tone> &tones, bool singlePlay, QObject *parent)
|
||||||
@@ -66,10 +69,15 @@ namespace BlackSound
|
|||||||
// http://hyperphysics.phy-astr.gsu.edu/hbase/audio/sumdif.html
|
// http://hyperphysics.phy-astr.gsu.edu/hbase/audio/sumdif.html
|
||||||
// http://math.stackexchange.com/questions/164369/how-do-you-calculate-the-frequency-perceived-by-humans-of-two-sinusoidal-waves-a
|
// http://math.stackexchange.com/questions/164369/how-do-you-calculate-the-frequency-perceived-by-humans-of-two-sinusoidal-waves-a
|
||||||
const double pseudoTime = double(sampleIndexPerTone % format.sampleRate()) / format.sampleRate();
|
const double pseudoTime = double(sampleIndexPerTone % format.sampleRate()) / format.sampleRate();
|
||||||
const double amplitude = t.m_secondaryFrequencyHz == 0 ?
|
double amplitude = 0; // silence
|
||||||
qSin(2 * M_PI * t.m_frequencyHz * pseudoTime) :
|
if (t.m_frequencyHz > 10)
|
||||||
qSin(M_PI * (t.m_frequencyHz + t.m_secondaryFrequencyHz) * pseudoTime) *
|
{
|
||||||
qCos(M_PI * (t.m_frequencyHz - t.m_secondaryFrequencyHz) * pseudoTime);
|
amplitude = t.m_secondaryFrequencyHz == 0 ?
|
||||||
|
qSin(2 * M_PI * t.m_frequencyHz * pseudoTime) :
|
||||||
|
qSin(M_PI * (t.m_frequencyHz + t.m_secondaryFrequencyHz) * pseudoTime) *
|
||||||
|
qCos(M_PI * (t.m_frequencyHz - t.m_secondaryFrequencyHz) * pseudoTime);
|
||||||
|
}
|
||||||
|
|
||||||
// the combination of two frequencies actually would have 2*amplitude,
|
// the combination of two frequencies actually would have 2*amplitude,
|
||||||
// but I have to normalize with amplitude -1 -> +1
|
// but I have to normalize with amplitude -1 -> +1
|
||||||
|
|
||||||
@@ -186,4 +194,18 @@ namespace BlackSound
|
|||||||
audioOutput->start(generator);
|
audioOutput->start(generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void 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);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user