summaryrefslogtreecommitdiffstats
path: root/src/engine/enginesidechaincompressor.h
diff options
context:
space:
mode:
authorOwen Williams <owilliams@mixxx.org>2014-01-29 10:04:23 -0430
committerOwen Williams <owilliams@mixxx.org>2014-02-09 14:14:06 -0500
commita27966dce546de42dc93191efe38c482f90d7fd7 (patch)
treeeebbd07aaca950bfb6ebfecd845897e931d52b63 /src/engine/enginesidechaincompressor.h
parent8c270360e473b09fb87d204df3575d3a41ede5d0 (diff)
First pass at implementing a sidechain compressor, for mostly for lowering music volume when mic is active.
Diffstat (limited to 'src/engine/enginesidechaincompressor.h')
-rw-r--r--src/engine/enginesidechaincompressor.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/engine/enginesidechaincompressor.h b/src/engine/enginesidechaincompressor.h
new file mode 100644
index 0000000000..c18326b0ac
--- /dev/null
+++ b/src/engine/enginesidechaincompressor.h
@@ -0,0 +1,76 @@
+#ifndef ENGINECOMPRESSOR_H
+#define ENGINECOMPRESSOR_H
+
+#include "defs.h"
+#include "configobject.h"
+#include "engine/engineobject.h"
+
+class ControlObject;
+
+class EngineSideChainCompressor : public EngineObject {
+ Q_OBJECT
+ public:
+ EngineSideChainCompressor(ConfigObject<ConfigValue>* pConfig, const char* group);
+ virtual ~EngineSideChainCompressor() { };
+
+ void setThreshold(CSAMPLE threshold) {
+ m_threshold = threshold;
+ calculateRates();
+ }
+
+ void setStrength(CSAMPLE strength) {
+ m_strength = strength;
+ calculateRates();
+ }
+
+ void setAttackTime(unsigned int attack_time) {
+ m_attackTime = attack_time;
+ calculateRates();
+ }
+
+ void setDecayTime(unsigned int decay_time) {
+ m_decayTime = decay_time;
+ calculateRates();
+ }
+
+ // Every loop, before calling process, first call processKey to feed
+ // the compressor the input key signal.
+ void processKey(const CSAMPLE* pIn, const int iBufferSize);
+
+ void process(const CSAMPLE* pIn, CSAMPLE* pOut, const int iBufferSize);
+
+ private:
+ // Update the attack and decay rates.
+ void calculateRates();
+
+ // Calculates a new compression value for the next frame
+ // based on the current compression ratio and whether the current input is above threshold.
+ inline double calculateCompression(CSAMPLE currentRatio, bool aboveThreshold) const;
+
+ ConfigObject<ConfigValue>* m_pConfig;
+
+ // The current ratio the signal is being compressed. This is the same as m_strength
+ // when the compressor is at maximum engagement (not attacking or decaying).
+ CSAMPLE m_compressRatio;
+
+ // True if the input signal is above the threshold.
+ bool m_bAboveThreshold;
+
+ // The sample value above which the compressor is triggered.
+ CSAMPLE m_threshold;
+
+ // The largest ratio the signal can be compressed.
+ CSAMPLE m_strength;
+
+ // The length of time, in frames (samples/2), until maximum compression is reached.
+ unsigned int m_attackTime;
+
+ // The length of time, in frames, until compression is completely off.
+ unsigned int m_decayTime;
+
+ // These are the delta compression values per sample based on the strengths and timings.
+ CSAMPLE m_attackPerFrame;
+ CSAMPLE m_decayPerFrame;
+};
+
+#endif