Code: Select all
#define MIC_PIN 34
#define SPEAKER_PIN 25
const int delaySamples = 500;
const float reverbFactor = 0.3;
int audioBuffer[1024];
int reverbBuffer[1024];
void setup() {
pinMode(MIC_PIN, INPUT);
pinMode(SPEAKER_PIN, OUTPUT);
}
void loop() {
int micValue = analogRead(MIC_PIN); // Valores entre 0 y 4095
for (int i = 1023; i > 0; i--) {
audioBuffer[i] = audioBuffer[i - 1];
}
audioBuffer[0] = micValue; // Agregar el valor nuevo al principio del buffer
int outputValue = micValue; // Valor original
if (delaySamples < 1024) {
int delayedValue = reverbBuffer[delaySamples];
outputValue += reverbFactor * delayedValue;
}
if (outputValue > 4095) outputValue = 4095;
if (outputValue < 0) outputValue = 0;
int speakerValue = map(outputValue, 0, 4095, 0, 255);
dacWrite(SPEAKER_PIN, speakerValue);
for (int i = 1023; i > 0; i--) {
reverbBuffer[i] = reverbBuffer[i - 1];
}
reverbBuffer[0] = outputValue;
}