swift
volumesampleprovider.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include "volumesampleprovider.h"
7 
8 #include "misc/metadatautils.h"
9 
10 using namespace swift::misc;
11 
12 namespace swift::sound::sample_provider
13 {
14  CVolumeSampleProvider::CVolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent)
15  : ISampleProvider(parent), m_sourceProvider(sourceProvider)
16  {
17  Q_ASSERT_X(sourceProvider, Q_FUNC_INFO, "Need source provider");
18  const QString on = QStringLiteral("%1 with source: %2").arg(classNameShort(this), sourceProvider->objectName());
19  this->setObjectName(on);
20  }
21 
22  int CVolumeSampleProvider::readSamples(QVector<float> &samples, qint64 count)
23  {
24  const int samplesRead = m_sourceProvider->readSamples(samples, count);
25  if (!qFuzzyCompare(m_gainRatio, 1.0))
26  {
27  for (int n = 0; n < samplesRead; n++) { samples[n] = static_cast<float>(m_gainRatio * samples[n]); }
28  }
29  return samplesRead;
30  }
31 
33  {
34  const bool changed = !qFuzzyCompare(m_gainRatio, volume);
35  if (changed) { m_gainRatio = volume; }
36  return changed;
37  }
38 } // namespace swift::sound::sample_provider
bool setGainRatio(double gainRatio)
Gain ratio, value a amplitude need to be multiplied with.
virtual int readSamples(QVector< float > &samples, qint64 count)
Read samples.
virtual int readSamples(QVector< float > &samples, qint64 count)=0
Read samples.
Free functions in swift::misc.
QString classNameShort(const QObject *object)
Class name as from QMetaObject::className without namespace.