mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
[AFV] Finalize blocking tone
Blocking tone is emitted if more than one station is received in parallel.
This commit is contained in:
committed by
Mat Sutcliffe
parent
ec0a20b1d1
commit
b8661918d7
41
src/blacksound/sampleprovider/sinusgenerator.cpp
Normal file
41
src/blacksound/sampleprovider/sinusgenerator.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/* Copyright (C) 2019
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "sinusgenerator.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace BlackSound
|
||||
{
|
||||
namespace SampleProvider
|
||||
{
|
||||
CSinusGenerator::CSinusGenerator(double frequency, QObject *parent) :
|
||||
ISampleProvider(parent),
|
||||
m_frequency(frequency)
|
||||
{}
|
||||
|
||||
int CSinusGenerator::readSamples(QVector<float> &samples, qint64 count)
|
||||
{
|
||||
samples.clear();
|
||||
samples.fill(0, static_cast<int>(count));
|
||||
|
||||
for (int sampleCount = 0; sampleCount < count; sampleCount++)
|
||||
{
|
||||
double multiple = m_twoPi * m_frequency / m_sampleRate;
|
||||
double sampleValue = m_gain * qSin(m_nSample * multiple);
|
||||
samples[sampleCount] = static_cast<float>(sampleValue);
|
||||
m_nSample++;
|
||||
}
|
||||
return static_cast<int>(count);
|
||||
}
|
||||
|
||||
void CSinusGenerator::setFrequency(double frequency)
|
||||
{
|
||||
m_frequency = frequency;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
51
src/blacksound/sampleprovider/sinusgenerator.h
Normal file
51
src/blacksound/sampleprovider/sinusgenerator.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* Copyright (C) 2019
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKSOUND_SAMPLEPROVIDER_SINUSGENERATOR_H
|
||||
#define BLACKSOUND_SAMPLEPROVIDER_SINUSGENERATOR_H
|
||||
|
||||
#include "blacksound/blacksoundexport.h"
|
||||
#include "blacksound/sampleprovider/sampleprovider.h"
|
||||
|
||||
#include <QtMath>
|
||||
|
||||
namespace BlackSound
|
||||
{
|
||||
namespace SampleProvider
|
||||
{
|
||||
//! Saw tooth generator
|
||||
class BLACKSOUND_EXPORT CSinusGenerator : public ISampleProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Ctor
|
||||
CSinusGenerator(double frequency, QObject *parent = nullptr);
|
||||
|
||||
//! \copydoc ISampleProvider::readSamples
|
||||
virtual int readSamples(QVector<float> &samples, qint64 count) override;
|
||||
|
||||
//! Set the gain
|
||||
void setGain(double gain) { m_gain = gain; }
|
||||
|
||||
//! Set frequency in Hz
|
||||
void setFrequency(double frequency);
|
||||
|
||||
private:
|
||||
double m_gain = 0.0;
|
||||
double m_frequency = 0.0;
|
||||
double m_sampleRate = 48000;
|
||||
int m_nSample = 0;
|
||||
const double m_twoPi = 2 * M_PI;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user