2023-03-25 20:24:10 +00:00
|
|
|
#include "BitCrushEffect.h"
|
|
|
|
|
|
|
|
BitCrushEffect::BitCrushEffect() {}
|
|
|
|
|
2023-03-28 12:12:41 +00:00
|
|
|
// algorithm from https://www.kvraudio.com/forum/viewtopic.php?t=163880
|
2024-10-23 11:44:31 +00:00
|
|
|
OsciPoint BitCrushEffect::apply(int index, OsciPoint input, const std::vector<std::atomic<double>>& values, double sampleRate) {
|
2023-07-14 14:34:24 +00:00
|
|
|
double value = values[0];
|
2023-03-28 12:12:41 +00:00
|
|
|
// change rage of value from 0-1 to 0.0-0.78
|
|
|
|
double rangedValue = value * 0.78;
|
|
|
|
double powValue = pow(2.0f, 1.0 - rangedValue) - 1.0;
|
|
|
|
double crush = powValue * 12;
|
|
|
|
double x = powf(2.0f, crush);
|
|
|
|
double quant = 0.5 * x;
|
|
|
|
double dequant = 1.0f / quant;
|
2024-10-23 11:44:31 +00:00
|
|
|
return OsciPoint(dequant * (int)(input.x * quant), dequant * (int)(input.y * quant), dequant * (int)(input.z * quant));
|
2023-03-28 12:12:41 +00:00
|
|
|
}
|