mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
Implement VolumeSampleProvider to gain in and output
fixup! Implement VolumeSampleProvider to gain in and output
This commit is contained in:
committed by
Mat Sutcliffe
parent
8b1fb1baca
commit
8d1eea25b1
40
src/blacksound/sampleprovider/volumesampleprovider.cpp
Normal file
40
src/blacksound/sampleprovider/volumesampleprovider.cpp
Normal 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;
|
||||
}
|
||||
36
src/blacksound/sampleprovider/volumesampleprovider.h
Normal file
36
src/blacksound/sampleprovider/volumesampleprovider.h
Normal 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
|
||||
Reference in New Issue
Block a user