summaryrefslogtreecommitdiffstats
path: root/src/effects/builtin/bitcrushereffect.h
blob: f9966da8a3d99d4cc1b797302240078b757ec27f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef BITCRUSHEREFFECT_H
#define BITCRUSHEREFFECT_H

#include <QMap>

#include "effects/effect.h"
#include "effects/effectprocessor.h"
#include "engine/effects/engineeffect.h"
#include "engine/effects/engineeffectparameter.h"
#include "util/class.h"
#include "util/types.h"

struct BitCrusherGroupState : public EffectState {
    // Default accumulator to 1 so we immediately pick an input value.
    BitCrusherGroupState(const mixxx::EngineParameters& bufferParameters)
            : EffectState(bufferParameters),
              hold_l(0),
              hold_r(0),
              accumulator(1) {
    }
    CSAMPLE hold_l, hold_r;
    // Accumulated fractions of a samplerate period.
    CSAMPLE accumulator;
};

class BitCrusherEffect : public EffectProcessorImpl<BitCrusherGroupState> {
  public:
    BitCrusherEffect(EngineEffect* pEffect);
    virtual ~BitCrusherEffect();

    static QString getId();
    static EffectManifestPointer getManifest();

    // See effectprocessor.h
    void processChannel(const ChannelHandle& handle,
                        BitCrusherGroupState* pState,
                        const CSAMPLE* pInput, CSAMPLE *pOutput,
                        const mixxx::EngineParameters& bufferParameters,
                        const EffectEnableState enableState,
                        const GroupFeatureState& groupFeatureState,
                        const EffectChainInsertionType insertionType);

  private:
    QString debugString() const {
        return getId();
    }

    EngineEffectParameter* m_pBitDepthParameter;
    EngineEffectParameter* m_pDownsampleParameter;

    DISALLOW_COPY_AND_ASSIGN(BitCrusherEffect);
};

#endif /* BITCRUSHEREFFECT_H */