Implement VolumeSampleProvider to gain in and output

fixup! Implement VolumeSampleProvider to gain in and output
This commit is contained in:
Roland Rossgotterer
2019-09-20 21:46:51 +02:00
committed by Mat Sutcliffe
parent 8b1fb1baca
commit 8d1eea25b1
6 changed files with 119 additions and 31 deletions

View File

@@ -0,0 +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
#include "volumesampleprovider.h"
VolumeSampleProvider::VolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent) :
ISampleProvider(parent),
m_sourceProvider(sourceProvider)
{ }
int VolumeSampleProvider::readSamples(QVector<qint16> &samples, qint64 count)
{
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;
}
double VolumeSampleProvider::volume() const
{
return m_volume;
}
void VolumeSampleProvider::setVolume(double volume)
{
m_volume = volume;
}

View File

@@ -0,0 +1,36 @@
/* 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 VOLUMESAMPLEPROVIDER_H
#define VOLUMESAMPLEPROVIDER_H
#include "blacksound/blacksoundexport.h"
#include "blacksound/sampleprovider/sampleprovider.h"
//! Pink noise generator
class BLACKSOUND_EXPORT VolumeSampleProvider : public ISampleProvider
{
Q_OBJECT
public:
//! Noise generator
VolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent = nullptr);
virtual int readSamples(QVector<qint16> &samples, qint64 count) override;
double volume() const;
void setVolume(double volume);
private:
ISampleProvider *m_sourceProvider;
double m_volume = 1.0;
};
#endif // guard