swift
Loading...
Searching...
No Matches
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
7
9
10using namespace swift::misc;
11
12namespace swift::sound::sample_provider
13{
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
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++)
28 {
29 samples[n] = static_cast<float>(m_gainRatio * samples[n]);
30 }
31 }
32 return samplesRead;
33 }
34
36 {
37 const bool changed = !qFuzzyCompare(m_gainRatio, volume);
38 if (changed)
39 {
40 m_gainRatio = volume;
41 }
42 return changed;
43 }
44} // namespace swift::sound::sample_provider
bool setGainRatio(double gainRatio)
Gain ratio, value a amplitude need to be multiplied with.
int readSamples(QVector< float > &samples, qint64 count)
Read samples.
CVolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent=nullptr)
Noise generator.
ISampleProvider(QObject *parent=nullptr)
Ctor.
Free functions in swift::misc.
QString classNameShort(const QObject *object)
Class name as from QMetaObject::className without namespace.
QObject(QObject *parent)
QObject * parent() const const
void setObjectName(QAnyStringView name)
QString arg(Args &&... args) const const