mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 18:25:37 +08:00
refactor: Rename BlackSound to swift::sound
This commit is contained in:
40
src/sound/sampleprovider/volumesampleprovider.cpp
Normal file
40
src/sound/sampleprovider/volumesampleprovider.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||
|
||||
//! \file
|
||||
|
||||
#include "volumesampleprovider.h"
|
||||
#include "blackmisc/metadatautils.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace swift::sound::sample_provider
|
||||
{
|
||||
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)
|
||||
{
|
||||
const int samplesRead = m_sourceProvider->readSamples(samples, count);
|
||||
if (!qFuzzyCompare(m_gainRatio, 1.0))
|
||||
{
|
||||
for (int n = 0; n < samplesRead; n++)
|
||||
{
|
||||
samples[n] = static_cast<float>(m_gainRatio * samples[n]);
|
||||
}
|
||||
}
|
||||
return samplesRead;
|
||||
}
|
||||
|
||||
bool CVolumeSampleProvider::setGainRatio(double volume)
|
||||
{
|
||||
const bool changed = !qFuzzyCompare(m_gainRatio, volume);
|
||||
if (changed) { m_gainRatio = volume; }
|
||||
return changed;
|
||||
}
|
||||
} // ns
|
||||
Reference in New Issue
Block a user