109 lines
3.7 KiB
C
109 lines
3.7 KiB
C
#include "MCP4xxx.h"
|
|
|
|
#define BUFFER_LENGTH 1851
|
|
//Przeliczenie przesunięcia w próbkach na czas dla fs = 10 kHz
|
|
#define _0MS 0
|
|
#define _1MS 10
|
|
#define _5MS 50
|
|
#define _10MS 100
|
|
#define _15MS 150
|
|
#define _16MS 160
|
|
#define _18MS 180
|
|
#define _20MS 200
|
|
#define _23MS 230
|
|
#define _25MS 250
|
|
#define _30MS 300
|
|
#define _35MS 350
|
|
#define _40MS 400
|
|
#define _41MS 410
|
|
#define _50MS 500
|
|
#define _60MS 600
|
|
#define _70MS 700
|
|
#define _80MS 800
|
|
#define _85MS 850
|
|
#define _90MS 900
|
|
#define _100MS 1000
|
|
#define _105MS 1050
|
|
#define _110MS 1100
|
|
#define _120MS 1200
|
|
#define _135MS 1350
|
|
#define _140MS 1400
|
|
#define _150MS 1500
|
|
#define _160MS 1600
|
|
#define _170MS 1700
|
|
#define _175MS 1750
|
|
#define _180MS 1800
|
|
#define _185MS 1850
|
|
|
|
|
|
int16_t reverb(uint8_t buffer [BUFFER_LENGTH], uint16_t bufferIndex, uint8_t roomSize){
|
|
int16_t echo1Index = bufferIndex - _35MS;
|
|
if(echo1Index < 0) echo1Index += BUFFER_LENGTH;
|
|
int16_t echo2Index = bufferIndex - _60MS;
|
|
if(echo2Index < 0) echo2Index += BUFFER_LENGTH;
|
|
int16_t echo3Index = bufferIndex - _85MS;
|
|
if(echo3Index < 0) echo3Index += BUFFER_LENGTH;
|
|
int16_t echo4Index = bufferIndex - _110MS;
|
|
if(echo4Index < 0) echo4Index += BUFFER_LENGTH;
|
|
int16_t echo5Index = bufferIndex - _135MS;
|
|
if(echo5Index < 0) echo5Index += BUFFER_LENGTH;
|
|
int16_t echo6Index = bufferIndex - _160MS;
|
|
if(echo6Index < 0) echo6Index += BUFFER_LENGTH;
|
|
int16_t echo7Index = bufferIndex - _185MS;
|
|
if(echo6Index < 0) echo7Index += BUFFER_LENGTH;
|
|
|
|
//wyznaczenie zmiennych tymczasowych (bez składowych stałych)
|
|
int16_t echo1Temp = -128 + buffer[echo1Index];
|
|
int16_t echo2Temp = -128 + buffer[echo2Index];
|
|
int16_t echo3Temp = -128 + buffer[echo3Index];
|
|
int16_t echo4Temp = -128 + buffer[echo4Index];
|
|
int16_t echo5Temp = -128 + buffer[echo5Index];
|
|
int16_t echo6Temp = -128 + buffer[echo6Index];
|
|
int16_t echo7Temp = -128 + buffer[echo6Index];
|
|
|
|
//obliczenie wartości próbki do przekazania DAC i przywrócenie składowej stałej
|
|
if(roomSize == 1){
|
|
return (1*echo1Temp + 3*echo2Temp + 2*echo3Temp)/30 +128;
|
|
} else if(roomSize == 2){
|
|
return (1*echo1Temp + 3*echo2Temp + 2*echo3Temp + 2*echo4Temp)/30 +128;
|
|
} else if(roomSize == 3){
|
|
return (1*echo1Temp + 3*echo2Temp + 3*echo3Temp + 2*echo4Temp + 1*echo5Temp)/30 +128;
|
|
} else if(roomSize == 4){
|
|
return (2*echo1Temp + 4*echo2Temp + 3*echo3Temp + 2*echo4Temp + 1*echo5Temp)/30 +128;
|
|
} else if(roomSize == 5){
|
|
return (2*echo1Temp + 4*echo2Temp + 3*echo3Temp + 3*echo4Temp + 2*echo5Temp + 1*echo6Temp)/30 +128;
|
|
} else if(roomSize == 6){
|
|
return (2*echo1Temp + 5*echo2Temp + 4*echo3Temp + 3*echo4Temp + 3*echo5Temp + 1*echo6Temp)/30 +128;
|
|
} else if(roomSize == 7){
|
|
return (2*echo1Temp + 5*echo2Temp + 5*echo3Temp + 4*echo4Temp + 3*echo5Temp + 2*echo6Temp + 1*echo7Temp)/30 +128;
|
|
} else if(roomSize == 8){
|
|
return (3*echo1Temp + 6*echo2Temp + 5*echo3Temp + 4*echo4Temp + 4*echo5Temp + 2*echo6Temp + 2*echo7Temp)/30 +128;
|
|
} else {
|
|
return (3*echo1Temp + 7*echo2Temp + 6*echo3Temp + 5*echo4Temp + 4*echo5Temp + 3*echo6Temp + 2*echo7Temp)/30 +128;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
int16_t distortion(uint8_t cutoff, uint8_t adcVal){
|
|
//jeżeli wartość przekracza ustawiony próg, to jest ona do nigo zmniejszana (ucinanie górnej części przebiegu)
|
|
if (adcVal > cutoff){
|
|
return cutoff;
|
|
} else {
|
|
return adcVal;
|
|
}
|
|
}
|
|
|
|
|
|
int16_t chorusFlanger(uint8_t buffer [BUFFER_LENGTH], uint16_t bufferIndex, uint16_t delayVal, uint8_t attenuationLevel){
|
|
int16_t echoIndex = bufferIndex - delayVal;
|
|
if(echoIndex < 0) echoIndex += BUFFER_LENGTH;
|
|
int16_t echoTemp = -128 + buffer[echoIndex];
|
|
|
|
return echoTemp/(1+attenuationLevel) + 128;
|
|
}
|
|
|
|
int16_t tremolo(uint8_t adcVal, uint8_t amplitudeLevel){
|
|
return ((adcVal - 128)*(amplitudeLevel+70))/271 + 128;
|
|
} |