30 lines
677 B
C
30 lines
677 B
C
/*
|
|
Simple fixed point bitcrash.
|
|
https://github.com/schollz/fpfx
|
|
*/
|
|
|
|
#ifndef COM_SND_BITCRSH_H
|
|
#define COM_SND_BITCRSH_H
|
|
|
|
#include "../fix.h"
|
|
#include <stdint.h>
|
|
|
|
struct com_snd_bitcrsh {
|
|
uint8_t bits; /* How much to trim when triggered. */
|
|
uint8_t reduce; /* Every Nth sample frame. */
|
|
};
|
|
|
|
static void com_snd_bitcrsh_process(Bitcrush *bitcrush, int32_t *buf,
|
|
unsigned int nr_samples) {
|
|
for (int i = 0; i < nr_samples; i++) {
|
|
if (i % bitcrush->reduce == 0) {
|
|
// bitcrush fixedpoint
|
|
buf[i] = buf[i] >> (16 - bitcrush->bits) << (16 - bitcrush->bits);
|
|
} else {
|
|
buf[i] = buf[i - 1];
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|