|
-
-
- #include <Arduino.h>
- #include "effect_chorus.h"
-
-
-
-
-
-
-
-
- boolean AudioEffectChorus::begin(short *delayline,int d_length,int n_chorus)
- {
- #if 0
- Serial.print("AudioEffectChorus.begin(Chorus delay line length = ");
- Serial.print(d_length);
- Serial.print(", n_chorus = ");
- Serial.print(n_chorus);
- Serial.println(")");
- #endif
-
- l_delayline = NULL;
- delay_length = 0;
- l_circ_idx = 0;
-
- if(delayline == NULL) {
- return(false);
- }
- if(d_length < 10) {
- return(false);
- }
- if(n_chorus < 1) {
- return(false);
- }
-
- l_delayline = delayline;
- delay_length = d_length/2;
- num_chorus = n_chorus;
-
- return(true);
- }
-
- void AudioEffectChorus::voices(int n_chorus)
- {
- num_chorus = n_chorus;
- }
-
-
- void AudioEffectChorus::update(void)
- {
- audio_block_t *block;
- short *bp;
- int sum;
- int c_idx;
-
- if(l_delayline == NULL)return;
-
-
-
-
- if(num_chorus <= 1) {
-
- block = receiveWritable(0);
- if(block) {
- bp = block->data;
- for(int i = 0;i < AUDIO_BLOCK_SAMPLES;i++) {
- l_circ_idx++;
- if(l_circ_idx >= delay_length) {
- l_circ_idx = 0;
- }
- l_delayline[l_circ_idx] = *bp++;
- }
- transmit(block,0);
- release(block);
- }
- return;
- }
-
-
-
- block = receiveWritable(0);
- if(block) {
- bp = block->data;
- uint32_t tmp = delay_length/(num_chorus - 1) - 1;
- for(int i = 0;i < AUDIO_BLOCK_SAMPLES;i++) {
- l_circ_idx++;
- if(l_circ_idx >= delay_length) {
- l_circ_idx = 0;
- }
- l_delayline[l_circ_idx] = *bp;
- sum = 0;
- c_idx = l_circ_idx;
- for(int k = 0; k < num_chorus; k++) {
- sum += l_delayline[c_idx];
- if(num_chorus > 1)c_idx -= tmp;
- if(c_idx < 0) {
- c_idx += delay_length;
- }
- }
- *bp++ = sum/num_chorus;
- }
-
-
- transmit(block,0);
- release(block);
- }
- }
-
-
|