DaisySP
Loading...
Searching...
No Matches
decimator.h
1/*
2Copyright (c) 2020 Electrosmith, Corp
3
4Use of this source code is governed by an MIT-style
5license that can be found in the LICENSE file or at
6https://opensource.org/licenses/MIT.
7*/
8
9#pragma once
10#ifndef DECIMATOR_H
11#define DECIMATOR_H
12#include <stdint.h>
13#ifdef __cplusplus
14
15namespace daisysp
16{
20{
21 public:
22 Decimator() {}
23 ~Decimator() {}
26 void Init();
27
31 float Process(float input);
32
33
37 inline void SetDownsampleFactor(float downsample_factor)
38 {
39 downsample_factor_ = downsample_factor;
40 }
41
45 inline void SetBitcrushFactor(float bitcrush_factor)
46 {
47 bitcrush_factor_ = bitcrush_factor;
48 bits_to_crush_ = (uint32_t)(bitcrush_factor * kMaxBitsToCrush);
49 bit_overflow_
50 = 2.0f - (bitcrush_factor * 16.0f) + (float)(bits_to_crush_);
51 }
52
56 inline void SetBitsToCrush(const uint8_t &bits)
57 {
58 bits_to_crush_ = bits <= kMaxBitsToCrush ? bits : kMaxBitsToCrush;
59 smooth_crushing_ = false;
60 }
61
65 inline void SetSmoothCrushing(bool smooth_crushing)
66 {
67 smooth_crushing_ = smooth_crushing;
68 }
69
72 inline bool GetSmoothCrushing() { return smooth_crushing_; }
75 inline float GetDownsampleFactor() { return downsample_factor_; }
78 inline float GetBitcrushFactor() { return bitcrush_factor_; }
81 inline int GetBitsToCrush() { return bits_to_crush_; }
82
83 private:
84 const uint8_t kMaxBitsToCrush = 16;
85 float downsample_factor_, bitcrush_factor_;
86 uint32_t bits_to_crush_;
87 float downsampled_, bitcrushed_;
88 uint32_t inc_, threshold_;
89 bool smooth_crushing_;
90 float bit_overflow_;
91};
92} // namespace daisysp
93#endif
94#endif
Definition decimator.h:20
void SetSmoothCrushing(bool smooth_crushing)
Definition decimator.h:65
int GetBitsToCrush()
Definition decimator.h:81
void SetDownsampleFactor(float downsample_factor)
Definition decimator.h:37
float GetBitcrushFactor()
Definition decimator.h:78
bool GetSmoothCrushing()
Definition decimator.h:72
void SetBitcrushFactor(float bitcrush_factor)
Definition decimator.h:45
void SetBitsToCrush(const uint8_t &bits)
Definition decimator.h:56
float GetDownsampleFactor()
Definition decimator.h:75
float Process(float input)
Definition decimator.cpp:17
void Init()
Definition decimator.cpp:5
FIR Filter implementation, generic and ARM CMSIS DSP based.
Definition adenv.h:16