You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since by default the oscillators are set in the [0, 1] range the usual operations of addition will not work as planned. So we should provide a way to easily add oscillators.
Notice though that an average of oscillators would do the trick; furthermore it will ensure result stays within [0, 1] so perhaps that's all we would need. Something to think about...
More broadly we can think about ways to combine multiple sources together (composition?)
add
subtract
min
max
average
not
and
or
xor
The text was updated successfully, but these errors were encountered:
In an effort to try to address this issue I tried implementing a solution using variadic functions. It is far from ideal and also, well, it does not work. The problem is that in order to call the superclass we need to use some kind of casting and I don't think it is possible without using pointers. So we have to come up with another solution.
void_addWavesHelper(int count, float& sum, float& sumAmps, ...) {
sum = 0; // Assuming AbstractWave has a default constructor
sumAmps = 0;
if (count <= 0) return; // Handle edge case where no waves are providedva_list args;
va_start(args, sumAmps);
for (int i = 0; i < count; ++i) {
Serial.println(i);
AbstractWave& wave = va_arg(args, AbstractWave);
sum += wave.get(); // <------------------- THIS DOES NOT WORK AND RESULTS IN CORE DUMP
sumAmps += wave.amplitude();
}
va_end(args);
}
floataddWaves(int count, ...) {
float sum;
float sumAmps;
va_list args;
va_start(args, count);
_addWavesHelper(count, sum, sumAmps, args);
va_end(args);
return sum / count;
}
floataddWaves01(int count, ...) {
float sum;
float sumAmps;
va_list args;
va_start(args, count);
_addWavesHelper(count, sum, sumAmps, args);
va_end(args);
return sum / sumAmps;
}
floataddWavesAmplify(int count, float amplitude, ...) {
va_list args;
va_start(args, count);
float result = mapFrom01(addWaves01(count, args), (1 - amplitude) / 2, (1 + amplitude)/2);
va_end(args);
return result;
}
Since by default the oscillators are set in the [0, 1] range the usual operations of addition will not work as planned. So we should provide a way to easily add oscillators.
Notice though that an average of oscillators would do the trick; furthermore it will ensure result stays within [0, 1] so perhaps that's all we would need. Something to think about...
More broadly we can think about ways to combine multiple sources together (composition?)
The text was updated successfully, but these errors were encountered: