swift
Loading...
Searching...
No Matches
simplecompressoreffect.cpp
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 <QDebug>
7
8namespace swift::sound::sample_provider
9{
11 : ISampleProvider(parent), m_sourceStream(source)
12 {
13
14 this->setObjectName("CSimpleCompressorEffect");
15 m_timer = new QTimer(this);
16 m_timer->setObjectName(this->objectName() + ":m_timer");
17
18 m_simpleCompressor.setAttack(5.0);
19 m_simpleCompressor.setRelease(10.0);
20 m_simpleCompressor.setSampleRate(48000.0);
21 m_simpleCompressor.setThresh(16.0);
22 m_simpleCompressor.setRatio(6.0);
23 m_simpleCompressor.setMakeUpGain(16.0);
24 m_timer->start(3000);
25 }
26
28 {
29 int samplesRead = m_sourceStream->readSamples(samples, count);
30
31 if (m_enabled)
32 {
33 for (int sample = 0; sample < samplesRead; sample += m_channels)
34 {
35 double in1 = samples.at(sample);
36 double in2 = (m_channels == 1) ? 0 : samples.at(sample + 1);
37 m_simpleCompressor.process(in1, in2);
38 samples[sample] = static_cast<float>(in1);
39 if (m_channels > 1)
40 {
41 samples[sample + 1] = static_cast<float>(in2);
42 }
43 }
44 }
45 return samplesRead;
46 }
47
48 void CSimpleCompressorEffect::setEnabled(bool enabled) { m_enabled = enabled; }
49
50 void CSimpleCompressorEffect::setMakeUpGain(double gain) { m_simpleCompressor.setMakeUpGain(gain); }
51
53 {
54 if (channels < 1)
55 {
56 channels = 1;
57 }
58 else if (channels > 2)
59 {
60 channels = 2;
61 }
62 m_channels = channels;
63 }
64} // namespace swift::sound::sample_provider
CSimpleCompressorEffect(ISampleProvider *source, QObject *parent=nullptr)
Ctor.
int readSamples(QVector< float > &samples, qint64 count)
Read samples.
ISampleProvider(QObject *parent=nullptr)
Ctor.
QList< T >::const_reference at(qsizetype i) const const
QObject(QObject *parent)
QObject * parent() const const
void setObjectName(QAnyStringView name)