
Guitar Effector using "mbed application board".
Guitar Effector using "mbed application board".
Delay.h
- Committer:
- vaifreak
- Date:
- 2015-09-01
- Revision:
- 1:bfbfd6fede05
- Child:
- 2:25adc1277b3e
File content as of revision 1:bfbfd6fede05:
//============================================================================= // //============================================================================= #pragma once #define DELAY_BUFF_SIZE 5000 //--------------------------------------------- // //--------------------------------------------- class Delay { private: unsigned short buff[ DELAY_BUFF_SIZE ]; int current; int offset; /// [-1.0 ~ 1.0] float buff_get( int i ){ return ((float)buff[i] * (2.0f/65535.0f) ) - 1.0f; } void buff_set( int i, float val ){ // [-1.0 ~ 1.0] to [ 0 ~ 65535 ] buff[i] = (unsigned short)(((val + 1.0f) * 0.5f) * 65535.0f); } public: float delay_time; //[0.0~1.0] float feedback; //[0.0~1.0] float effect_level; Delay() { for(int i=0; i<DELAY_BUFF_SIZE; i++) buff[i] = 0; delay_time = 0.8f; feedback = 0.5f; effect_level = 0.5f; current = 0; } float process(float input) { float output; float buff_val = buff_get(current); // feedback process. offset = current + (int)(delay_time * (float)DELAY_BUFF_SIZE); if( offset >= DELAY_BUFF_SIZE ) offset -= DELAY_BUFF_SIZE; buff_set( offset, (input + buff_val) * feedback ); // effect mix. output = input + buff_val * effect_level; current++; if(current >= DELAY_BUFF_SIZE) current = 0; return output; } };