From 99edc9cb1398b5de06080282957dffcaa75d7e5e Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 21 Sep 2019 03:29:58 +0200 Subject: [PATCH] Ref T730, code style, adding namespaces --- samples/afvclient/main.cpp | 2 +- .../afv/audio/callsignsampleprovider.cpp | 21 +- .../afv/audio/callsignsampleprovider.h | 29 +- src/blackcore/afv/audio/input.cpp | 32 +-- src/blackcore/afv/audio/input.h | 21 +- src/blackcore/afv/audio/output.cpp | 20 +- src/blackcore/afv/audio/output.h | 11 +- .../afv/audio/receiversampleprovider.cpp | 32 +-- .../afv/audio/receiversampleprovider.h | 7 +- .../afv/audio/soundcardsampleprovider.cpp | 40 +-- .../afv/audio/soundcardsampleprovider.h | 8 +- src/blackcore/afv/clients/afvclient.cpp | 85 +++--- src/blackcore/afv/clients/afvclient.h | 16 +- .../afv/connection/clientconnection.cpp | 32 +-- .../afv/connection/clientconnection.h | 6 +- .../afv/connection/clientconnectiondata.cpp | 10 +- .../afv/connection/clientconnectiondata.h | 6 +- src/blackcore/afv/crypto/cryptodtochannel.cpp | 18 +- src/blackcore/afv/crypto/cryptodtochannel.h | 6 +- .../afv/crypto/cryptodtoserializer.cpp | 4 +- .../afv/crypto/cryptodtoserializer.h | 8 +- src/blackcore/afv/dto.h | 62 +++-- src/blackcore/context/contextaudioimpl.h | 2 +- src/blacksound/codecs/opusdecoder.h | 4 +- .../sampleprovider/bufferedwaveprovider.cpp | 58 ++-- .../sampleprovider/bufferedwaveprovider.h | 44 ++- .../equalizersampleprovider.cpp | 88 +++--- .../sampleprovider/equalizersampleprovider.h | 63 +++-- .../sampleprovider/mixingsampleprovider.cpp | 66 +++-- .../sampleprovider/mixingsampleprovider.h | 34 ++- .../sampleprovider/pinknoisegenerator.cpp | 40 +-- .../sampleprovider/pinknoisegenerator.h | 32 ++- .../sampleprovider/resourcesound.cpp | 49 ++-- src/blacksound/sampleprovider/resourcesound.h | 40 ++- .../resourcesoundsampleprovider.cpp | 140 +++++----- .../resourcesoundsampleprovider.h | 62 +++-- .../sampleprovider/sampleprovider.h | 35 ++- src/blacksound/sampleprovider/samples.cpp | 54 ++-- src/blacksound/sampleprovider/samples.h | 40 ++- .../sampleprovider/sawtoothgenerator.cpp | 46 ++-- .../sampleprovider/sawtoothgenerator.h | 49 ++-- .../sampleprovider/simplecompressoreffect.cpp | 86 +++--- .../sampleprovider/simplecompressoreffect.h | 50 ++-- .../sampleprovider/volumesampleprovider.cpp | 41 ++- .../sampleprovider/volumesampleprovider.h | 36 +-- src/blacksound/wav/wavfile.cpp | 252 +++++++++--------- src/blacksound/wav/wavfile.h | 50 ++-- 47 files changed, 1136 insertions(+), 801 deletions(-) diff --git a/samples/afvclient/main.cpp b/samples/afvclient/main.cpp index e18fbdedd..3ef628d60 100644 --- a/samples/afvclient/main.cpp +++ b/samples/afvclient/main.cpp @@ -23,7 +23,7 @@ int main(int argc, char *argv[]) AFVMapReader *afvMapReader = new AFVMapReader(&a); afvMapReader->updateFromMap(); - AFVClient voiceClient("https://voice1.vatsim.uk"); + CAfvClient voiceClient("https://voice1.vatsim.uk"); QQmlApplicationEngine engine; QQmlContext *ctxt = engine.rootContext(); diff --git a/src/blackcore/afv/audio/callsignsampleprovider.cpp b/src/blackcore/afv/audio/callsignsampleprovider.cpp index 7468f56d4..70def1e54 100644 --- a/src/blackcore/afv/audio/callsignsampleprovider.cpp +++ b/src/blackcore/afv/audio/callsignsampleprovider.cpp @@ -14,6 +14,8 @@ #include #include +using namespace BlackSound::SampleProvider; + namespace BlackCore { namespace Afv @@ -27,22 +29,22 @@ namespace BlackCore { Q_ASSERT(audioFormat.channelCount() == 1); - mixer = new MixingSampleProvider(this); - crackleSoundProvider = new ResourceSoundSampleProvider(Samples::instance().crackle(), mixer); + mixer = new CMixingSampleProvider(this); + crackleSoundProvider = new CResourceSoundSampleProvider(Samples::instance().crackle(), mixer); crackleSoundProvider->setLooping(true); crackleSoundProvider->setGain(0.0); - whiteNoise = new ResourceSoundSampleProvider(Samples::instance().whiteNoise(), mixer); + whiteNoise = new CResourceSoundSampleProvider(Samples::instance().whiteNoise(), mixer); whiteNoise->setLooping(true); whiteNoise->setGain(0.0); - acBusNoise = new SawToothGenerator(400, mixer); - audioInput = new BufferedWaveProvider(audioFormat, mixer); + acBusNoise = new CSawToothGenerator(400, mixer); + audioInput = new CBufferedWaveProvider(audioFormat, mixer); // Create the compressor - simpleCompressorEffect = new SimpleCompressorEffect(audioInput, mixer); + simpleCompressorEffect = new CSimpleCompressorEffect(audioInput, mixer); simpleCompressorEffect->setMakeUpGain(-5.5); // Create the voice EQ - voiceEq = new EqualizerSampleProvider(simpleCompressorEffect, EqualizerPresets::VHFEmulation, mixer); + voiceEq = new CEqualizerSampleProvider(simpleCompressorEffect, EqualizerPresets::VHFEmulation, mixer); mixer->addMixerInput(whiteNoise); mixer->addMixerInput(acBusNoise); @@ -80,10 +82,7 @@ namespace BlackCore } } - QString CallsignSampleProvider::type() const - { - return m_type; - } + void CallsignSampleProvider::active(const QString &callsign, const QString &aircraftType) { diff --git a/src/blackcore/afv/audio/callsignsampleprovider.h b/src/blackcore/afv/audio/callsignsampleprovider.h index a3e6fec9b..8271a7d3d 100644 --- a/src/blackcore/afv/audio/callsignsampleprovider.h +++ b/src/blackcore/afv/audio/callsignsampleprovider.h @@ -8,8 +8,8 @@ //! \file -#ifndef CALLSIGNSAMPLEPROVIDER_H -#define CALLSIGNSAMPLEPROVIDER_H +#ifndef BLACKCORE_AFV_AUDIO_CALLSIGNSAMPLEPROVIDER_H +#define BLACKCORE_AFV_AUDIO_CALLSIGNSAMPLEPROVIDER_H #include "blackcore/afv/dto.h" #include "blacksound/sampleprovider/pinknoisegenerator.h" @@ -34,19 +34,20 @@ namespace BlackCore namespace Audio { //! Callsign provide - class CallsignSampleProvider : public ISampleProvider + class CallsignSampleProvider : public BlackSound::SampleProvider::ISampleProvider { Q_OBJECT public: + //! Ctor CallsignSampleProvider(const QAudioFormat &audioFormat, QObject *parent = nullptr); int readSamples(QVector &samples, qint64 count) override; //! The callsign - const QString callsign() const { return m_callsign; } + const QString &callsign() const { return m_callsign; } - QString type() const; + const QString &type() const { return m_type; } void active(const QString &callsign, const QString &aircraftType); void activeSilent(const QString &callsign, const QString &aircraftType); @@ -69,8 +70,8 @@ namespace BlackCore QAudioFormat m_audioFormat; const double whiteNoiseGainMin = 0.15; //0.01; - const double acBusGainMin = 0.003; //0.002; - const int frameCount = 960; + const double acBusGainMin = 0.003; //0.002; + const int frameCount = 960; const int idleTimeoutMs = 500; QString m_callsign; @@ -81,13 +82,13 @@ namespace BlackCore float m_distanceRatio = 1.0; - MixingSampleProvider *mixer; - ResourceSoundSampleProvider *crackleSoundProvider; - ResourceSoundSampleProvider *whiteNoise; - SawToothGenerator *acBusNoise; - SimpleCompressorEffect *simpleCompressorEffect; - EqualizerSampleProvider *voiceEq; - BufferedWaveProvider *audioInput; + BlackSound::SampleProvider::CMixingSampleProvider *mixer = nullptr; + BlackSound::SampleProvider::CResourceSoundSampleProvider *crackleSoundProvider = nullptr; + BlackSound::SampleProvider::CResourceSoundSampleProvider *whiteNoise = nullptr; + BlackSound::SampleProvider::CSawToothGenerator *acBusNoise = nullptr; + BlackSound::SampleProvider::CSimpleCompressorEffect *simpleCompressorEffect = nullptr; + BlackSound::SampleProvider::CEqualizerSampleProvider *voiceEq = nullptr; + BlackSound::SampleProvider::CBufferedWaveProvider *audioInput = nullptr; QTimer m_timer; BlackSound::Codecs::COpusDecoder m_decoder; diff --git a/src/blackcore/afv/audio/input.cpp b/src/blackcore/afv/audio/input.cpp index 8c08a23c1..215327fef 100644 --- a/src/blackcore/afv/audio/input.cpp +++ b/src/blackcore/afv/audio/input.cpp @@ -21,17 +21,17 @@ namespace BlackCore { namespace Audio { - AudioInputBuffer::AudioInputBuffer(QObject *parent) : + CAudioInputBuffer::CAudioInputBuffer(QObject *parent) : QIODevice(parent) {} - void AudioInputBuffer::start() + void CAudioInputBuffer::start() { open(QIODevice::WriteOnly | QIODevice::Unbuffered); m_timerId = startTimer(20, Qt::PreciseTimer); } - void AudioInputBuffer::stop() + void CAudioInputBuffer::stop() { if (m_timerId > 0) { @@ -41,7 +41,7 @@ namespace BlackCore close(); } - qint64 AudioInputBuffer::readData(char *data, qint64 maxlen) + qint64 CAudioInputBuffer::readData(char *data, qint64 maxlen) { Q_UNUSED(data) Q_UNUSED(maxlen) @@ -49,14 +49,14 @@ namespace BlackCore return 0; } - qint64 AudioInputBuffer::writeData(const char *data, qint64 len) + qint64 CAudioInputBuffer::writeData(const char *data, qint64 len) { QByteArray buffer(data, static_cast(len)); m_buffer.append(buffer); return len; } - void AudioInputBuffer::timerEvent(QTimerEvent *event) + void CAudioInputBuffer::timerEvent(QTimerEvent *event) { Q_UNUSED(event); // 20 ms = 960 samples * 2 bytes = 1920 Bytes @@ -67,7 +67,7 @@ namespace BlackCore } } - Input::Input(int sampleRate, QObject *parent) : + CInput::CInput(int sampleRate, QObject *parent) : QObject(parent), m_sampleRate(sampleRate), m_encoder(sampleRate, 1, OPUS_APPLICATION_VOIP) @@ -75,32 +75,32 @@ namespace BlackCore m_encoder.setBitRate(16 * 1024); } - bool Input::started() const + bool CInput::started() const { return m_started; } - int Input::opusBytesEncoded() const + int CInput::opusBytesEncoded() const { return m_opusBytesEncoded; } - void Input::setOpusBytesEncoded(int opusBytesEncoded) + void CInput::setOpusBytesEncoded(int opusBytesEncoded) { m_opusBytesEncoded = opusBytesEncoded; } - double Input::volume() const + double CInput::volume() const { return m_volume; } - void Input::setVolume(double volume) + void CInput::setVolume(double volume) { m_volume = volume; } - void Input::start(const QAudioDeviceInfo &inputDevice) + void CInput::start(const QAudioDeviceInfo &inputDevice) { if (m_started) { return; } @@ -124,12 +124,12 @@ namespace BlackCore m_audioInputBuffer.start(); m_audioInput->start(&m_audioInputBuffer); - connect(&m_audioInputBuffer, &AudioInputBuffer::frameAvailable, this, &Input::audioInDataAvailable); + connect(&m_audioInputBuffer, &CAudioInputBuffer::frameAvailable, this, &CInput::audioInDataAvailable); m_started = true; } - void Input::stop() + void CInput::stop() { if (! m_started) { return; } @@ -139,7 +139,7 @@ namespace BlackCore m_audioInput.reset(); } - void Input::audioInDataAvailable(const QByteArray &frame) + void CInput::audioInDataAvailable(const QByteArray &frame) { QVector samples = convertBytesTo16BitPCM(frame); diff --git a/src/blackcore/afv/audio/input.h b/src/blackcore/afv/audio/input.h index 792017a16..712ae8c9b 100644 --- a/src/blackcore/afv/audio/input.h +++ b/src/blackcore/afv/audio/input.h @@ -27,20 +27,25 @@ namespace BlackCore namespace Audio { //! Input buffer - class AudioInputBuffer : public QIODevice + class CAudioInputBuffer : public QIODevice { Q_OBJECT public: - AudioInputBuffer(QObject *parent = nullptr); + //! Inout buffer + CAudioInputBuffer(QObject *parent = nullptr); void start(); void stop(); - qint64 readData(char *data, qint64 maxlen) override; - qint64 writeData(const char *data, qint64 len) override; + //! \copydoc QIODevice::readData + virtual qint64 readData(char *data, qint64 maxlen) override; + + //! \copydoc QIODevice::writeData + virtual qint64 writeData(const char *data, qint64 len) override; signals: + //! Frame is available void frameAvailable(const QByteArray &frame); protected: @@ -66,12 +71,14 @@ namespace BlackCore float PeakVU = 0.0; }; - class Input : public QObject + //! Input + class CInput : public QObject { Q_OBJECT public: - Input(int sampleRate, QObject *parent = nullptr); + //! Ctor + CInput(int sampleRate, QObject *parent = nullptr); bool started() const; @@ -109,7 +116,7 @@ namespace BlackCore uint m_audioSequenceCounter = 0; - AudioInputBuffer m_audioInputBuffer; + CAudioInputBuffer m_audioInputBuffer; }; } // ns } // ns diff --git a/src/blackcore/afv/audio/output.cpp b/src/blackcore/afv/audio/output.cpp index ecd2a58c7..04a972d71 100644 --- a/src/blackcore/afv/audio/output.cpp +++ b/src/blackcore/afv/audio/output.cpp @@ -13,22 +13,24 @@ #include #include +using namespace BlackSound::SampleProvider; + namespace BlackCore { namespace Afv { namespace Audio { - AudioOutputBuffer::AudioOutputBuffer(ISampleProvider *sampleProvider, QObject *parent) : + CAudioOutputBuffer::CAudioOutputBuffer(ISampleProvider *sampleProvider, QObject *parent) : QIODevice(parent), m_sampleProvider(sampleProvider) { } - qint64 AudioOutputBuffer::readData(char *data, qint64 maxlen) + qint64 CAudioOutputBuffer::readData(char *data, qint64 maxlen) { - int sampleBytes = m_outputFormat.sampleSize() / 8; + int sampleBytes = m_outputFormat.sampleSize() / 8; int channelCount = m_outputFormat.channelCount(); - int count = maxlen / (sampleBytes * channelCount); + qint64 count = maxlen / (sampleBytes * channelCount); QVector buffer; m_sampleProvider->readSamples(buffer, count); @@ -63,10 +65,10 @@ namespace BlackCore return maxlen; } - qint64 AudioOutputBuffer::writeData(const char *data, qint64 len) + qint64 CAudioOutputBuffer::writeData(const char *data, qint64 len) { - Q_UNUSED(data); - Q_UNUSED(len); + Q_UNUSED(data) + Q_UNUSED(len) return -1; } @@ -75,8 +77,8 @@ namespace BlackCore void Output::start(const QAudioDeviceInfo &device, ISampleProvider *sampleProvider) { - m_audioOutputBuffer = new AudioOutputBuffer(sampleProvider, this); - connect(m_audioOutputBuffer, &AudioOutputBuffer::outputVolumeStream, this, &Output::outputVolumeStream); + m_audioOutputBuffer = new CAudioOutputBuffer(sampleProvider, this); + connect(m_audioOutputBuffer, &CAudioOutputBuffer::outputVolumeStream, this, &Output::outputVolumeStream); QAudioFormat outputFormat; outputFormat.setSampleRate(48000); diff --git a/src/blackcore/afv/audio/output.h b/src/blackcore/afv/audio/output.h index 8c160f2a3..cd6a7cb9d 100644 --- a/src/blackcore/afv/audio/output.h +++ b/src/blackcore/afv/audio/output.h @@ -32,14 +32,15 @@ namespace BlackCore float PeakVU = 0.0; }; - class AudioOutputBuffer : public QIODevice + class CAudioOutputBuffer : public QIODevice { Q_OBJECT public: - AudioOutputBuffer(ISampleProvider *sampleProvider, QObject *parent = nullptr); + //! Ctor + CAudioOutputBuffer(BlackSound::SampleProvider::ISampleProvider *sampleProvider, QObject *parent = nullptr); - ISampleProvider *m_sampleProvider = nullptr; + BlackSound::SampleProvider::ISampleProvider *m_sampleProvider = nullptr; void setAudioFormat(const QAudioFormat &format) { m_outputFormat = format; } @@ -66,7 +67,7 @@ namespace BlackCore public: Output(QObject *parent = nullptr); - void start(const QAudioDeviceInfo &device, ISampleProvider *sampleProvider); + void start(const QAudioDeviceInfo &device, BlackSound::SampleProvider::ISampleProvider *sampleProvider); void stop(); signals: @@ -76,7 +77,7 @@ namespace BlackCore bool m_started = false; QScopedPointer m_audioOutputCom1; - AudioOutputBuffer *m_audioOutputBuffer; + CAudioOutputBuffer *m_audioOutputBuffer; }; } // ns } // ns diff --git a/src/blackcore/afv/audio/receiversampleprovider.cpp b/src/blackcore/afv/audio/receiversampleprovider.cpp index 5b061ab78..93d8b2717 100644 --- a/src/blackcore/afv/audio/receiversampleprovider.cpp +++ b/src/blackcore/afv/audio/receiversampleprovider.cpp @@ -14,31 +14,33 @@ #include +using namespace BlackSound::SampleProvider; + namespace BlackCore { namespace Afv { namespace Audio { - ReceiverSampleProvider::ReceiverSampleProvider(const QAudioFormat &audioFormat, quint16 id, int voiceInputNumber, QObject *parent) : + CReceiverSampleProvider::CReceiverSampleProvider(const QAudioFormat &audioFormat, quint16 id, int voiceInputNumber, QObject *parent) : ISampleProvider(parent), m_id(id) { - m_mixer = new MixingSampleProvider(this); + m_mixer = new CMixingSampleProvider(this); for (int i = 0; i < voiceInputNumber; i++) { auto voiceInput = new CallsignSampleProvider(audioFormat, m_mixer); m_voiceInputs.push_back(voiceInput); 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); } - void ReceiverSampleProvider::setBypassEffects(bool value) + void CReceiverSampleProvider::setBypassEffects(bool value) { for (CallsignSampleProvider *voiceInput : m_voiceInputs) { @@ -46,7 +48,7 @@ namespace BlackCore } } - void ReceiverSampleProvider::setFrequency(const uint &frequency) + void CReceiverSampleProvider::setFrequency(const uint &frequency) { if (frequency != m_frequency) { @@ -58,26 +60,26 @@ namespace BlackCore m_frequency = frequency; } - int ReceiverSampleProvider::activeCallsigns() const + int CReceiverSampleProvider::activeCallsigns() const { - int numberOfCallsigns = std::count_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CallsignSampleProvider * p) + const int numberOfCallsigns = std::count_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CallsignSampleProvider * p) { return p->inUse() == true; }); return numberOfCallsigns; } - float ReceiverSampleProvider::volume() const + float CReceiverSampleProvider::volume() const { return 1.0; } - bool ReceiverSampleProvider::getMute() const + bool CReceiverSampleProvider::getMute() const { return m_mute; } - void ReceiverSampleProvider::setMute(bool value) + void CReceiverSampleProvider::setMute(bool value) { m_mute = value; if (value) @@ -89,7 +91,7 @@ namespace BlackCore } } - int ReceiverSampleProvider::readSamples(QVector &samples, qint64 count) + int CReceiverSampleProvider::readSamples(QVector &samples, qint64 count) { int numberOfInUseInputs = activeCallsigns(); @@ -105,7 +107,7 @@ namespace BlackCore if (m_doClickWhenAppropriate && numberOfInUseInputs == 0) { - ResourceSoundSampleProvider *resourceSound = new ResourceSoundSampleProvider(Samples::instance().click(), m_mixer); + CResourceSoundSampleProvider *resourceSound = new CResourceSoundSampleProvider(Samples::instance().click(), m_mixer); m_mixer->addMixerInput(resourceSound); qDebug() << "Click..."; m_doClickWhenAppropriate = false; @@ -133,7 +135,7 @@ namespace BlackCore return m_mixer->readSamples(samples, count); } - void ReceiverSampleProvider::addOpusSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio) + void CReceiverSampleProvider::addOpusSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio) { if (m_frequency != frequency) //Lag in the backend means we get the tail end of a transmission return; @@ -167,7 +169,7 @@ namespace BlackCore m_doClickWhenAppropriate = true; } - void ReceiverSampleProvider::addSilentSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio) + void CReceiverSampleProvider::addSilentSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio) { Q_UNUSED(distanceRatio); if (m_frequency != frequency) //Lag in the backend means we get the tail end of a transmission @@ -200,7 +202,7 @@ namespace BlackCore } } - QString ReceiverSampleProvider::getReceivingCallsigns() const + QString CReceiverSampleProvider::getReceivingCallsigns() const { return m_receivingCallsigns; } diff --git a/src/blackcore/afv/audio/receiversampleprovider.h b/src/blackcore/afv/audio/receiversampleprovider.h index 7dfc9fafd..d444c5561 100644 --- a/src/blackcore/afv/audio/receiversampleprovider.h +++ b/src/blackcore/afv/audio/receiversampleprovider.h @@ -31,12 +31,13 @@ namespace BlackCore }; //! A sample provider - class ReceiverSampleProvider : public ISampleProvider + class CReceiverSampleProvider : public BlackSound::SampleProvider::ISampleProvider { Q_OBJECT public: - ReceiverSampleProvider(const QAudioFormat &audioFormat, quint16 id, int voiceInputNumber, QObject *parent = nullptr); + //! Ctor + CReceiverSampleProvider(const QAudioFormat &audioFormat, quint16 id, int voiceInputNumber, QObject *parent = nullptr); void setBypassEffects(bool value); void setFrequency(const uint &frequency); @@ -67,7 +68,7 @@ namespace BlackCore quint16 m_id; // TODO VolumeSampleProvider volume; - MixingSampleProvider *m_mixer; + BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr; // TODO SignalGenerator blockTone; QVector m_voiceInputs; QString m_receivingCallsigns; diff --git a/src/blackcore/afv/audio/soundcardsampleprovider.cpp b/src/blackcore/afv/audio/soundcardsampleprovider.cpp index 92c313e60..5bdd02e32 100644 --- a/src/blackcore/afv/audio/soundcardsampleprovider.cpp +++ b/src/blackcore/afv/audio/soundcardsampleprovider.cpp @@ -10,15 +10,17 @@ #include "soundcardsampleprovider.h" +using namespace BlackSound::SampleProvider; + namespace BlackCore { namespace Afv { namespace Audio { - SoundcardSampleProvider::SoundcardSampleProvider(int sampleRate, const QVector &transceiverIDs, QObject *parent) : + CSoundcardSampleProvider::CSoundcardSampleProvider(int sampleRate, const QVector &transceiverIDs, QObject *parent) : ISampleProvider(parent), - m_mixer(new MixingSampleProvider()) + m_mixer(new CMixingSampleProvider()) { m_waveFormat.setSampleRate(sampleRate); m_waveFormat.setChannelCount(1); @@ -27,34 +29,34 @@ namespace BlackCore m_waveFormat.setByteOrder(QAudioFormat::LittleEndian); m_waveFormat.setCodec("audio/pcm"); - m_mixer = new MixingSampleProvider(this); + m_mixer = new CMixingSampleProvider(this); m_receiverIDs = transceiverIDs; for (quint16 transceiverID : transceiverIDs) { - ReceiverSampleProvider *transceiverInput = new ReceiverSampleProvider(m_waveFormat, transceiverID, 4, m_mixer); - connect(transceiverInput, &ReceiverSampleProvider::receivingCallsignsChanged, this, &SoundcardSampleProvider::receivingCallsignsChanged); + CReceiverSampleProvider *transceiverInput = new CReceiverSampleProvider(m_waveFormat, transceiverID, 4, m_mixer); + connect(transceiverInput, &CReceiverSampleProvider::receivingCallsignsChanged, this, &CSoundcardSampleProvider::receivingCallsignsChanged); m_receiverInputs.push_back(transceiverInput); m_receiverIDs.push_back(transceiverID); m_mixer->addMixerInput(transceiverInput); } } - QAudioFormat SoundcardSampleProvider::waveFormat() const + QAudioFormat CSoundcardSampleProvider::waveFormat() const { return m_waveFormat; } - void SoundcardSampleProvider::setBypassEffects(bool value) + void CSoundcardSampleProvider::setBypassEffects(bool value) { - for (ReceiverSampleProvider *receiverInput : m_receiverInputs) + for (CReceiverSampleProvider *receiverInput : m_receiverInputs) { receiverInput->setBypassEffects(value); } } - void SoundcardSampleProvider::pttUpdate(bool active, const QVector &txTransceivers) + void CSoundcardSampleProvider::pttUpdate(bool active, const QVector &txTransceivers) { if (active) { @@ -71,7 +73,7 @@ namespace BlackCore for (const TxTransceiverDto &txTransceiver : txTransceiversFiltered) { - auto it = std::find_if(m_receiverInputs.begin(), m_receiverInputs.end(), [txTransceiver](const ReceiverSampleProvider * p) + auto it = std::find_if(m_receiverInputs.begin(), m_receiverInputs.end(), [txTransceiver](const CReceiverSampleProvider * p) { return p->getId() == txTransceiver.id; }); @@ -82,19 +84,19 @@ namespace BlackCore } else { - for (ReceiverSampleProvider *receiverInput : m_receiverInputs) + for (CReceiverSampleProvider *receiverInput : m_receiverInputs) { receiverInput->setMute(false); } } } - int SoundcardSampleProvider::readSamples(QVector &samples, qint64 count) + int CSoundcardSampleProvider::readSamples(QVector &samples, qint64 count) { return m_mixer->readSamples(samples, count); } - void SoundcardSampleProvider::addOpusSamples(const IAudioDto &audioDto, const QVector &rxTransceivers) + void CSoundcardSampleProvider::addOpusSamples(const IAudioDto &audioDto, const QVector &rxTransceivers) { QVector rxTransceiversFilteredAndSorted = rxTransceivers; @@ -120,8 +122,8 @@ namespace BlackCore { handledTransceiverIDs.push_back(rxTransceiver.id); - ReceiverSampleProvider *receiverInput = nullptr; - auto it = std::find_if(m_receiverInputs.begin(), m_receiverInputs.end(), [rxTransceiver](const ReceiverSampleProvider * p) + CReceiverSampleProvider *receiverInput = nullptr; + auto it = std::find_if(m_receiverInputs.begin(), m_receiverInputs.end(), [rxTransceiver](const CReceiverSampleProvider * p) { return p->getId() == rxTransceiver.id; }); @@ -147,11 +149,11 @@ namespace BlackCore } } - void SoundcardSampleProvider::updateRadioTransceivers(const QVector &radioTransceivers) + void CSoundcardSampleProvider::updateRadioTransceivers(const QVector &radioTransceivers) { for (const TransceiverDto &radioTransceiver : radioTransceivers) { - auto it = std::find_if(m_receiverInputs.begin(), m_receiverInputs.end(), [radioTransceiver](const ReceiverSampleProvider * p) + auto it = std::find_if(m_receiverInputs.begin(), m_receiverInputs.end(), [radioTransceiver](const CReceiverSampleProvider * p) { return p->getId() == radioTransceiver.id; }); @@ -162,7 +164,7 @@ namespace BlackCore } } - for (ReceiverSampleProvider *receiverInput : m_receiverInputs) + for (CReceiverSampleProvider *receiverInput : m_receiverInputs) { quint16 transceiverID = receiverInput->getId(); bool contains = std::any_of(radioTransceivers.begin(), radioTransceivers.end(), [&](const auto & tx) { return transceiverID == tx.id; }); @@ -173,7 +175,7 @@ namespace BlackCore } } - QString SoundcardSampleProvider::getReceivingCallsigns(quint16 transceiverID) + QString CSoundcardSampleProvider::getReceivingCallsigns(quint16 transceiverID) { return m_receiverInputs.at(transceiverID)->getReceivingCallsigns(); } diff --git a/src/blackcore/afv/audio/soundcardsampleprovider.h b/src/blackcore/afv/audio/soundcardsampleprovider.h index fbad8abf3..bd5877a4d 100644 --- a/src/blackcore/afv/audio/soundcardsampleprovider.h +++ b/src/blackcore/afv/audio/soundcardsampleprovider.h @@ -25,13 +25,13 @@ namespace BlackCore namespace Audio { //! Soundcard sample - class SoundcardSampleProvider : public ISampleProvider + class CSoundcardSampleProvider : public BlackSound::SampleProvider::ISampleProvider { Q_OBJECT public: //! Ctor - SoundcardSampleProvider(int sampleRate, const QVector &transceiverIDs, QObject *parent = nullptr); + CSoundcardSampleProvider(int sampleRate, const QVector &transceiverIDs, QObject *parent = nullptr); QAudioFormat waveFormat() const; @@ -47,8 +47,8 @@ namespace BlackCore private: QAudioFormat m_waveFormat; - MixingSampleProvider *m_mixer; - QVector m_receiverInputs; + BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr; + QVector m_receiverInputs; QVector m_receiverIDs; }; diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index 5105e17b4..77c7503e1 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -14,6 +14,7 @@ using namespace BlackMisc::PhysicalQuantities; using namespace BlackCore::Context; using namespace BlackCore::Afv::Audio; using namespace BlackCore::Afv::Connection; +using namespace BlackSound::SampleProvider; namespace BlackCore { @@ -21,22 +22,22 @@ namespace BlackCore { namespace Clients { - AFVClient::AFVClient(const QString &apiServer, QObject *parent) : + CAfvClient::CAfvClient(const QString &apiServer, QObject *parent) : QObject(parent) { - m_connection = new ClientConnection(apiServer, this); + m_connection = new CClientConnection(apiServer, this); m_connection->setReceiveAudio(false); - m_input = new Input(c_sampleRate, this); - connect(m_input, &Input::opusDataAvailable, this, &AFVClient::opusDataAvailable); - connect(m_input, &Input::inputVolumeStream, this, &AFVClient::inputVolumeStream); + m_input = new CInput(c_sampleRate, this); + connect(m_input, &CInput::opusDataAvailable, this, &CAfvClient::opusDataAvailable); + connect(m_input, &CInput::inputVolumeStream, this, &CAfvClient::inputVolumeStream); m_output = new Output(this); - connect(m_output, &Output::outputVolumeStream, this, &AFVClient::outputVolumeStream); + connect(m_output, &Output::outputVolumeStream, this, &CAfvClient::outputVolumeStream); - connect(m_connection, &ClientConnection::audioReceived, this, &AFVClient::audioOutDataAvailable); + connect(m_connection, &CClientConnection::audioReceived, this, &CAfvClient::audioOutDataAvailable); - connect(&m_voiceServerPositionTimer, &QTimer::timeout, this, qOverload<>(&AFVClient::updateTransceivers)); + connect(&m_voiceServerPositionTimer, &QTimer::timeout, this, qOverload<>(&CAfvClient::updateTransceivers)); m_transceivers = { @@ -58,16 +59,16 @@ namespace BlackCore qDebug() << "UserClient instantiated"; } - void AFVClient::setContextOwnAircraft(const IContextOwnAircraft *contextOwnAircraft) + void CAfvClient::setContextOwnAircraft(const IContextOwnAircraft *contextOwnAircraft) { m_contextOwnAircraft = contextOwnAircraft; if (m_contextOwnAircraft) { - connect(m_contextOwnAircraft, &IContextOwnAircraft::changedAircraftCockpit, this, &AFVClient::updateTransceiversFromContext); + connect(m_contextOwnAircraft, &IContextOwnAircraft::changedAircraftCockpit, this, &CAfvClient::updateTransceiversFromContext); } } - void AFVClient::connectTo(const QString &cid, const QString &password, const QString &callsign) + void CAfvClient::connectTo(const QString &cid, const QString &password, const QString &callsign) { m_callsign = callsign; m_connection->connectTo(cid, password, callsign); @@ -79,13 +80,13 @@ namespace BlackCore m_connection->getAllAliasedStations(); } - void AFVClient::disconnectFrom() + void CAfvClient::disconnectFrom() { m_connection->disconnectFrom(); emit connectionStatusChanged(Disconnected); } - QStringList AFVClient::availableInputDevices() const + QStringList CAfvClient::availableInputDevices() const { const QList inputDevices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); @@ -97,7 +98,7 @@ namespace BlackCore return deviceNames; } - QStringList AFVClient::availableOutputDevices() const + QStringList CAfvClient::availableOutputDevices() const { const QList outputDevices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); @@ -109,7 +110,7 @@ namespace BlackCore return deviceNames; } - void AFVClient::setBypassEffects(bool value) + void CAfvClient::setBypassEffects(bool value) { if (soundcardSampleProvider) { @@ -117,7 +118,7 @@ namespace BlackCore } } - void AFVClient::start(const QAudioDeviceInfo &inputDevice, const QAudioDeviceInfo &outputDevice, const QVector &transceiverIDs) + void CAfvClient::start(const QAudioDeviceInfo &inputDevice, const QAudioDeviceInfo &outputDevice, const QVector &transceiverIDs) { if (m_isStarted) { @@ -125,9 +126,9 @@ namespace BlackCore return; } - soundcardSampleProvider = new SoundcardSampleProvider(c_sampleRate, transceiverIDs, this); - connect(soundcardSampleProvider, &SoundcardSampleProvider::receivingCallsignsChanged, this, &AFVClient::receivingCallsignsChanged); - outputSampleProvider = new VolumeSampleProvider(soundcardSampleProvider, this); + soundcardSampleProvider = new CSoundcardSampleProvider(c_sampleRate, transceiverIDs, this); + connect(soundcardSampleProvider, &CSoundcardSampleProvider::receivingCallsignsChanged, this, &CAfvClient::receivingCallsignsChanged); + outputSampleProvider = new CVolumeSampleProvider(soundcardSampleProvider, this); outputSampleProvider->setVolume(m_outputVolume); m_output->start(outputDevice, outputSampleProvider); @@ -140,13 +141,13 @@ namespace BlackCore qDebug() << ("Started [Input: " + inputDevice.deviceName() + "] [Output: " + outputDevice.deviceName() + "]"); } - void AFVClient::start(const QString &inputDeviceName, const QString &outputDeviceName) + void CAfvClient::start(const QString &inputDeviceName, const QString &outputDeviceName) { if (m_isStarted) { return; } - soundcardSampleProvider = new SoundcardSampleProvider(c_sampleRate, { 0, 1 }, this); - connect(soundcardSampleProvider, &SoundcardSampleProvider::receivingCallsignsChanged, this, &AFVClient::receivingCallsignsChanged); - outputSampleProvider = new VolumeSampleProvider(soundcardSampleProvider, this); + soundcardSampleProvider = new CSoundcardSampleProvider(c_sampleRate, { 0, 1 }, this); + connect(soundcardSampleProvider, &CSoundcardSampleProvider::receivingCallsignsChanged, this, &CAfvClient::receivingCallsignsChanged); + outputSampleProvider = new CVolumeSampleProvider(soundcardSampleProvider, this); outputSampleProvider->setVolume(m_outputVolume); QAudioDeviceInfo inputDevice = QAudioDeviceInfo::defaultInputDevice(); @@ -178,7 +179,7 @@ namespace BlackCore m_isStarted = true; } - void AFVClient::stop() + void CAfvClient::stop() { if (! m_isStarted) { @@ -196,7 +197,7 @@ namespace BlackCore m_output->stop(); } - void AFVClient::enableTransceiver(quint16 id, bool enable) + void CAfvClient::enableTransceiver(quint16 id, bool enable) { if (enable) { m_enabledTransceivers.insert(id); } else { m_enabledTransceivers.remove(id); } @@ -204,7 +205,7 @@ namespace BlackCore updateTransceivers(); } - void AFVClient::updateComFrequency(quint16 id, quint32 frequency) + void CAfvClient::updateComFrequency(quint16 id, quint32 frequency) { if (id != 0 && id != 1) { return; } @@ -221,7 +222,7 @@ namespace BlackCore } } - void AFVClient::updatePosition(double latitude, double longitude, double height) + void CAfvClient::updatePosition(double latitude, double longitude, double height) { for (TransceiverDto &transceiver : m_transceivers) { @@ -232,7 +233,7 @@ namespace BlackCore } } - void AFVClient::updateTransceivers() + void CAfvClient::updateTransceivers() { if (! m_connection->isConnected()) { return; } @@ -262,18 +263,18 @@ namespace BlackCore } } - void AFVClient::setTransmittingTransceivers(quint16 transceiverID) + void CAfvClient::setTransmittingTransceivers(quint16 transceiverID) { TxTransceiverDto tx = { transceiverID }; setTransmittingTransceivers({ tx }); } - void AFVClient::setTransmittingTransceivers(const QVector &transceivers) + void CAfvClient::setTransmittingTransceivers(const QVector &transceivers) { m_transmittingTransceivers = transceivers; } - void AFVClient::setPtt(bool active) + void CAfvClient::setPtt(bool active) { if (! m_isStarted) { @@ -303,7 +304,7 @@ namespace BlackCore qDebug() << "PTT:" << active; } - void AFVClient::setInputVolumeDb(double value) + void CAfvClient::setInputVolumeDb(double value) { if (value > 18) { value = 18; } if (value < -18) { value = -18; } @@ -311,7 +312,7 @@ namespace BlackCore m_input->setVolume(qPow(10, value / 20)); } - void AFVClient::opusDataAvailable(const OpusDataAvailableArgs &args) + void CAfvClient::opusDataAvailable(const OpusDataAvailableArgs &args) { if (m_loopbackOn && m_transmit) { @@ -360,7 +361,7 @@ namespace BlackCore } } - void AFVClient::audioOutDataAvailable(const AudioRxOnTransceiversDto &dto) + void CAfvClient::audioOutDataAvailable(const AudioRxOnTransceiversDto &dto) { IAudioDto audioData; audioData.audio = QByteArray(dto.audio.data(), static_cast(dto.audio.size())); @@ -370,19 +371,19 @@ namespace BlackCore soundcardSampleProvider->addOpusSamples(audioData, QVector::fromStdVector(dto.transceivers)); } - void AFVClient::inputVolumeStream(const InputVolumeStreamArgs &args) + void CAfvClient::inputVolumeStream(const InputVolumeStreamArgs &args) { m_inputVolumeStream = args; emit inputVolumePeakVU(m_inputVolumeStream.PeakVU); } - void AFVClient::outputVolumeStream(const OutputVolumeStreamArgs &args) + void CAfvClient::outputVolumeStream(const OutputVolumeStreamArgs &args) { m_outputVolumeStream = args; emit outputVolumePeakVU(m_outputVolumeStream.PeakVU); } - QString AFVClient::getReceivingCallsignsCom1() + QString CAfvClient::getReceivingCallsignsCom1() { if (soundcardSampleProvider) { @@ -391,7 +392,7 @@ namespace BlackCore return {}; } - QString AFVClient::getReceivingCallsignsCom2() + QString CAfvClient::getReceivingCallsignsCom2() { if (soundcardSampleProvider) { @@ -400,7 +401,7 @@ namespace BlackCore return {}; } - void AFVClient::updateTransceiversFromContext(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator) + void CAfvClient::updateTransceiversFromContext(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator) { Q_UNUSED(originator); updatePosition(aircraft.latitude().value(CAngleUnit::deg()), @@ -411,12 +412,12 @@ namespace BlackCore updateTransceivers(); } - double AFVClient::getOutputVolumeDb() const + double CAfvClient::getOutputVolumeDb() const { return m_outputVolume; } - void AFVClient::setOutputVolumeDb(double outputVolume) + void CAfvClient::setOutputVolumeDb(double outputVolume) { if (outputVolume > 18) { m_outputVolume = 18; } if (outputVolume < -60) { m_outputVolume = -60; } @@ -427,7 +428,7 @@ namespace BlackCore } } - AFVClient::ConnectionStatus AFVClient::getConnectionStatus() const + CAfvClient::ConnectionStatus CAfvClient::getConnectionStatus() const { return m_connection->isConnected() ? Connected : Disconnected; } diff --git a/src/blackcore/afv/clients/afvclient.h b/src/blackcore/afv/clients/afvclient.h index 9c769ad9b..27c26f4d1 100644 --- a/src/blackcore/afv/clients/afvclient.h +++ b/src/blackcore/afv/clients/afvclient.h @@ -36,7 +36,7 @@ namespace BlackCore namespace Clients { //! AFV client - class BLACKCORE_EXPORT AFVClient final : public QObject + class BLACKCORE_EXPORT CAfvClient final : public QObject { Q_OBJECT Q_PROPERTY(float inputVolumePeakVU READ getInputVolumePeakVU NOTIFY inputVolumePeakVU) @@ -50,10 +50,10 @@ namespace BlackCore Q_ENUM(ConnectionStatus) //! Ctor - AFVClient(const QString &apiServer, QObject *parent = nullptr); + CAfvClient(const QString &apiServer, QObject *parent = nullptr); //! Dtor - virtual ~AFVClient() + virtual ~CAfvClient() override { stop(); } @@ -125,19 +125,19 @@ namespace BlackCore void updateTransceiversFromContext(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); static constexpr int c_sampleRate = 48000; - static constexpr int frameSize = 960; //20ms + static constexpr int frameSize = 960; // 20ms // Connection - Connection::ClientConnection *m_connection = nullptr; + Connection::CClientConnection *m_connection = nullptr; // Properties QString m_callsign; - Audio::Input *m_input = nullptr; + Audio::CInput *m_input = nullptr; Audio::Output *m_output = nullptr; - Audio::SoundcardSampleProvider *soundcardSampleProvider = nullptr; - VolumeSampleProvider *outputSampleProvider = nullptr; + Audio::CSoundcardSampleProvider *soundcardSampleProvider = nullptr; + BlackSound::SampleProvider::CVolumeSampleProvider *outputSampleProvider = nullptr; bool m_transmit = false; bool m_transmitHistory = false; diff --git a/src/blackcore/afv/connection/clientconnection.cpp b/src/blackcore/afv/connection/clientconnection.cpp index 0ece86f1b..6a2cc9add 100644 --- a/src/blackcore/afv/connection/clientconnection.cpp +++ b/src/blackcore/afv/connection/clientconnection.cpp @@ -17,7 +17,7 @@ namespace BlackCore { namespace Connection { - ClientConnection::ClientConnection(const QString &apiServer, QObject *parent) : + CClientConnection::CClientConnection(const QString &apiServer, QObject *parent) : QObject(parent), m_apiServerConnection(apiServer, this) { @@ -27,13 +27,13 @@ namespace BlackCore // connect(&m_apiServerConnection, &ApiServerConnection::addCallsignFinished, this, &ClientConnection::addCallsignFinished); // connect(&m_apiServerConnection, &ApiServerConnection::removeCallsignFinished, this, &ClientConnection::removeCallsignFinished); - connect(&m_voiceServerTimer, &QTimer::timeout, this, &ClientConnection::voiceServerHeartbeat); + connect(&m_voiceServerTimer, &QTimer::timeout, this, &CClientConnection::voiceServerHeartbeat); - connect(&m_udpSocket, &QUdpSocket::readyRead, this, &ClientConnection::readPendingDatagrams); - connect(&m_udpSocket, qOverload(&QUdpSocket::error), this, &ClientConnection::handleSocketError); + connect(&m_udpSocket, &QUdpSocket::readyRead, this, &CClientConnection::readPendingDatagrams); + connect(&m_udpSocket, qOverload(&QUdpSocket::error), this, &CClientConnection::handleSocketError); } - void ClientConnection::connectTo(const QString &userName, const QString &password, const QString &callsign) + void CClientConnection::connectTo(const QString &userName, const QString &password, const QString &callsign) { if (m_connection.m_connected) { @@ -57,7 +57,7 @@ namespace BlackCore qDebug() << "Connected:" << callsign; } - void ClientConnection::disconnectFrom(const QString &reason) + void CClientConnection::disconnectFrom(const QString &reason) { if (! m_connection.m_connected) { @@ -82,27 +82,27 @@ namespace BlackCore qDebug() << "Disconnection complete"; } - bool ClientConnection::receiveAudioDto() const + bool CClientConnection::receiveAudioDto() const { return m_receiveAudioDto; } - void ClientConnection::setReceiveAudioDto(bool receiveAudioDto) + void CClientConnection::setReceiveAudioDto(bool receiveAudioDto) { m_receiveAudioDto = receiveAudioDto; } - void ClientConnection::updateTransceivers(const QString &callsign, const QVector &transceivers) + void CClientConnection::updateTransceivers(const QString &callsign, const QVector &transceivers) { m_apiServerConnection.updateTransceivers(callsign, transceivers); } - QVector ClientConnection::getAllAliasedStations() + QVector CClientConnection::getAllAliasedStations() { return m_apiServerConnection.getAllAliasedStations(); } - void ClientConnection::connectToVoiceServer() + void CClientConnection::connectToVoiceServer() { QHostAddress localAddress(QHostAddress::AnyIPv4); m_udpSocket.bind(localAddress); @@ -111,14 +111,14 @@ namespace BlackCore qDebug() << "Connected to voice server (" + m_connection.m_tokens.VoiceServer.addressIpV4 << ")"; } - void ClientConnection::disconnectFromVoiceServer() + void CClientConnection::disconnectFromVoiceServer() { m_voiceServerTimer.stop(); m_udpSocket.disconnectFromHost(); qDebug() << "All TaskVoiceServer tasks stopped"; } - void ClientConnection::readPendingDatagrams() + void CClientConnection::readPendingDatagrams() { while (m_udpSocket.hasPendingDatagrams()) { @@ -127,7 +127,7 @@ namespace BlackCore } } - void ClientConnection::processMessage(const QByteArray &messageDdata, bool loopback) + void CClientConnection::processMessage(const QByteArray &messageDdata, bool loopback) { CryptoDtoSerializer::Deserializer deserializer = CryptoDtoSerializer::deserialize(*m_connection.voiceCryptoChannel, messageDdata, loopback); @@ -151,13 +151,13 @@ namespace BlackCore } } - void ClientConnection::handleSocketError(QAbstractSocket::SocketError error) + void CClientConnection::handleSocketError(QAbstractSocket::SocketError error) { Q_UNUSED(error); qDebug() << "UDP socket error" << m_udpSocket.errorString(); } - void ClientConnection::voiceServerHeartbeat() + void CClientConnection::voiceServerHeartbeat() { QUrl voiceServerUrl("udp://" + m_connection.m_tokens.VoiceServer.addressIpV4); qDebug() << "Sending voice server heartbeat to" << voiceServerUrl.host(); diff --git a/src/blackcore/afv/connection/clientconnection.h b/src/blackcore/afv/connection/clientconnection.h index e75b8c3c6..1dc8deb1d 100644 --- a/src/blackcore/afv/connection/clientconnection.h +++ b/src/blackcore/afv/connection/clientconnection.h @@ -28,7 +28,7 @@ namespace BlackCore namespace Connection { //! Client connection - class ClientConnection : public QObject + class CClientConnection : public QObject { Q_OBJECT @@ -41,7 +41,7 @@ namespace BlackCore }; Q_ENUM(ConnectionStatus) - ClientConnection(const QString &apiServer, QObject *parent = nullptr); + CClientConnection(const QString &apiServer, QObject *parent = nullptr); void connectTo(const QString &userName, const QString &password, const QString &callsign); void disconnectFrom(const QString &reason = {}); @@ -82,7 +82,7 @@ namespace BlackCore const QUuid m_networkVersion = QUuid("3a5ddc6d-cf5d-4319-bd0e-d184f772db80"); //Data - ClientConnectionData m_connection; + CClientConnectionData m_connection; // Voice server QUdpSocket m_udpSocket; diff --git a/src/blackcore/afv/connection/clientconnectiondata.cpp b/src/blackcore/afv/connection/clientconnectiondata.cpp index 878ed84ee..6b039304b 100644 --- a/src/blackcore/afv/connection/clientconnectiondata.cpp +++ b/src/blackcore/afv/connection/clientconnectiondata.cpp @@ -17,27 +17,27 @@ namespace BlackCore { namespace Connection { - qint64 ClientConnectionData::secondsSinceAuthentication() const + qint64 CClientConnectionData::secondsSinceAuthentication() const { return m_authenticatedDateTimeUtc.secsTo(QDateTime::currentDateTimeUtc()); } - bool ClientConnectionData::isVoiceServerAlive() const + bool CClientConnectionData::isVoiceServerAlive() const { return m_lastVoiceServerHeartbeatAckUtc.secsTo(QDateTime::currentDateTimeUtc()) > serverTimeout; } - void ClientConnectionData::createCryptoChannels() + void CClientConnectionData::createCryptoChannels() { if (! m_tokens.isValid) { qWarning() << "Tokens not set"; } - voiceCryptoChannel.reset(new CryptoDtoChannel(m_tokens.VoiceServer.channelConfig)); + voiceCryptoChannel.reset(new CCryptoDtoChannel(m_tokens.VoiceServer.channelConfig)); // dataCryptoChannel.reset(new CryptoDtoChannel(m_tokens.DataServer.channelConfig)); } - bool ClientConnectionData::voiceServerAlive() const + bool CClientConnectionData::voiceServerAlive() const { return timeSinceAuthentication() < serverTimeout || m_lastVoiceServerHeartbeatAckUtc.secsTo(QDateTime::currentDateTimeUtc()) < serverTimeout; diff --git a/src/blackcore/afv/connection/clientconnectiondata.h b/src/blackcore/afv/connection/clientconnectiondata.h index 26717053b..727541e06 100644 --- a/src/blackcore/afv/connection/clientconnectiondata.h +++ b/src/blackcore/afv/connection/clientconnectiondata.h @@ -27,9 +27,9 @@ namespace BlackCore namespace Connection { //! Client connection data - struct ClientConnectionData + struct CClientConnectionData { - ClientConnectionData() = default; + CClientConnectionData() = default; qint64 secondsSinceAuthentication() const; @@ -53,7 +53,7 @@ namespace BlackCore PostCallsignResponseDto m_tokens; - QScopedPointer voiceCryptoChannel; + QScopedPointer voiceCryptoChannel; QDateTime m_authenticatedDateTimeUtc; QDateTime m_lastVoiceServerHeartbeatAckUtc; diff --git a/src/blackcore/afv/crypto/cryptodtochannel.cpp b/src/blackcore/afv/crypto/cryptodtochannel.cpp index c05bc2984..ecaab6924 100644 --- a/src/blackcore/afv/crypto/cryptodtochannel.cpp +++ b/src/blackcore/afv/crypto/cryptodtochannel.cpp @@ -14,7 +14,7 @@ namespace BlackCore { namespace Crypto { - CryptoDtoChannel::CryptoDtoChannel(QString channelTag, const QByteArray &aeadReceiveKey, const QByteArray &aeadTransmitKey, int receiveSequenceHistorySize) + CCryptoDtoChannel::CCryptoDtoChannel(QString channelTag, const QByteArray &aeadReceiveKey, const QByteArray &aeadTransmitKey, int receiveSequenceHistorySize) { ChannelTag = channelTag; m_aeadReceiveKey = aeadReceiveKey; @@ -27,7 +27,7 @@ namespace BlackCore receiveSequenceHistoryDepth = 0; } - CryptoDtoChannel::CryptoDtoChannel(CryptoDtoChannelConfigDto channelConfig, int receiveSequenceHistorySize) + CCryptoDtoChannel::CCryptoDtoChannel(CryptoDtoChannelConfigDto channelConfig, int receiveSequenceHistorySize) { ChannelTag = channelConfig.channelTag; m_aeadReceiveKey = channelConfig.aeadReceiveKey; @@ -41,7 +41,7 @@ namespace BlackCore receiveSequenceHistoryDepth = 0; } - QByteArray CryptoDtoChannel::getTransmitKey(CryptoDtoMode mode) + QByteArray CCryptoDtoChannel::getTransmitKey(CryptoDtoMode mode) { switch (mode) { @@ -54,7 +54,7 @@ namespace BlackCore return {}; } - QByteArray CryptoDtoChannel::getTransmitKey(CryptoDtoMode mode, uint &sequenceToSend) + QByteArray CCryptoDtoChannel::getTransmitKey(CryptoDtoMode mode, uint &sequenceToSend) { sequenceToSend = transmitSequence; transmitSequence++; @@ -71,12 +71,12 @@ namespace BlackCore return {}; } - QString CryptoDtoChannel::getChannelTag() const + QString CCryptoDtoChannel::getChannelTag() const { return ChannelTag; } - QByteArray CryptoDtoChannel::getReceiveKey(CryptoDtoMode mode) + QByteArray CCryptoDtoChannel::getReceiveKey(CryptoDtoMode mode) { switch (mode) { @@ -89,7 +89,7 @@ namespace BlackCore return {}; } - bool CryptoDtoChannel::checkReceivedSequence(uint sequenceReceived) + bool CCryptoDtoChannel::checkReceivedSequence(uint sequenceReceived) { if (contains(sequenceReceived)) { @@ -113,7 +113,7 @@ namespace BlackCore return true; } - bool CryptoDtoChannel::contains(uint sequence) + bool CCryptoDtoChannel::contains(uint sequence) { for (int i = 0; i < receiveSequenceHistoryDepth; i++) { @@ -123,7 +123,7 @@ namespace BlackCore return false; } - uint CryptoDtoChannel::getMin(int &minIndex) + uint CCryptoDtoChannel::getMin(int &minIndex) { uint minValue = std::numeric_limits::max(); minIndex = -1; diff --git a/src/blackcore/afv/crypto/cryptodtochannel.h b/src/blackcore/afv/crypto/cryptodtochannel.h index 6c5d36b1a..ca060fdd5 100644 --- a/src/blackcore/afv/crypto/cryptodtochannel.h +++ b/src/blackcore/afv/crypto/cryptodtochannel.h @@ -26,14 +26,14 @@ namespace BlackCore namespace Crypto { //! Crypto channel - class CryptoDtoChannel + class CCryptoDtoChannel { public: //! Ctor - CryptoDtoChannel(QString channelTag, const QByteArray &aeadReceiveKey, const QByteArray &aeadTransmitKey, int receiveSequenceHistorySize = 10); + CCryptoDtoChannel(QString channelTag, const QByteArray &aeadReceiveKey, const QByteArray &aeadTransmitKey, int receiveSequenceHistorySize = 10); //! Ctor - CryptoDtoChannel(CryptoDtoChannelConfigDto channelConfig, int receiveSequenceHistorySize = 10); + CCryptoDtoChannel(CryptoDtoChannelConfigDto channelConfig, int receiveSequenceHistorySize = 10); QByteArray getTransmitKey(CryptoDtoMode mode); QByteArray getTransmitKey(CryptoDtoMode mode, uint &sequenceToSend); diff --git a/src/blackcore/afv/crypto/cryptodtoserializer.cpp b/src/blackcore/afv/crypto/cryptodtoserializer.cpp index c8ae8fdd8..9749125d1 100644 --- a/src/blackcore/afv/crypto/cryptodtoserializer.cpp +++ b/src/blackcore/afv/crypto/cryptodtoserializer.cpp @@ -17,12 +17,12 @@ namespace BlackCore { CryptoDtoSerializer::CryptoDtoSerializer() { } - CryptoDtoSerializer::Deserializer CryptoDtoSerializer::deserialize(CryptoDtoChannel &channel, const QByteArray &bytes, bool loopback) + CryptoDtoSerializer::Deserializer CryptoDtoSerializer::deserialize(CCryptoDtoChannel &channel, const QByteArray &bytes, bool loopback) { return Deserializer(channel, bytes, loopback); } - CryptoDtoSerializer::Deserializer::Deserializer(CryptoDtoChannel &channel, const QByteArray &bytes, bool loopback) + CryptoDtoSerializer::Deserializer::Deserializer(CCryptoDtoChannel &channel, const QByteArray &bytes, bool loopback) { QByteArray data(bytes); QBuffer buffer(&data); diff --git a/src/blackcore/afv/crypto/cryptodtoserializer.h b/src/blackcore/afv/crypto/cryptodtoserializer.h index 87ee1b35c..ea38acd4e 100644 --- a/src/blackcore/afv/crypto/cryptodtoserializer.h +++ b/src/blackcore/afv/crypto/cryptodtoserializer.h @@ -34,6 +34,7 @@ namespace BlackCore public: CryptoDtoSerializer(); + //! Serialize a DTO template static QByteArray Serialize(const QString &channelTag, CryptoDtoMode mode, const QByteArray &transmitKey, uint sequenceToBeSent, T dto) { @@ -105,8 +106,9 @@ namespace BlackCore return {}; } + //! Serialize a DTO template - static QByteArray Serialize(CryptoDtoChannel &channel, CryptoDtoMode mode, T dto) + static QByteArray Serialize(CCryptoDtoChannel &channel, CryptoDtoMode mode, T dto) { uint sequenceToSend = 0; QByteArray transmitKey = channel.getTransmitKey(mode, sequenceToSend); @@ -115,7 +117,7 @@ namespace BlackCore struct Deserializer { - Deserializer(CryptoDtoChannel &channel, const QByteArray &bytes, bool loopback); + Deserializer(CCryptoDtoChannel &channel, const QByteArray &bytes, bool loopback); template T getDto() @@ -143,7 +145,7 @@ namespace BlackCore bool verified = false; }; - static Deserializer deserialize(CryptoDtoChannel &channel, const QByteArray &bytes, bool loopback); + static Deserializer deserialize(CCryptoDtoChannel &channel, const QByteArray &bytes, bool loopback); }; } // ns } // ns diff --git a/src/blackcore/afv/dto.h b/src/blackcore/afv/dto.h index bec115db7..dc33e819f 100644 --- a/src/blackcore/afv/dto.h +++ b/src/blackcore/afv/dto.h @@ -22,16 +22,19 @@ namespace BlackCore { namespace Afv { - struct IMsgPack - { }; + // struct IMsgPack { }; + //! Channel config DTO struct CryptoDtoChannelConfigDto { + //! Properties @{ QString channelTag; QByteArray aeadReceiveKey; QByteArray aeadTransmitKey; QByteArray hmacKey; + //! @} + //! To JSON QJsonObject toJson() const { QJsonObject json; @@ -42,6 +45,7 @@ namespace BlackCore return json; } + //! From JSON static CryptoDtoChannelConfigDto fromJson(const QJsonObject &json) { CryptoDtoChannelConfigDto dto; @@ -54,12 +58,16 @@ namespace BlackCore } }; + //! Voice server DTO struct VoiceServerConnectionDataDto { + //! Properties @{ QString addressIpV4; // Example: 123.123.123.123:50000 QString addressIpV6; // Example: 123.123.123.123:50000 CryptoDtoChannelConfigDto channelConfig; + //! @} + //! To JSON QJsonObject toJson() const { QJsonObject json; @@ -69,6 +77,7 @@ namespace BlackCore return json; } + //! From JSON static VoiceServerConnectionDataDto fromJson(const QJsonObject &json) { VoiceServerConnectionDataDto dto; @@ -79,12 +88,16 @@ namespace BlackCore } }; + //! Callsign DTO struct PostCallsignResponseDto { - VoiceServerConnectionDataDto VoiceServer; + //! Properties @{ // DataServerConnectionDataDto DataServer; + VoiceServerConnectionDataDto VoiceServer; bool isValid = false; + //! @} + //! To JSON QJsonObject toJson() const { QJsonObject json; @@ -93,6 +106,7 @@ namespace BlackCore return json; } + //! From JSON static PostCallsignResponseDto fromJson(const QJsonObject &json) { PostCallsignResponseDto dto; @@ -103,16 +117,20 @@ namespace BlackCore } }; + //! Transceiver DTO struct TransceiverDto { + //! Properties @{ quint16 id; quint32 frequency; double LatDeg = 0.0; double LonDeg = 0.0; double HeightMslM = 0.0; double HeightAglM = 0.0; + //! @} MSGPACK_DEFINE(id, frequency, LatDeg, LonDeg, HeightMslM, HeightAglM) + //! To JSON QJsonObject toJson() const { QJsonObject json; @@ -125,11 +143,12 @@ namespace BlackCore return json; } + //! From JSON static TransceiverDto fromJson(const QJsonObject &json) { TransceiverDto dto; - dto.id = json.value("id").toInt(); - dto.frequency = json.value("frequency").toInt(); + dto.id = static_cast(json.value("id").toInt()); + dto.frequency = static_cast(json.value("frequency").toInt()); dto.LatDeg = json.value("latDeg").toDouble(); dto.LonDeg = json.value("lonDeg").toDouble(); dto.HeightMslM = json.value("heightMslM").toDouble(); @@ -138,33 +157,39 @@ namespace BlackCore } }; + //! Station DTO struct StationDto { + //! Properties @{ QUuid id; QString name; quint32 frequency; quint32 frequencyAlias; + //! @} + //! From JSON static StationDto fromJson(const QJsonObject &json) { StationDto dto; dto.id = json.value("id").toString(); dto.name = json.value("name").toString(); - dto.frequency = json.value("frequency").toInt(); - dto.frequencyAlias = json.value("frequencyAlias").toInt(); + dto.frequency = static_cast(json.value("frequency").toInt()); + dto.frequencyAlias = static_cast(json.value("frequencyAlias").toInt()); return dto; } }; + //! Heartbeat DTO struct HeartbeatDto { static QByteArray getDtoName() { return "HeartbeatDto"; } static QByteArray getShortDtoName() { return "H"; } - std::string callsign; + std::string callsign; //!< callsign MSGPACK_DEFINE(callsign) }; + //! Heartbeat DTO struct HeartbeatAckDto { static QByteArray getDtoName() { return "HeartbeatAckDto"; } @@ -172,20 +197,22 @@ namespace BlackCore MSGPACK_DEFINE() }; + //! Receive transceiver DTO struct RxTransceiverDto { + //! Properties @{ uint16_t id; uint32_t frequency; float distanceRatio; // std::string RelayCallsign; - + //! @} MSGPACK_DEFINE(id, frequency, distanceRatio/*, RelayCallsign*/) }; + //! Transmit transceiver DTO struct TxTransceiverDto { - uint16_t id; - + uint16_t id; //!< id MSGPACK_DEFINE(id) }; @@ -194,11 +221,13 @@ namespace BlackCore static QByteArray getDtoName() { return "AudioTxOnTransceiversDto"; } static QByteArray getShortDtoName() { return "AT"; } + //! Properties @{ std::string callsign; uint sequenceCounter; std::vector audio; bool lastPacket; std::vector transceivers; + //! @} MSGPACK_DEFINE(callsign, sequenceCounter, audio, lastPacket, transceivers) }; @@ -207,20 +236,23 @@ namespace BlackCore static QByteArray getDtoName() { return "AudioRxOnTransceiversDto"; } static QByteArray getShortDtoName() { return "AR"; } + //! Properties @{ std::string callsign; uint sequenceCounter; std::vector audio; bool lastPacket; std::vector transceivers; + //! @} MSGPACK_DEFINE(callsign, sequenceCounter, audio, lastPacket, transceivers) }; + //! Audio DTO struct IAudioDto { - QString callsign; // Callsign that audio originates from - uint sequenceCounter; // Receiver optionally uses this in reordering algorithm/gap detection - QByteArray audio; // Opus compressed audio - bool lastPacket; // Used to indicate to receiver that the sender has stopped sending + QString callsign; //!< Callsign that audio originates from + uint sequenceCounter; //!< Receiver optionally uses this in reordering algorithm/gap detection + QByteArray audio; //!< Opus compressed audio + bool lastPacket; //!< Used to indicate to receiver that the sender has stopped sending }; } // ns } // ns diff --git a/src/blackcore/context/contextaudioimpl.h b/src/blackcore/context/contextaudioimpl.h index 8738041d0..60198d040 100644 --- a/src/blackcore/context/contextaudioimpl.h +++ b/src/blackcore/context/contextaudioimpl.h @@ -223,7 +223,7 @@ namespace BlackCore BlackMisc::CSetting m_outputDeviceSetting { this, &CContextAudio::changeDeviceSettings }; // AFV - Afv::Clients::AFVClient m_voiceClient; + Afv::Clients::CAfvClient m_voiceClient; }; } // namespace } // namespace diff --git a/src/blacksound/codecs/opusdecoder.h b/src/blacksound/codecs/opusdecoder.h index 7f862adbc..1e14f6240 100644 --- a/src/blacksound/codecs/opusdecoder.h +++ b/src/blacksound/codecs/opusdecoder.h @@ -8,8 +8,8 @@ //! \file -#ifndef BLACKSOUND_OPUSDECODER_H -#define BLACKSOUND_OPUSDECODER_H +#ifndef BLACKSOUND_CODECS_OPUSDECODER_H +#define BLACKSOUND_CODECS_OPUSDECODER_H #include "blacksound/blacksoundexport.h" #include "opus/opus.h" diff --git a/src/blacksound/sampleprovider/bufferedwaveprovider.cpp b/src/blacksound/sampleprovider/bufferedwaveprovider.cpp index 4dd5bd1e4..368dd593a 100644 --- a/src/blacksound/sampleprovider/bufferedwaveprovider.cpp +++ b/src/blacksound/sampleprovider/bufferedwaveprovider.cpp @@ -2,33 +2,39 @@ #include -BufferedWaveProvider::BufferedWaveProvider(const QAudioFormat &format, QObject *parent) : - ISampleProvider(parent) +namespace BlackSound { - // Set buffer size to 10 secs - m_maxBufferSize = format.bytesForDuration(10 * 1000 * 1000); -} - -void BufferedWaveProvider::addSamples(const QVector &samples) -{ - int delta = m_audioBuffer.size() + samples.size() - m_maxBufferSize; - if(delta > 0) + namespace SampleProvider { - m_audioBuffer.remove(0, delta); - } - m_audioBuffer.append(samples); -} + CBufferedWaveProvider::CBufferedWaveProvider(const QAudioFormat &format, QObject *parent) : + ISampleProvider(parent) + { + // Set buffer size to 10 secs + m_maxBufferSize = format.bytesForDuration(10 * 1000 * 1000); + } -int BufferedWaveProvider::readSamples(QVector &samples, qint64 count) -{ - qint64 len = qMin(count, static_cast(m_audioBuffer.size())); - samples = m_audioBuffer.mid(0, len); - // if (len != 0) qDebug() << "Reading" << count << "samples." << m_audioBuffer.size() << "currently in the buffer."; - m_audioBuffer.remove(0, len); - return len; -} + void CBufferedWaveProvider::addSamples(const QVector &samples) + { + int delta = m_audioBuffer.size() + samples.size() - m_maxBufferSize; + if (delta > 0) + { + m_audioBuffer.remove(0, delta); + } + m_audioBuffer.append(samples); + } -void BufferedWaveProvider::clearBuffer() -{ - m_audioBuffer.clear(); -} + int CBufferedWaveProvider::readSamples(QVector &samples, qint64 count) + { + qint64 len = qMin(count, static_cast(m_audioBuffer.size())); + samples = m_audioBuffer.mid(0, len); + // if (len != 0) qDebug() << "Reading" << count << "samples." << m_audioBuffer.size() << "currently in the buffer."; + m_audioBuffer.remove(0, len); + return len; + } + + void CBufferedWaveProvider::clearBuffer() + { + m_audioBuffer.clear(); + } + } // ns +} // ns diff --git a/src/blacksound/sampleprovider/bufferedwaveprovider.h b/src/blacksound/sampleprovider/bufferedwaveprovider.h index 6034c8d59..349277481 100644 --- a/src/blacksound/sampleprovider/bufferedwaveprovider.h +++ b/src/blacksound/sampleprovider/bufferedwaveprovider.h @@ -1,3 +1,13 @@ +/* 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_BUFFEREDWAVEPROVIDER_H #define BLACKSOUND_BUFFEREDWAVEPROVIDER_H @@ -8,23 +18,31 @@ #include #include -class BLACKSOUND_EXPORT BufferedWaveProvider : public ISampleProvider +namespace BlackSound { - Q_OBJECT + namespace SampleProvider + { + //! Buffered wave generator + class BLACKSOUND_EXPORT CBufferedWaveProvider : public ISampleProvider + { + Q_OBJECT -public: - BufferedWaveProvider(const QAudioFormat &format, QObject *parent = nullptr); + public: + //! Ctor + CBufferedWaveProvider(const QAudioFormat &format, QObject *parent = nullptr); - void addSamples(const QVector &samples); - virtual int readSamples(QVector &samples, qint64 count) override; + void addSamples(const QVector &samples); + virtual int readSamples(QVector &samples, qint64 count) override; - int getBufferedBytes() const { return m_audioBuffer.size(); } + int getBufferedBytes() const { return m_audioBuffer.size(); } - void clearBuffer(); + void clearBuffer(); -private: - QVector m_audioBuffer; - qint32 m_maxBufferSize; -}; + private: + QVector m_audioBuffer; + qint32 m_maxBufferSize; + }; + } +} -#endif // BUFFEREDWAVEPROVIDER_H +#endif // guard diff --git a/src/blacksound/sampleprovider/equalizersampleprovider.cpp b/src/blacksound/sampleprovider/equalizersampleprovider.cpp index ca1d269f3..0e459e7f5 100644 --- a/src/blacksound/sampleprovider/equalizersampleprovider.cpp +++ b/src/blacksound/sampleprovider/equalizersampleprovider.cpp @@ -1,51 +1,57 @@ #include "equalizersampleprovider.h" -EqualizerSampleProvider::EqualizerSampleProvider(ISampleProvider *sourceProvider, EqualizerPresets preset, QObject *parent) : - ISampleProvider(parent) +namespace BlackSound { - m_sourceProvider = sourceProvider; - setupPreset(preset); -} - -int EqualizerSampleProvider::readSamples(QVector &samples, qint64 count) -{ - int samplesRead = m_sourceProvider->readSamples(samples, count); - if (m_bypass) return samplesRead; - - for (int n = 0; n < samplesRead; n++) + namespace SampleProvider { - // TODO stereo implementation - - for (int band = 0; band < m_filters.size(); band++) + CEqualizerSampleProvider::CEqualizerSampleProvider(ISampleProvider *sourceProvider, EqualizerPresets preset, QObject *parent) : + ISampleProvider(parent) { - float s = samples[n] / 32768.0f; - s = m_filters[band].process(s); - samples[n] = s * 32768; + m_sourceProvider = sourceProvider; + setupPreset(preset); } - samples[n] *= m_outputGain; - } - return samplesRead; -} + int CEqualizerSampleProvider::readSamples(QVector &samples, qint64 count) + { + int samplesRead = m_sourceProvider->readSamples(samples, count); + if (m_bypass) return samplesRead; -void EqualizerSampleProvider::setupPreset(EqualizerPresets preset) -{ - switch (preset) - { - case VHFEmulation: - m_filters.push_back(BiQuadFilter(BiQuadFilterType::HighPass, 44100, 450, 1.0f)); - m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 2200, 0.25, 13.0f)); - m_filters.push_back(BiQuadFilter(BiQuadFilterType::LowPass, 44100, 3000, 1.0f)); - break; + for (int n = 0; n < samplesRead; n++) + { + // TODO stereo implementation + + for (int band = 0; band < m_filters.size(); band++) + { + float s = samples[n] / 32768.0f; + s = m_filters[band].process(s); + samples[n] = s * 32768; + } + + samples[n] *= m_outputGain; + } + return samplesRead; + } + + void CEqualizerSampleProvider::setupPreset(EqualizerPresets preset) + { + switch (preset) + { + case VHFEmulation: + m_filters.push_back(BiQuadFilter(BiQuadFilterType::HighPass, 44100, 450, 1.0f)); + m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 2200, 0.25, 13.0f)); + m_filters.push_back(BiQuadFilter(BiQuadFilterType::LowPass, 44100, 3000, 1.0f)); + break; + } + } + + double CEqualizerSampleProvider::outputGain() const + { + return m_outputGain; + } + + void CEqualizerSampleProvider::setOutputGain(double outputGain) + { + m_outputGain = outputGain; + } } } - -double EqualizerSampleProvider::outputGain() const -{ - return m_outputGain; -} - -void EqualizerSampleProvider::setOutputGain(double outputGain) -{ - m_outputGain = outputGain; -} diff --git a/src/blacksound/sampleprovider/equalizersampleprovider.h b/src/blacksound/sampleprovider/equalizersampleprovider.h index 3c99d9b0d..a87ee051c 100644 --- a/src/blacksound/sampleprovider/equalizersampleprovider.h +++ b/src/blacksound/sampleprovider/equalizersampleprovider.h @@ -1,5 +1,15 @@ -#ifndef EQUALIZERSAMPLEPROVIDER_H -#define EQUALIZERSAMPLEPROVIDER_H +/* 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_EQUALIZERSAMPLEPROVIDER_H +#define BLACKSOUND_SAMPLEPROVIDER_EQUALIZERSAMPLEPROVIDER_H #include "blacksound/blacksoundexport.h" #include "blacksound/sampleprovider/sampleprovider.h" @@ -8,34 +18,41 @@ #include #include -enum EqualizerPresets +namespace BlackSound { - VHFEmulation = 1 -}; + namespace SampleProvider + { + //! Equalizer + enum EqualizerPresets + { + VHFEmulation = 1 + }; -class BLACKSOUND_EXPORT EqualizerSampleProvider : public ISampleProvider -{ - Q_OBJECT + class BLACKSOUND_EXPORT CEqualizerSampleProvider : public ISampleProvider + { + Q_OBJECT -public: - EqualizerSampleProvider(ISampleProvider *sourceProvider, EqualizerPresets preset, QObject *parent = nullptr); + public: + CEqualizerSampleProvider(ISampleProvider *sourceProvider, EqualizerPresets preset, QObject *parent = nullptr); - virtual int readSamples(QVector &samples, qint64 count) override; + virtual int readSamples(QVector &samples, qint64 count) override; - void setBypassEffects(bool value) { m_bypass = value; } + void setBypassEffects(bool value) { m_bypass = value; } - double outputGain() const; - void setOutputGain(double outputGain); + double outputGain() const; + void setOutputGain(double outputGain); -private: - void setupPreset(EqualizerPresets preset); + private: + void setupPreset(EqualizerPresets preset); - ISampleProvider *m_sourceProvider; + ISampleProvider *m_sourceProvider; - int m_channels = 1; - bool m_bypass = false; - double m_outputGain = 1.0; - QVector m_filters; -}; + int m_channels = 1; + bool m_bypass = false; + double m_outputGain = 1.0; + QVector m_filters; + }; + } // ns +} // ns -#endif // EQUALIZERSAMPLEPROVIDER_H +#endif // guard diff --git a/src/blacksound/sampleprovider/mixingsampleprovider.cpp b/src/blacksound/sampleprovider/mixingsampleprovider.cpp index 0bef196d9..0f2da1998 100644 --- a/src/blacksound/sampleprovider/mixingsampleprovider.cpp +++ b/src/blacksound/sampleprovider/mixingsampleprovider.cpp @@ -1,36 +1,50 @@ +/* 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 "mixingsampleprovider.h" -int MixingSampleProvider::readSamples(QVector &samples, qint64 count) +namespace BlackSound { - samples.clear(); - samples.fill(0, count); - int outputLen = 0; - - QVector finishedProviders; - for (int i = 0; i < m_sources.size(); i++) + namespace SampleProvider { - ISampleProvider *sampleProvider = m_sources.at(i); - QVector sourceBuffer; - int len = sampleProvider->readSamples(sourceBuffer, count); - - for (int n = 0; n < len; n++) + int CMixingSampleProvider::readSamples(QVector &samples, qint64 count) { - samples[n] += sourceBuffer[n]; - } + samples.clear(); + samples.fill(0, count); + int outputLen = 0; - outputLen = qMax(len, outputLen); + QVector finishedProviders; + for (int i = 0; i < m_sources.size(); i++) + { + ISampleProvider *sampleProvider = m_sources.at(i); + QVector sourceBuffer; + int len = sampleProvider->readSamples(sourceBuffer, count); - if (sampleProvider->isFinished()) - { - finishedProviders.push_back(sampleProvider); + for (int n = 0; n < len; n++) + { + samples[n] += sourceBuffer[n]; + } + + outputLen = qMax(len, outputLen); + + if (sampleProvider->isFinished()) + { + finishedProviders.push_back(sampleProvider); + } + } + + for (ISampleProvider *sampleProvider : finishedProviders) + { + sampleProvider->deleteLater(); + m_sources.removeAll(sampleProvider); + } + + return outputLen; } } - - for (ISampleProvider *sampleProvider : finishedProviders) - { - sampleProvider->deleteLater(); - m_sources.removeAll(sampleProvider); - } - - return outputLen; } diff --git a/src/blacksound/sampleprovider/mixingsampleprovider.h b/src/blacksound/sampleprovider/mixingsampleprovider.h index 05a3caea8..5705807f9 100644 --- a/src/blacksound/sampleprovider/mixingsampleprovider.h +++ b/src/blacksound/sampleprovider/mixingsampleprovider.h @@ -1,3 +1,13 @@ +/* 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 MIXINGSAMPLEPROVIDER_H #define MIXINGSAMPLEPROVIDER_H @@ -6,16 +16,22 @@ #include #include -class BLACKSOUND_EXPORT MixingSampleProvider : public ISampleProvider +namespace BlackSound { -public: - MixingSampleProvider(QObject * parent = nullptr) : ISampleProvider(parent) {} + namespace SampleProvider + { + class BLACKSOUND_EXPORT CMixingSampleProvider : public ISampleProvider + { + public: + CMixingSampleProvider(QObject *parent = nullptr) : ISampleProvider(parent) {} - void addMixerInput(ISampleProvider *provider) { m_sources.append(provider); } - virtual int readSamples(QVector &samples, qint64 count) override; + void addMixerInput(ISampleProvider *provider) { m_sources.append(provider); } + virtual int readSamples(QVector &samples, qint64 count) override; -private: - QVector m_sources; -}; + private: + QVector m_sources; + }; + } +} -#endif // MIXINGSAMPLEPROVIDER_H +#endif // guard diff --git a/src/blacksound/sampleprovider/pinknoisegenerator.cpp b/src/blacksound/sampleprovider/pinknoisegenerator.cpp index 4242b337c..3a8398f00 100644 --- a/src/blacksound/sampleprovider/pinknoisegenerator.cpp +++ b/src/blacksound/sampleprovider/pinknoisegenerator.cpp @@ -10,25 +10,31 @@ #include "pinknoisegenerator.h" -int PinkNoiseGenerator::readSamples(QVector &samples, qint64 count) +namespace BlackSound { - samples.clear(); - samples.fill(0, count); - - for (int sampleCount = 0; sampleCount < count; sampleCount++) + namespace SampleProvider { - double white = 2 * random.generateDouble() - 1; + int CPinkNoiseGenerator::readSamples(QVector &samples, qint64 count) + { + samples.clear(); + samples.fill(0, count); - pinkNoiseBuffer[0] = 0.99886*pinkNoiseBuffer[0] + white*0.0555179; - pinkNoiseBuffer[1] = 0.99332*pinkNoiseBuffer[1] + white*0.0750759; - pinkNoiseBuffer[2] = 0.96900*pinkNoiseBuffer[2] + white*0.1538520; - pinkNoiseBuffer[3] = 0.86650*pinkNoiseBuffer[3] + white*0.3104856; - pinkNoiseBuffer[4] = 0.55000*pinkNoiseBuffer[4] + white*0.5329522; - pinkNoiseBuffer[5] = -0.7616*pinkNoiseBuffer[5] - white*0.0168980; - double pink = pinkNoiseBuffer[0] + pinkNoiseBuffer[1] + pinkNoiseBuffer[2] + pinkNoiseBuffer[3] + pinkNoiseBuffer[4] + pinkNoiseBuffer[5] + pinkNoiseBuffer[6] + white*0.5362; - pinkNoiseBuffer[6] = white*0.115926; - double sampleValue = (m_gain*(pink/5)); - samples[sampleCount] = sampleValue * 32768; + for (int sampleCount = 0; sampleCount < count; sampleCount++) + { + double white = 2 * random.generateDouble() - 1; + + pinkNoiseBuffer[0] = 0.99886 * pinkNoiseBuffer[0] + white * 0.0555179; + pinkNoiseBuffer[1] = 0.99332 * pinkNoiseBuffer[1] + white * 0.0750759; + pinkNoiseBuffer[2] = 0.96900 * pinkNoiseBuffer[2] + white * 0.1538520; + pinkNoiseBuffer[3] = 0.86650 * pinkNoiseBuffer[3] + white * 0.3104856; + pinkNoiseBuffer[4] = 0.55000 * pinkNoiseBuffer[4] + white * 0.5329522; + pinkNoiseBuffer[5] = -0.7616 * pinkNoiseBuffer[5] - white * 0.0168980; + double pink = pinkNoiseBuffer[0] + pinkNoiseBuffer[1] + pinkNoiseBuffer[2] + pinkNoiseBuffer[3] + pinkNoiseBuffer[4] + pinkNoiseBuffer[5] + pinkNoiseBuffer[6] + white * 0.5362; + pinkNoiseBuffer[6] = white * 0.115926; + double sampleValue = (m_gain * (pink / 5)); + samples[sampleCount] = sampleValue * 32768; + } + return count; + } } - return count; } diff --git a/src/blacksound/sampleprovider/pinknoisegenerator.h b/src/blacksound/sampleprovider/pinknoisegenerator.h index 78e54a261..fc030449c 100644 --- a/src/blacksound/sampleprovider/pinknoisegenerator.h +++ b/src/blacksound/sampleprovider/pinknoisegenerator.h @@ -19,23 +19,29 @@ #include -//! Pink noise generator -class BLACKSOUND_EXPORT PinkNoiseGenerator : public ISampleProvider +namespace BlackSound { - Q_OBJECT + namespace SampleProvider + { + //! Pink noise generator + class BLACKSOUND_EXPORT CPinkNoiseGenerator : public ISampleProvider + { + Q_OBJECT -public: - //! Noise generator - PinkNoiseGenerator(QObject *parent = nullptr) : ISampleProvider(parent) {} + public: + //! Noise generator + CPinkNoiseGenerator(QObject *parent = nullptr) : ISampleProvider(parent) {} - virtual int readSamples(QVector &samples, qint64 count) override; + virtual int readSamples(QVector &samples, qint64 count) override; - void setGain(double gain) { m_gain = gain; } + void setGain(double gain) { m_gain = gain; } -private: - QRandomGenerator random; - std::array pinkNoiseBuffer = {0}; - double m_gain = 0.0; -}; + private: + QRandomGenerator random; + std::array pinkNoiseBuffer = {0}; + double m_gain = 0.0; + }; + } +} #endif // guard diff --git a/src/blacksound/sampleprovider/resourcesound.cpp b/src/blacksound/sampleprovider/resourcesound.cpp index 45ac7879c..919b3b27d 100644 --- a/src/blacksound/sampleprovider/resourcesound.cpp +++ b/src/blacksound/sampleprovider/resourcesound.cpp @@ -1,22 +1,39 @@ +/* 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 + #include "resourcesound.h" #include "audioutilities.h" -ResourceSound::ResourceSound(const QString &audioFileName) -{ - m_wavFile = new WavFile; - m_wavFile->open(audioFileName); - if (m_wavFile->fileFormat().sampleType() == QAudioFormat::Float) - { - m_samples = convertFloatBytesTo16BitPCM(m_wavFile->audioData()); - } - else - { - m_samples = convertBytesTo16BitPCM(m_wavFile->audioData()); - } +using namespace BlackSound::Wav; -} - -const QVector& ResourceSound::audioData() +namespace BlackSound { - return m_samples; + namespace SampleProvider + { + CResourceSound::CResourceSound(const QString &audioFileName) + { + m_wavFile = new WavFile; + m_wavFile->open(audioFileName); + if (m_wavFile->fileFormat().sampleType() == QAudioFormat::Float) + { + m_samples = convertFloatBytesTo16BitPCM(m_wavFile->audioData()); + } + else + { + m_samples = convertBytesTo16BitPCM(m_wavFile->audioData()); + } + } + + const QVector &CResourceSound::audioData() + { + return m_samples; + } + } } diff --git a/src/blacksound/sampleprovider/resourcesound.h b/src/blacksound/sampleprovider/resourcesound.h index 4d7d1108b..aaf246653 100644 --- a/src/blacksound/sampleprovider/resourcesound.h +++ b/src/blacksound/sampleprovider/resourcesound.h @@ -1,5 +1,15 @@ -#ifndef RESOURCESOUND_H -#define RESOURCESOUND_H +/* 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_RESOURCESOUND_H +#define BLACKSOUND_SAMPLEPROVIDER_RESOURCESOUND_H #include "blacksound/blacksoundexport.h" #include "blacksound/wav/wavfile.h" @@ -7,16 +17,24 @@ #include #include -class ResourceSound +namespace BlackSound { -public: - ResourceSound(const QString &audioFileName); + namespace SampleProvider + { + //! File from resources + class CResourceSound + { + public: + //! Sound of audio file + CResourceSound(const QString &audioFileName); - const QVector &audioData(); + const QVector &audioData(); -private: - WavFile *m_wavFile; - QVector m_samples; -}; + private: + Wav::WavFile *m_wavFile = nullptr; + QVector m_samples; + }; + } +} -#endif // RESOURCESOUND_H +#endif // guard diff --git a/src/blacksound/sampleprovider/resourcesoundsampleprovider.cpp b/src/blacksound/sampleprovider/resourcesoundsampleprovider.cpp index a1f0292e7..b96e8123a 100644 --- a/src/blacksound/sampleprovider/resourcesoundsampleprovider.cpp +++ b/src/blacksound/sampleprovider/resourcesoundsampleprovider.cpp @@ -1,76 +1,82 @@ #include "resourcesoundsampleprovider.h" #include -ResourceSoundSampleProvider::ResourceSoundSampleProvider(const ResourceSound &resourceSound, QObject *parent) : - ISampleProvider(parent), - m_resourceSound(resourceSound) +namespace BlackSound { - tempBuffer.resize(tempBufferSize); -} - -int ResourceSoundSampleProvider::readSamples(QVector &samples, qint64 count) -{ - if (count > tempBufferSize) + namespace SampleProvider { - qDebug() << "Count too large for temp buffer"; - return 0; - } - qint64 availableSamples = m_resourceSound.audioData().size() - position; - - qint64 samplesToCopy = qMin(availableSamples, count); - samples.clear(); - samples.fill(0, samplesToCopy); - - for (qint64 i = 0; i < samplesToCopy; i++) - { - tempBuffer[i] = m_resourceSound.audioData().at(position + i); - } - - if (m_gain != 1.0f) - { - for (int i = 0; i < samplesToCopy; i++) + CResourceSoundSampleProvider::CResourceSoundSampleProvider(const CResourceSound &resourceSound, QObject *parent) : + ISampleProvider(parent), + m_resourceSound(resourceSound) { - tempBuffer[i] *= m_gain; + tempBuffer.resize(tempBufferSize); + } + + int CResourceSoundSampleProvider::readSamples(QVector &samples, qint64 count) + { + if (count > tempBufferSize) + { + qDebug() << "Count too large for temp buffer"; + return 0; + } + qint64 availableSamples = m_resourceSound.audioData().size() - position; + + qint64 samplesToCopy = qMin(availableSamples, count); + samples.clear(); + samples.fill(0, samplesToCopy); + + for (qint64 i = 0; i < samplesToCopy; i++) + { + tempBuffer[i] = m_resourceSound.audioData().at(position + i); + } + + if (m_gain != 1.0f) + { + for (int i = 0; i < samplesToCopy; i++) + { + tempBuffer[i] *= m_gain; + } + } + + for (qint64 i = 0; i < samplesToCopy; i++) + { + samples[i] = tempBuffer.at(i); + } + + position += samplesToCopy; + + if (position > availableSamples - 1) + { + if (m_looping) { position = 0; } + else { m_isFinished = true; } + } + + return (int)samplesToCopy; + } + + bool CResourceSoundSampleProvider::isFinished() + { + return m_isFinished; + } + + bool CResourceSoundSampleProvider::looping() const + { + return m_looping; + } + + void CResourceSoundSampleProvider::setLooping(bool looping) + { + m_looping = looping; + } + + float CResourceSoundSampleProvider::gain() const + { + return m_gain; + } + + void CResourceSoundSampleProvider::setGain(float gain) + { + m_gain = gain; } } - - for (qint64 i = 0; i < samplesToCopy; i++) - { - samples[i] = tempBuffer.at(i); - } - - position += samplesToCopy; - - if (position > availableSamples - 1) - { - if (m_looping) { position = 0; } - else { m_isFinished = true; } - } - - return (int)samplesToCopy; -} - -bool ResourceSoundSampleProvider::isFinished() -{ - return m_isFinished; -} - -bool ResourceSoundSampleProvider::looping() const -{ - return m_looping; -} - -void ResourceSoundSampleProvider::setLooping(bool looping) -{ - m_looping = looping; -} - -float ResourceSoundSampleProvider::gain() const -{ - return m_gain; -} - -void ResourceSoundSampleProvider::setGain(float gain) -{ - m_gain = gain; } diff --git a/src/blacksound/sampleprovider/resourcesoundsampleprovider.h b/src/blacksound/sampleprovider/resourcesoundsampleprovider.h index b6dcfb47e..f795fe27c 100644 --- a/src/blacksound/sampleprovider/resourcesoundsampleprovider.h +++ b/src/blacksound/sampleprovider/resourcesoundsampleprovider.h @@ -1,37 +1,51 @@ -#ifndef RESOURCESOUNDSAMPLEPROVIDER_H -#define RESOURCESOUNDSAMPLEPROVIDER_H +/* 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. + */ + +#ifndef BLACKSOUND_SAMPLEPROVIDER_RESOURCESOUNDSAMPLEPROVIDER_H +#define BLACKSOUND_SAMPLEPROVIDER_RESOURCESOUNDSAMPLEPROVIDER_H #include "blacksound/blacksoundexport.h" #include "sampleprovider.h" #include "resourcesound.h" -//! A sample provider -class BLACKSOUND_EXPORT ResourceSoundSampleProvider : public ISampleProvider +namespace BlackSound { - Q_OBJECT + namespace SampleProvider + { + //! A sample provider + class BLACKSOUND_EXPORT CResourceSoundSampleProvider : public ISampleProvider + { + Q_OBJECT -public: - //! Ctor - ResourceSoundSampleProvider(const ResourceSound &resourceSound, QObject *parent = nullptr); + public: + //! Ctor + CResourceSoundSampleProvider(const CResourceSound &resourceSound, QObject *parent = nullptr); - virtual int readSamples(QVector &samples, qint64 count) override; - virtual bool isFinished() override; + virtual int readSamples(QVector &samples, qint64 count) override; + virtual bool isFinished() override; - bool looping() const; - void setLooping(bool looping); + bool looping() const; + void setLooping(bool looping); - float gain() const; - void setGain(float gain); + float gain() const; + void setGain(float gain); -private: - float m_gain = 1.0f; - bool m_looping = false; + private: + float m_gain = 1.0f; + bool m_looping = false; - ResourceSound m_resourceSound; - qint64 position = 0; - const int tempBufferSize = 9600; //9600 = 200ms - QVector tempBuffer; - bool m_isFinished = false; -}; + CResourceSound m_resourceSound; + qint64 position = 0; + const int tempBufferSize = 9600; //9600 = 200ms + QVector tempBuffer; + bool m_isFinished = false; + }; + } +} -#endif // RESOURCESOUNDSAMPLEPROVIDER_H +#endif // guard diff --git a/src/blacksound/sampleprovider/sampleprovider.h b/src/blacksound/sampleprovider/sampleprovider.h index 04d201bac..9fd610403 100644 --- a/src/blacksound/sampleprovider/sampleprovider.h +++ b/src/blacksound/sampleprovider/sampleprovider.h @@ -1,3 +1,13 @@ +/* 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 SAMPLEPROVIDER_H #define SAMPLEPROVIDER_H @@ -5,17 +15,24 @@ #include #include -class BLACKSOUND_EXPORT ISampleProvider : public QObject +namespace BlackSound { - Q_OBJECT + namespace SampleProvider + { + //! Sample provider interface + class BLACKSOUND_EXPORT ISampleProvider : public QObject + { + Q_OBJECT -public: - ISampleProvider(QObject *parent = nullptr) : QObject(parent) {} - virtual ~ISampleProvider() {} + public: + ISampleProvider(QObject *parent = nullptr) : QObject(parent) {} + virtual ~ISampleProvider() override {} - virtual int readSamples(QVector &samples, qint64 count) = 0; + virtual int readSamples(QVector &samples, qint64 count) = 0; - virtual bool isFinished() { return false; } -}; + virtual bool isFinished() { return false; } + }; + } +} -#endif // SAMPLEPROVIDER_H +#endif // guard diff --git a/src/blacksound/sampleprovider/samples.cpp b/src/blacksound/sampleprovider/samples.cpp index f1a29459e..87fe965c2 100644 --- a/src/blacksound/sampleprovider/samples.cpp +++ b/src/blacksound/sampleprovider/samples.cpp @@ -1,29 +1,43 @@ +/* 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 "samples.h" #include "blackmisc/directoryutils.h" -Samples &Samples::instance() +namespace BlackSound { - static Samples samples; - return samples; -} + namespace SampleProvider + { + Samples &Samples::instance() + { + static Samples samples; + return samples; + } -Samples::Samples() : - m_crackle(BlackMisc::CDirectoryUtils::soundFilesDirectory() + "/Crackle_f32.wav"), - m_click(BlackMisc::CDirectoryUtils::soundFilesDirectory() + "/Click_f32.wav"), - m_whiteNoise(BlackMisc::CDirectoryUtils::soundFilesDirectory() + "/WhiteNoise_f32.wav") -{ } + Samples::Samples() : + m_crackle(BlackMisc::CDirectoryUtils::soundFilesDirectory() + "/Crackle_f32.wav"), + m_click(BlackMisc::CDirectoryUtils::soundFilesDirectory() + "/Click_f32.wav"), + m_whiteNoise(BlackMisc::CDirectoryUtils::soundFilesDirectory() + "/WhiteNoise_f32.wav") + { } -ResourceSound Samples::click() const -{ - return m_click; -} + CResourceSound Samples::click() const + { + return m_click; + } -ResourceSound Samples::crackle() const -{ - return m_crackle; -} + CResourceSound Samples::crackle() const + { + return m_crackle; + } -ResourceSound Samples::whiteNoise() const -{ - return m_whiteNoise; + CResourceSound Samples::whiteNoise() const + { + return m_whiteNoise; + } + } } diff --git a/src/blacksound/sampleprovider/samples.h b/src/blacksound/sampleprovider/samples.h index aa69b03a4..88df6bc21 100644 --- a/src/blacksound/sampleprovider/samples.h +++ b/src/blacksound/sampleprovider/samples.h @@ -1,24 +1,40 @@ +/* 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 SAMPLES_H #define SAMPLES_H #include "blacksound/blacksoundexport.h" #include "resourcesound.h" -class BLACKSOUND_EXPORT Samples +namespace BlackSound { -public: - static Samples &instance(); + namespace SampleProvider + { + class BLACKSOUND_EXPORT Samples + { + public: + static Samples &instance(); - ResourceSound crackle() const; - ResourceSound click() const; - ResourceSound whiteNoise() const; + CResourceSound crackle() const; + CResourceSound click() const; + CResourceSound whiteNoise() const; -private: - Samples(); + private: + Samples(); - ResourceSound m_crackle; - ResourceSound m_click; - ResourceSound m_whiteNoise; -}; + CResourceSound m_crackle; + CResourceSound m_click; + CResourceSound m_whiteNoise; + }; + } +} #endif // SAMPLES_H diff --git a/src/blacksound/sampleprovider/sawtoothgenerator.cpp b/src/blacksound/sampleprovider/sawtoothgenerator.cpp index 3148c700c..66eaa72d2 100644 --- a/src/blacksound/sampleprovider/sawtoothgenerator.cpp +++ b/src/blacksound/sampleprovider/sawtoothgenerator.cpp @@ -1,23 +1,37 @@ +/* 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 "sawtoothgenerator.h" #include -SawToothGenerator::SawToothGenerator(double frequency, QObject *parent) : - ISampleProvider(parent), - m_frequency(frequency) -{} - -int SawToothGenerator::readSamples(QVector &samples, qint64 count) +namespace BlackSound { - samples.clear(); - samples.fill(0, count); - - for (int sampleCount = 0; sampleCount < count; sampleCount++) + namespace SampleProvider { - double multiple = 2 * m_frequency / m_sampleRate; - double sampleSaw = std::fmod((m_nSample * multiple), 2) - 1; - double sampleValue = m_gain * sampleSaw; - samples[sampleCount] = sampleValue * 32768; - m_nSample++; + CSawToothGenerator::CSawToothGenerator(double frequency, QObject *parent) : + ISampleProvider(parent), + m_frequency(frequency) + {} + + int CSawToothGenerator::readSamples(QVector &samples, qint64 count) + { + samples.clear(); + samples.fill(0, count); + + for (int sampleCount = 0; sampleCount < count; sampleCount++) + { + double multiple = 2 * m_frequency / m_sampleRate; + double sampleSaw = std::fmod((m_nSample * multiple), 2) - 1; + double sampleValue = m_gain * sampleSaw; + samples[sampleCount] = sampleValue * 32768; + m_nSample++; + } + return static_cast(count); + } } - return count; } diff --git a/src/blacksound/sampleprovider/sawtoothgenerator.h b/src/blacksound/sampleprovider/sawtoothgenerator.h index 4c078c136..cd04a3161 100644 --- a/src/blacksound/sampleprovider/sawtoothgenerator.h +++ b/src/blacksound/sampleprovider/sawtoothgenerator.h @@ -1,30 +1,45 @@ -#ifndef SAWTOOTHGENERATOR_H -#define SAWTOOTHGENERATOR_H +/* 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_SAWTOOTHGENERATOR_H +#define BLACKSOUND_SAMPLEPROVIDER_SAWTOOTHGENERATOR_H #include "blacksound/blacksoundexport.h" #include "blacksound/sampleprovider/sampleprovider.h" - #include #include - #include -class BLACKSOUND_EXPORT SawToothGenerator : public ISampleProvider +namespace BlackSound { - Q_OBJECT + namespace SampleProvider + { + //! Saw tooth generator + class BLACKSOUND_EXPORT CSawToothGenerator : public ISampleProvider + { + Q_OBJECT -public: - SawToothGenerator(double frequency, QObject *parent = nullptr); + public: + CSawToothGenerator(double frequency, QObject *parent = nullptr); - virtual int readSamples(QVector &samples, qint64 count) override; + virtual int readSamples(QVector &samples, qint64 count) override; - void setGain(double gain) { m_gain = gain; } + void setGain(double gain) { m_gain = gain; } -private: - double m_gain = 0.0; - double m_frequency = 0.0; - double m_sampleRate = 48000; - int m_nSample = 0; -}; + private: + double m_gain = 0.0; + double m_frequency = 0.0; + double m_sampleRate = 48000; + int m_nSample = 0; + }; + } +} -#endif // SAWTOOTHGENERATOR_H +#endif // guard diff --git a/src/blacksound/sampleprovider/simplecompressoreffect.cpp b/src/blacksound/sampleprovider/simplecompressoreffect.cpp index fd844cf6a..5d1ff01a4 100644 --- a/src/blacksound/sampleprovider/simplecompressoreffect.cpp +++ b/src/blacksound/sampleprovider/simplecompressoreffect.cpp @@ -1,45 +1,59 @@ +/* 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 "simplecompressoreffect.h" #include -SimpleCompressorEffect::SimpleCompressorEffect(ISampleProvider *source, QObject *parent) : - ISampleProvider(parent), - m_sourceStream(source) +namespace BlackSound { - m_simpleCompressor.setAttack(5.0); - m_simpleCompressor.setRelease(10.0); - m_simpleCompressor.setSampleRate(48000.0); - m_simpleCompressor.setThresh(16.0); - m_simpleCompressor.setRatio(6.0); - m_simpleCompressor.setMakeUpGain(16.0); - - m_timer.start(3000); -} - -int SimpleCompressorEffect::readSamples(QVector &samples, qint64 count) -{ - int samplesRead = m_sourceStream->readSamples(samples, count); - - if (m_enabled) + namespace SampleProvider { - for (int sample = 0; sample < samplesRead; sample+=channels) + CSimpleCompressorEffect::CSimpleCompressorEffect(ISampleProvider *source, QObject *parent) : + ISampleProvider(parent), + m_sourceStream(source) { - double in1 = samples.at(sample) / 32768.0; - double in2 = (channels == 1) ? 0 : samples.at(sample+1); - m_simpleCompressor.process(in1, in2); - samples[sample] = in1 * 32768.0; - if (channels > 1) - samples[sample + 1] = in2 * 32768.0f; + m_simpleCompressor.setAttack(5.0); + m_simpleCompressor.setRelease(10.0); + m_simpleCompressor.setSampleRate(48000.0); + m_simpleCompressor.setThresh(16.0); + m_simpleCompressor.setRatio(6.0); + m_simpleCompressor.setMakeUpGain(16.0); + + m_timer.start(3000); + } + + int CSimpleCompressorEffect::readSamples(QVector &samples, qint64 count) + { + int samplesRead = m_sourceStream->readSamples(samples, count); + + if (m_enabled) + { + for (int sample = 0; sample < samplesRead; sample += channels) + { + double in1 = samples.at(sample) / 32768.0; + double in2 = (channels == 1) ? 0 : samples.at(sample + 1); + m_simpleCompressor.process(in1, in2); + samples[sample] = in1 * 32768.0; + if (channels > 1) + samples[sample + 1] = in2 * 32768.0f; + } + } + return samplesRead; + } + + void CSimpleCompressorEffect::setEnabled(bool enabled) + { + m_enabled = enabled; + } + + void CSimpleCompressorEffect::setMakeUpGain(double gain) + { + m_simpleCompressor.setMakeUpGain(gain); } } - return samplesRead; -} - -void SimpleCompressorEffect::setEnabled(bool enabled) -{ - m_enabled = enabled; -} - -void SimpleCompressorEffect::setMakeUpGain(double gain) -{ - m_simpleCompressor.setMakeUpGain(gain); } diff --git a/src/blacksound/sampleprovider/simplecompressoreffect.h b/src/blacksound/sampleprovider/simplecompressoreffect.h index 93fd98ce5..821689df1 100644 --- a/src/blacksound/sampleprovider/simplecompressoreffect.h +++ b/src/blacksound/sampleprovider/simplecompressoreffect.h @@ -1,5 +1,15 @@ -#ifndef SIMPLECOMPRESSOREFFECT_H -#define SIMPLECOMPRESSOREFFECT_H +/* 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_SIMPLECOMPRESSOREFFECT_H +#define BLACKSOUND_SAMPLEPROVIDER_SIMPLECOMPRESSOREFFECT_H #include "blacksound/blacksoundexport.h" #include "sampleprovider.h" @@ -8,25 +18,31 @@ #include #include -class BLACKSOUND_EXPORT SimpleCompressorEffect : public ISampleProvider +namespace BlackSound { - Q_OBJECT + namespace SampleProvider + { + class BLACKSOUND_EXPORT CSimpleCompressorEffect : public ISampleProvider + { + Q_OBJECT -public: - SimpleCompressorEffect(ISampleProvider *source, QObject *parent = nullptr); + public: + CSimpleCompressorEffect(ISampleProvider *source, QObject *parent = nullptr); - virtual int readSamples(QVector &samples, qint64 count) override; + virtual int readSamples(QVector &samples, qint64 count) override; - void setEnabled(bool enabled); - void setMakeUpGain(double gain); + void setEnabled(bool enabled); + void setMakeUpGain(double gain); -private: + private: - QTimer m_timer; - ISampleProvider *m_sourceStream; - bool m_enabled = true; - chunkware_simple::SimpleComp m_simpleCompressor; - const int channels = 1; -}; + QTimer m_timer; + ISampleProvider *m_sourceStream; + bool m_enabled = true; + chunkware_simple::SimpleComp m_simpleCompressor; + const int channels = 1; + }; + } +} -#endif // SIMPLECOMPRESSOREFFECT_H +#endif // guard diff --git a/src/blacksound/sampleprovider/volumesampleprovider.cpp b/src/blacksound/sampleprovider/volumesampleprovider.cpp index efddfbc9a..9a9c1d4e3 100644 --- a/src/blacksound/sampleprovider/volumesampleprovider.cpp +++ b/src/blacksound/sampleprovider/volumesampleprovider.cpp @@ -8,33 +8,30 @@ //! \file +#include "volumesampleprovider.h" #include "volumesampleprovider.h" -VolumeSampleProvider::VolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent) : - ISampleProvider(parent), - m_sourceProvider(sourceProvider) -{ } - -int VolumeSampleProvider::readSamples(QVector &samples, qint64 count) +namespace BlackSound { - int samplesRead = m_sourceProvider->readSamples(samples, count); - - if (! qFuzzyCompare(m_volume, 1.0)) + namespace SampleProvider { - for (int n = 0; n < samplesRead; n++) + CVolumeSampleProvider::CVolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent) : + ISampleProvider(parent), + m_sourceProvider(sourceProvider) + { } + + int CVolumeSampleProvider::readSamples(QVector &samples, qint64 count) { - samples[n] *= m_volume; + int samplesRead = m_sourceProvider->readSamples(samples, count); + + if (! qFuzzyCompare(m_volume, 1.0)) + { + for (int n = 0; n < samplesRead; n++) + { + samples[n] *= m_volume; + } + } + return samplesRead; } } - return samplesRead; -} - -double VolumeSampleProvider::volume() const -{ - return m_volume; -} - -void VolumeSampleProvider::setVolume(double volume) -{ - m_volume = volume; } diff --git a/src/blacksound/sampleprovider/volumesampleprovider.h b/src/blacksound/sampleprovider/volumesampleprovider.h index 07b06a15a..33b7c2234 100644 --- a/src/blacksound/sampleprovider/volumesampleprovider.h +++ b/src/blacksound/sampleprovider/volumesampleprovider.h @@ -8,29 +8,35 @@ //! \file -#ifndef VOLUMESAMPLEPROVIDER_H -#define VOLUMESAMPLEPROVIDER_H +#ifndef BLACKSOUND_SAMPLEPROVIDER_VOLUMESAMPLEPROVIDER_H +#define BLACKSOUND_SAMPLEPROVIDER_VOLUMESAMPLEPROVIDER_H #include "blacksound/blacksoundexport.h" #include "blacksound/sampleprovider/sampleprovider.h" -//! Pink noise generator -class BLACKSOUND_EXPORT VolumeSampleProvider : public ISampleProvider +namespace BlackSound { - Q_OBJECT + namespace SampleProvider + { + //! Pink noise generator + class BLACKSOUND_EXPORT CVolumeSampleProvider : public ISampleProvider + { + Q_OBJECT -public: - //! Noise generator - VolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent = nullptr); + public: + //! Noise generator + CVolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent = nullptr); - virtual int readSamples(QVector &samples, qint64 count) override; + virtual int readSamples(QVector &samples, qint64 count) override; - double volume() const; - void setVolume(double volume); + double volume() const { return m_volume; } + void setVolume(double volume) { m_volume = volume; } -private: - ISampleProvider *m_sourceProvider; - double m_volume = 1.0; -}; + private: + ISampleProvider *m_sourceProvider = nullptr; + double m_volume = 1.0; + }; + } +} #endif // guard diff --git a/src/blacksound/wav/wavfile.cpp b/src/blacksound/wav/wavfile.cpp index ff34221cb..5033687c4 100644 --- a/src/blacksound/wav/wavfile.cpp +++ b/src/blacksound/wav/wavfile.cpp @@ -1,133 +1,147 @@ +/* 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 #include #include // #include "utils.h" #include "wavfile.h" -struct chunk +namespace BlackSound { - char id[4]; - quint32 size; -}; - -struct RIFFHeader -{ - chunk descriptor; // "RIFF" - char type[4]; // "WAVE" -}; - -struct WAVEHeader -{ - chunk descriptor; - quint16 audioFormat; - quint16 numChannels; - quint32 sampleRate; - quint32 byteRate; - quint16 blockAlign; - quint16 bitsPerSample; -}; - -struct DATAHeader -{ - chunk descriptor; -}; - -struct CombinedHeader -{ - RIFFHeader riff; - WAVEHeader wave; -}; - -WavFile::WavFile(QObject *parent) : - QFile(parent), - m_headerLength(0) -{ } - -bool WavFile::open(const QString &fileName) -{ - close(); - setFileName(fileName); - return QFile::open(QIODevice::ReadOnly) && readHeader(); -} - -const QAudioFormat &WavFile::fileFormat() const -{ - return m_fileFormat; -} - -qint64 WavFile::headerLength() const -{ -return m_headerLength; -} - -bool WavFile::readHeader() -{ - seek(0); - CombinedHeader header; - DATAHeader dataHeader; - bool result = read(reinterpret_cast(&header), sizeof(CombinedHeader)) == sizeof(CombinedHeader); - if (result) + namespace Wav { - if ((memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0 - || memcmp(&header.riff.descriptor.id, "RIFX", 4) == 0) - && memcmp(&header.riff.type, "WAVE", 4) == 0 - && memcmp(&header.wave.descriptor.id, "fmt ", 4) == 0 - && (header.wave.audioFormat == 1 || header.wave.audioFormat == 0 || header.wave.audioFormat == 3)) + struct chunk { - // Read off remaining header information - if (qFromLittleEndian(header.wave.descriptor.size) > sizeof(WAVEHeader)) + char id[4]; + quint32 size; + }; + + struct RIFFHeader + { + chunk descriptor; // "RIFF" + char type[4]; // "WAVE" + }; + + struct WAVEHeader + { + chunk descriptor; + quint16 audioFormat; + quint16 numChannels; + quint32 sampleRate; + quint32 byteRate; + quint16 blockAlign; + quint16 bitsPerSample; + }; + + struct DATAHeader + { + chunk descriptor; + }; + + struct CombinedHeader + { + RIFFHeader riff; + WAVEHeader wave; + }; + + WavFile::WavFile(QObject *parent) : + QFile(parent), + m_headerLength(0) + { } + + bool WavFile::open(const QString &fileName) + { + close(); + setFileName(fileName); + return QFile::open(QIODevice::ReadOnly) && readHeader(); + } + + const QAudioFormat &WavFile::fileFormat() const + { + return m_fileFormat; + } + + qint64 WavFile::headerLength() const + { + return m_headerLength; + } + + bool WavFile::readHeader() + { + seek(0); + CombinedHeader header; + DATAHeader dataHeader; + bool result = read(reinterpret_cast(&header), sizeof(CombinedHeader)) == sizeof(CombinedHeader); + if (result) { - // Extended data available - quint16 extraFormatBytes; - if (peek((char*)&extraFormatBytes, sizeof(quint16)) != sizeof(quint16)) - return false; - const qint64 throwAwayBytes = sizeof(quint16) + qFromLittleEndian(extraFormatBytes); - if (read(throwAwayBytes).size() != throwAwayBytes) + if ((memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0 + || memcmp(&header.riff.descriptor.id, "RIFX", 4) == 0) + && memcmp(&header.riff.type, "WAVE", 4) == 0 + && memcmp(&header.wave.descriptor.id, "fmt ", 4) == 0 + && (header.wave.audioFormat == 1 || header.wave.audioFormat == 0 || header.wave.audioFormat == 3)) + { + // Read off remaining header information + if (qFromLittleEndian(header.wave.descriptor.size) > sizeof(WAVEHeader)) + { + // Extended data available + quint16 extraFormatBytes; + if (peek((char *)&extraFormatBytes, sizeof(quint16)) != sizeof(quint16)) + return false; + const qint64 throwAwayBytes = sizeof(quint16) + qFromLittleEndian(extraFormatBytes); + if (read(throwAwayBytes).size() != throwAwayBytes) + return false; + } + + if (read((char *)&dataHeader, sizeof(DATAHeader)) != sizeof(DATAHeader)) + return false; + + // Establish format + if (memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0) + m_fileFormat.setByteOrder(QAudioFormat::LittleEndian); + else + m_fileFormat.setByteOrder(QAudioFormat::BigEndian); + + int bps = qFromLittleEndian(header.wave.bitsPerSample); + m_fileFormat.setChannelCount(qFromLittleEndian(header.wave.numChannels)); + m_fileFormat.setCodec("audio/pcm"); + m_fileFormat.setSampleRate(qFromLittleEndian(header.wave.sampleRate)); + m_fileFormat.setSampleSize(qFromLittleEndian(header.wave.bitsPerSample)); + + if (header.wave.audioFormat == 1 || header.wave.audioFormat == 0) + { + m_fileFormat.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt); + } + else + { + m_fileFormat.setSampleType(QAudioFormat::Float); + } + + } + else + { + result = false; + } + } + m_headerLength = pos(); + + if (memcmp(&dataHeader.descriptor.id, "data", 4) == 0) + { + qint32 dataLength = qFromLittleEndian(dataHeader.descriptor.size); + m_audioData = read(dataLength); + if (m_audioData.size() != dataLength) + { return false; + m_audioData.clear(); + } } - if (read((char*)&dataHeader, sizeof(DATAHeader)) != sizeof(DATAHeader)) - return false; - - // Establish format - if (memcmp(&header.riff.descriptor.id, "RIFF", 4) == 0) - m_fileFormat.setByteOrder(QAudioFormat::LittleEndian); - else - m_fileFormat.setByteOrder(QAudioFormat::BigEndian); - - int bps = qFromLittleEndian(header.wave.bitsPerSample); - m_fileFormat.setChannelCount(qFromLittleEndian(header.wave.numChannels)); - m_fileFormat.setCodec("audio/pcm"); - m_fileFormat.setSampleRate(qFromLittleEndian(header.wave.sampleRate)); - m_fileFormat.setSampleSize(qFromLittleEndian(header.wave.bitsPerSample)); - - if (header.wave.audioFormat == 1 || header.wave.audioFormat == 0) - { - m_fileFormat.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt); - } - else - { - m_fileFormat.setSampleType(QAudioFormat::Float); - } - + return result; } - else - { - result = false; - } - } - m_headerLength = pos(); - - if (memcmp(&dataHeader.descriptor.id, "data", 4) == 0) - { - qint32 dataLength = qFromLittleEndian(dataHeader.descriptor.size); - m_audioData = read(dataLength); - if (m_audioData.size() != dataLength) - { - return false; - m_audioData.clear(); - } - } - - return result; -} + } // ns +} // ns diff --git a/src/blacksound/wav/wavfile.h b/src/blacksound/wav/wavfile.h index e90151cae..c7adf7169 100644 --- a/src/blacksound/wav/wavfile.h +++ b/src/blacksound/wav/wavfile.h @@ -1,3 +1,13 @@ +/* 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 WAVFILE_H #define WAVFILE_H @@ -5,24 +15,32 @@ #include #include -class WavFile : public QFile +namespace BlackSound { -public: - WavFile(QObject *parent = 0); + namespace Wav + { + //! * WAV file + class WavFile : public QFile + { + public: + //! Ctor + WavFile(QObject *parent = nullptr); - using QFile::open; - bool open(const QString &fileName); - const QAudioFormat &fileFormat() const; - qint64 headerLength() const; - QByteArray audioData() { return m_audioData; } + using QFile::open; + bool open(const QString &fileName); + const QAudioFormat &fileFormat() const; + qint64 headerLength() const; + QByteArray audioData() { return m_audioData; } -private: - bool readHeader(); + private: + bool readHeader(); -private: - QAudioFormat m_fileFormat; - qint64 m_headerLength; - QByteArray m_audioData; -}; + private: + QAudioFormat m_fileFormat; + qint64 m_headerLength; + QByteArray m_audioData; + }; + } // ns +} // ns -#endif // WAVFILE_H +#endif // guard