Thank you for your reply. I tried eliminating anything requiring or introducing delays and use constant fake readings and the problem is still present. Maybe, I messed up with the code. I try to post the relevant part of the code, maybe it could help... Now I can tell where exactly the problem arises (look in the function readSensor()). However, when I will solve this problem, I will be glad to add an example code in the mozzi examples.
int i=0;
void updateControl() {
distances[i] = readSensor(i);
i = (i+1)%NSENS;
int final = getMinFreq(); // this function returns the minimum of the 3 readings for sine frequency
if (final != OUT_OF_RANGE) {
active = 1;
} else {
final = 0;
active = 0;
}
float modulation = getMinMod(); // this function returns the minimum of the 3 readings for vibrato frequency
if (modulation == OUT_OF_RANGE)
modulation = 0;
else
modulation = map(modulation,0,OUT_OF_RANGE,-15,15);
aVibrato.setFreq(modulation);
averaged = kAverage.next(final>>1);
aSin0.setFreq(averaged);
}
int readSensor(int i) {
digitalWrite( triggerPort[i], LOW );
long msecs = mozziMicros();
while ((mozziMicros() - msecs) < 2);
digitalWrite( triggerPort[i], HIGH ); // IF I COMMENT JUST THIS LINE THE POPPING VANISHES!!!
// notice that triggerPort is defined as: int triggerPort[NSENS] = {12,10,6,4,2,0};
// if I change pin the popping still occurs, just with a different, but similar, pattern
msecs = mozziMicros();
while ((mozziMicros() - msecs) < 10);
digitalWrite( triggerPort[i], LOW );
int duration = pulseIn( echoPort[i], HIGH, OUT_OF_RANGE );
if (duration == 0) duration = OUT_OF_RANGE;
return duration;
}
int updateAudio(){
long vibrato = 300 * aVibrato.next();
return aSin0.phMod(vibrato)*active;
}