|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
-
-
- #include <Arduino.h>
- #include "effect_bitcrusher.h"
-
- void AudioEffectBitcrusher::update(void)
- {
- audio_block_t *block;
- uint32_t i;
- uint32_t sampleSquidge, sampleSqueeze;
-
- if (crushBits == 16 && sampleStep <= 1) {
-
- block = receiveReadOnly();
- if (!block) return;
- transmit(block);
- release(block);
- return;
- }
-
-
- block = receiveWritable();
- if (!block) return;
-
- if (sampleStep <= 1) {
- for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
-
-
- sampleSquidge = block->data[i] >> (16-crushBits);
-
-
- block->data[i] = sampleSquidge << (16-crushBits);
- }
- } else if (crushBits == 16) {
- i=0;
- while (i < AUDIO_BLOCK_SAMPLES) {
-
-
- sampleSqueeze = block->data[i];
- for (int j = 0; j < sampleStep && i < AUDIO_BLOCK_SAMPLES; j++) {
-
-
- block->data[i] = sampleSqueeze;
- i++;
- }
- }
- } else {
- i=0;
- while (i < AUDIO_BLOCK_SAMPLES) {
-
-
- sampleSqueeze = block->data[i];
- for (int j = 0; j < sampleStep && i < AUDIO_BLOCK_SAMPLES; j++) {
-
-
-
- sampleSquidge = sampleSqueeze >> (16-crushBits);
-
-
-
- block->data[i] = sampleSquidge << (16-crushBits);
- i++;
- }
- }
- }
- transmit(block);
- release(block);
- }
-
-
|