mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 04:25:42 +08:00
[AFV] misc style issues:
* object name * simple style fixes * some renamings * comments
This commit is contained in:
committed by
Mat Sutcliffe
parent
c1622951b3
commit
7d51bedc3e
@@ -1,4 +1,5 @@
|
||||
#include "bufferedwaveprovider.h"
|
||||
#include "blacksound/audioutilities.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
@@ -9,6 +10,9 @@ namespace BlackSound
|
||||
CBufferedWaveProvider::CBufferedWaveProvider(const QAudioFormat &format, QObject *parent) :
|
||||
ISampleProvider(parent)
|
||||
{
|
||||
const QString on = QStringLiteral("%1 format: ").arg(this->metaObject()->className(), BlackSound::toQString(format));
|
||||
this->setObjectName(on);
|
||||
|
||||
// Set buffer size to 10 secs
|
||||
m_maxBufferSize = format.bytesForDuration(10 * 1000 * 1000);
|
||||
}
|
||||
|
||||
@@ -11,13 +11,17 @@ namespace BlackSound
|
||||
CEqualizerSampleProvider::CEqualizerSampleProvider(ISampleProvider *sourceProvider, EqualizerPresets preset, QObject *parent) :
|
||||
ISampleProvider(parent)
|
||||
{
|
||||
Q_ASSERT_X(sourceProvider, Q_FUNC_INFO, "Need provider");
|
||||
const QString on = QStringLiteral("%1 of %2").arg(this->metaObject()->className(), sourceProvider->objectName());
|
||||
this->setObjectName(on);
|
||||
|
||||
m_sourceProvider = sourceProvider;
|
||||
setupPreset(preset);
|
||||
}
|
||||
|
||||
int CEqualizerSampleProvider::readSamples(QVector<float> &samples, qint64 count)
|
||||
{
|
||||
int samplesRead = m_sourceProvider->readSamples(samples, count);
|
||||
const int samplesRead = m_sourceProvider->readSamples(samples, count);
|
||||
if (m_bypass) return samplesRead;
|
||||
|
||||
for (int n = 0; n < samplesRead; n++)
|
||||
@@ -26,7 +30,7 @@ namespace BlackSound
|
||||
{
|
||||
samples[n] = m_filters[band].transform(samples[n]);
|
||||
}
|
||||
samples[n] *= m_outputGain;
|
||||
samples[n] *= static_cast<float>(m_outputGain);
|
||||
}
|
||||
return samplesRead;
|
||||
}
|
||||
|
||||
@@ -7,11 +7,29 @@
|
||||
*/
|
||||
|
||||
#include "mixingsampleprovider.h"
|
||||
#include "blackmisc/metadatautils.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackSound
|
||||
{
|
||||
namespace SampleProvider
|
||||
{
|
||||
CMixingSampleProvider::CMixingSampleProvider(QObject *parent) : ISampleProvider(parent)
|
||||
{
|
||||
const QString on = QStringLiteral("%1").arg(classNameShort(this));
|
||||
this->setObjectName(on);
|
||||
}
|
||||
|
||||
void CMixingSampleProvider::addMixerInput(ISampleProvider *provider)
|
||||
{
|
||||
Q_ASSERT(provider);
|
||||
m_sources.append(provider);
|
||||
|
||||
const QString on = QStringLiteral("%1 sources: %2").arg(classNameShort(this)).arg(m_sources.size());
|
||||
this->setObjectName(on);
|
||||
}
|
||||
|
||||
int CMixingSampleProvider::readSamples(QVector<float> &samples, qint64 count)
|
||||
{
|
||||
samples.clear();
|
||||
@@ -23,15 +41,14 @@ namespace BlackSound
|
||||
{
|
||||
ISampleProvider *sampleProvider = m_sources.at(i);
|
||||
QVector<float> sourceBuffer;
|
||||
int len = sampleProvider->readSamples(sourceBuffer, count);
|
||||
|
||||
const int len = sampleProvider->readSamples(sourceBuffer, count);
|
||||
for (int n = 0; n < len; n++)
|
||||
{
|
||||
samples[n] += sourceBuffer[n];
|
||||
}
|
||||
|
||||
outputLen = qMax(len, outputLen);
|
||||
|
||||
if (sampleProvider->isFinished())
|
||||
{
|
||||
finishedProviders.push_back(sampleProvider);
|
||||
|
||||
@@ -25,10 +25,10 @@ namespace BlackSound
|
||||
{
|
||||
public:
|
||||
//! Ctor mixing provider
|
||||
CMixingSampleProvider(QObject *parent = nullptr) : ISampleProvider(parent) {}
|
||||
CMixingSampleProvider(QObject *parent = nullptr);
|
||||
|
||||
//! Add a provider
|
||||
void addMixerInput(ISampleProvider *provider) { m_sources.append(provider); }
|
||||
void addMixerInput(ISampleProvider *provider);
|
||||
|
||||
//! \copydoc ISampleProvider::readSamples
|
||||
virtual int readSamples(QVector<float> &samples, qint64 count) override;
|
||||
|
||||
@@ -54,6 +54,12 @@ namespace BlackSound
|
||||
return true;
|
||||
}
|
||||
|
||||
const QString &CResourceSound::getFileName() const
|
||||
{
|
||||
static const QString empty;
|
||||
return m_data ? empty : m_data->fileName;
|
||||
}
|
||||
|
||||
bool CResourceSound::isSameFileName(const QString &fn) const
|
||||
{
|
||||
if (fn.isEmpty()) { return false; }
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace BlackSound
|
||||
const QVector<float> &audioData() const { return m_data->samples; }
|
||||
|
||||
//! Corresponding file
|
||||
const QString &getFileName() { return m_data->fileName; }
|
||||
const QString &getFileName() const;
|
||||
|
||||
//! Is same file?
|
||||
bool isSameFileName(const QString &fn) const;
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
/* 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 "resourcesoundsampleprovider.h"
|
||||
#include "resourcesoundsampleprovider.h"
|
||||
#include "blackmisc/metadatautils.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackSound
|
||||
{
|
||||
namespace SampleProvider
|
||||
@@ -10,21 +21,21 @@ namespace BlackSound
|
||||
ISampleProvider(parent),
|
||||
m_resourceSound(resourceSound)
|
||||
{
|
||||
const QString on = QStringLiteral("%1 %2").arg(classNameShort(this), resourceSound.getFileName());
|
||||
this->setObjectName(on);
|
||||
m_tempBuffer.resize(m_tempBufferSize);
|
||||
}
|
||||
|
||||
int CResourceSoundSampleProvider::readSamples(QVector<float> &samples, qint64 count)
|
||||
{
|
||||
if (! m_resourceSound.isLoaded()) { return 0; }
|
||||
|
||||
if (!m_resourceSound.isLoaded()) { return 0; }
|
||||
if (count > m_tempBufferSize)
|
||||
{
|
||||
qDebug() << "Count too large for temp buffer" << count;
|
||||
return 0;
|
||||
}
|
||||
qint64 availableSamples = m_resourceSound.audioData().size() - m_position;
|
||||
|
||||
const qint64 samplesToCopy = qMin(availableSamples, count);
|
||||
const qint64 availableSamples = m_resourceSound.audioData().size() - m_position;
|
||||
const qint64 samplesToCopy = qMin(availableSamples, count);
|
||||
samples.clear();
|
||||
samples.fill(0, static_cast<int>(samplesToCopy));
|
||||
|
||||
@@ -37,7 +48,7 @@ namespace BlackSound
|
||||
{
|
||||
for (int i = 0; i < samplesToCopy; i++)
|
||||
{
|
||||
m_tempBuffer[i] *= m_gain;
|
||||
m_tempBuffer[i] = static_cast<float>(m_gain * m_tempBuffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,22 @@
|
||||
*/
|
||||
|
||||
#include "sinusgenerator.h"
|
||||
#include "blackmisc/metadatautils.h"
|
||||
#include <cmath>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackSound
|
||||
{
|
||||
namespace SampleProvider
|
||||
{
|
||||
CSinusGenerator::CSinusGenerator(double frequency, QObject *parent) :
|
||||
CSinusGenerator::CSinusGenerator(double frequencyHz, QObject *parent) :
|
||||
ISampleProvider(parent),
|
||||
m_frequency(frequency)
|
||||
{}
|
||||
m_frequencyHz(frequencyHz)
|
||||
{
|
||||
const QString on = QStringLiteral("%1 frequency: %2Hz").arg(classNameShort(this)).arg(frequencyHz);
|
||||
this->setObjectName(on);
|
||||
}
|
||||
|
||||
int CSinusGenerator::readSamples(QVector<float> &samples, qint64 count)
|
||||
{
|
||||
@@ -25,17 +31,17 @@ namespace BlackSound
|
||||
|
||||
for (int sampleCount = 0; sampleCount < count; sampleCount++)
|
||||
{
|
||||
double multiple = m_twoPi * m_frequency / m_sampleRate;
|
||||
double sampleValue = m_gain * qSin(m_nSample * multiple);
|
||||
samples[sampleCount] = static_cast<float>(sampleValue);
|
||||
const double multiple = s_twoPi * m_frequencyHz / m_sampleRate;
|
||||
const double sampleValue = m_gain * qSin(m_nSample * multiple);
|
||||
samples[sampleCount] = static_cast<float>(sampleValue);
|
||||
m_nSample++;
|
||||
}
|
||||
return static_cast<int>(count);
|
||||
}
|
||||
|
||||
void CSinusGenerator::setFrequency(double frequency)
|
||||
void CSinusGenerator::setFrequency(double frequencyHz)
|
||||
{
|
||||
m_frequency = frequency;
|
||||
m_frequencyHz = frequencyHz;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace BlackSound
|
||||
|
||||
public:
|
||||
//! Ctor
|
||||
CSinusGenerator(double frequency, QObject *parent = nullptr);
|
||||
CSinusGenerator(double frequencyHz, QObject *parent = nullptr);
|
||||
|
||||
//! \copydoc ISampleProvider::readSamples
|
||||
virtual int readSamples(QVector<float> &samples, qint64 count) override;
|
||||
@@ -36,14 +36,14 @@ namespace BlackSound
|
||||
void setGain(double gain) { m_gain = gain; }
|
||||
|
||||
//! Set frequency in Hz
|
||||
void setFrequency(double frequency);
|
||||
void setFrequency(double frequencyHz);
|
||||
|
||||
private:
|
||||
double m_gain = 0.0;
|
||||
double m_frequency = 0.0;
|
||||
double m_sampleRate = 48000;
|
||||
int m_nSample = 0;
|
||||
const double m_twoPi = 2 * M_PI;
|
||||
double m_gain = 0.0;
|
||||
double m_frequencyHz = 0.0;
|
||||
double m_sampleRate = 48000;
|
||||
int m_nSample = 0;
|
||||
static constexpr double s_twoPi = 2 * M_PI;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
//! \file
|
||||
|
||||
#include "volumesampleprovider.h"
|
||||
#include "volumesampleprovider.h"
|
||||
#include "blackmisc/metadatautils.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackSound
|
||||
{
|
||||
@@ -18,17 +20,20 @@ namespace BlackSound
|
||||
CVolumeSampleProvider::CVolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent) :
|
||||
ISampleProvider(parent),
|
||||
m_sourceProvider(sourceProvider)
|
||||
{ }
|
||||
{
|
||||
Q_ASSERT_X(sourceProvider, Q_FUNC_INFO, "Need source provider");
|
||||
const QString on = QStringLiteral("%1 with source: %2").arg(classNameShort(this), sourceProvider->objectName());
|
||||
this->setObjectName(on);
|
||||
}
|
||||
|
||||
int CVolumeSampleProvider::readSamples(QVector<float> &samples, qint64 count)
|
||||
{
|
||||
int samplesRead = m_sourceProvider->readSamples(samples, count);
|
||||
|
||||
const int samplesRead = m_sourceProvider->readSamples(samples, count);
|
||||
if (!qFuzzyCompare(m_volume, 1.0))
|
||||
{
|
||||
for (int n = 0; n < samplesRead; n++)
|
||||
{
|
||||
samples[n] *= static_cast<float>(m_volume);
|
||||
samples[n] = static_cast<float>(m_volume * samples[n]);
|
||||
}
|
||||
}
|
||||
return samplesRead;
|
||||
|
||||
Reference in New Issue
Block a user