Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Crusher::update(void)
- {
- audio_block_t *block;
- block = receiveWritable();
- if (!block) return;
- uint32_t *data = (uint32_t *)(block->data);
- uint16_t res = pow(2,(16-bitDepth)+1);
- uint32_t crushed_sample;
- int i = 0;
- while (i < AUDIO_BLOCK_SAMPLES)
- {
- //Crushing the sample's resolution
- //This if statement should round the sample to the nearest int wich has the resolution of the desired bit-depth
- if ((data[i] % res) == 0) { //the sample already has the desired resolution
- crushed_sample = data[i];
- } else if (((data[i] % res) > (res/2)) { //sample has to be rounded up to the next int wich has desired resoluton
- crushed_sample = (((data[i] / res) + res) * res);
- } else crushed_sample = ((data[i] / res) * res); //sample has to be rounded down
- }
- //Simulating lower sample rate
- for (int j = 0; j < downsampling_factor && i < AUDIO_BLOCK_SAMPLES; j++)
- {
- data[i] = crushed_sample
- i++;
- }
- }
- transmit(block);
- release(block);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement