diff --git a/src/blackcore/afv/audio/receiversampleprovider.cpp b/src/blackcore/afv/audio/receiversampleprovider.cpp index dcf955a34..8439a70b6 100644 --- a/src/blackcore/afv/audio/receiversampleprovider.cpp +++ b/src/blackcore/afv/audio/receiversampleprovider.cpp @@ -36,9 +36,9 @@ namespace BlackCore m_mixer->addMixerInput(voiceInput); } - // TODO blockTone = new SignalGenerator(WaveFormat.SampleRate, 1) { Gain = 0, Type = SignalGeneratorType.Sin, Frequency = 180 }; - // TODO mixer.AddMixerInput(blockTone.ToMono()); - // TODO volume = new VolumeSampleProvider(mixer); + m_blockTone = new CSinusGenerator(180, this); + m_mixer->addMixerInput(m_blockTone); + m_volume = new CVolumeSampleProvider(m_mixer); } void CReceiverSampleProvider::setBypassEffects(bool value) @@ -88,12 +88,12 @@ namespace BlackCore if (numberOfInUseInputs > 1) { -// blockTone.Frequency = 180; -// blockTone.Gain = blockToneGain; + m_blockTone->setFrequency(180.0); + m_blockTone->setGain(m_blockToneGain); } else { -// blockTone.Gain = 0; + m_blockTone->setGain(0.0); } if (m_doClickWhenAppropriate && numberOfInUseInputs == 0) @@ -127,8 +127,7 @@ namespace BlackCore } m_lastNumberOfInUseInputs = numberOfInUseInputs; -// return volume.Read(buffer, offset, count); - return m_mixer->readSamples(samples, count); + return m_volume->readSamples(samples, count); } void CReceiverSampleProvider::addOpusSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio) diff --git a/src/blackcore/afv/audio/receiversampleprovider.h b/src/blackcore/afv/audio/receiversampleprovider.h index 7a3e737d5..61c03d34f 100644 --- a/src/blackcore/afv/audio/receiversampleprovider.h +++ b/src/blackcore/afv/audio/receiversampleprovider.h @@ -14,6 +14,8 @@ #include "blackcore/afv/audio/callsignsampleprovider.h" #include "blacksound/sampleprovider/sampleprovider.h" #include "blacksound/sampleprovider/mixingsampleprovider.h" +#include "blacksound/sampleprovider/sinusgenerator.h" +#include "blacksound/sampleprovider/volumesampleprovider.h" #include "blackmisc/aviation/callsignset.h" #include "blackmisc/audio/audiosettings.h" @@ -89,9 +91,9 @@ namespace BlackCore quint16 m_id; BlackMisc::CSettingReadOnly m_audioSettings { this }; - // TODO VolumeSampleProvider volume; + BlackSound::SampleProvider::CVolumeSampleProvider *m_volume = nullptr; BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr; - // TODO SignalGenerator blockTone; + BlackSound::SampleProvider::CSinusGenerator *m_blockTone = nullptr; QVector m_voiceInputs; QString m_receivingCallsignsString; diff --git a/src/blacksound/sampleprovider/sinusgenerator.cpp b/src/blacksound/sampleprovider/sinusgenerator.cpp new file mode 100644 index 000000000..d7d1f7ff8 --- /dev/null +++ b/src/blacksound/sampleprovider/sinusgenerator.cpp @@ -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 + +namespace BlackSound +{ + namespace SampleProvider + { + CSinusGenerator::CSinusGenerator(double frequency, QObject *parent) : + ISampleProvider(parent), + m_frequency(frequency) + {} + + int CSinusGenerator::readSamples(QVector &samples, qint64 count) + { + samples.clear(); + samples.fill(0, static_cast(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(sampleValue); + m_nSample++; + } + return static_cast(count); + } + + void CSinusGenerator::setFrequency(double frequency) + { + m_frequency = frequency; + } + } // ns +} // ns diff --git a/src/blacksound/sampleprovider/sinusgenerator.h b/src/blacksound/sampleprovider/sinusgenerator.h new file mode 100644 index 000000000..1a398a579 --- /dev/null +++ b/src/blacksound/sampleprovider/sinusgenerator.h @@ -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 + +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 &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