When no modulation input is present on an AudioSynthWaveformSineModulated object, variable "magnitude" is not taken into account, in other words amplitude has no effect, output is at maximum.
error in line 195 of /Audio/synth_sine.cpp
fix:
If you prefer bigger chunks of code or the full zipped file, please tell.
The next piece of code demonstrates the bug and that the fix is working when applied.
sine_fm1, frequency modulated by sine1, goes to left.
sine_fm2, with no modulation input, goes to right.
Every second, amplitude of sine_fm1 & sine_fm2 is toggled between 0 & 1.
So we should have 1sec of sound and 1sec of silence alternately, which clearly doesn't happen on the second channel.
error in line 195 of /Audio/synth_sine.cpp
Code:
block->data[i] = (val1 + val2) >> 16;
fix:
Code:
block->data[i] = multiply_32x32_rshift32(val1 + val2, magnitude);
If you prefer bigger chunks of code or the full zipped file, please tell.
The next piece of code demonstrates the bug and that the fix is working when applied.
sine_fm1, frequency modulated by sine1, goes to left.
sine_fm2, with no modulation input, goes to right.
Every second, amplitude of sine_fm1 & sine_fm2 is toggled between 0 & 1.
So we should have 1sec of sound and 1sec of silence alternately, which clearly doesn't happen on the second channel.
Code:
#include <Audio.h>
// GUItool: begin automatically generated code
AudioSynthWaveformSine sine1; //xy=94,251
AudioSynthWaveformSineModulated sine_fm1; //xy=248,251
AudioSynthWaveformSineModulated sine_fm2; //xy=248,304
AudioOutputI2S i2s1; //xy=455,257
AudioOutputAnalogStereo dacs1; //xy=456,298
AudioConnection patchCord1(sine1, sine_fm1);
AudioConnection patchCord2(sine_fm1, 0, i2s1, 0);
AudioConnection patchCord3(sine_fm1, 0, dacs1, 0);
AudioConnection patchCord4(sine_fm2, 0, i2s1, 1);
AudioConnection patchCord5(sine_fm2, 0, dacs1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=104,305
// GUItool: end automatically generated code
void setup() {
AudioMemory(20);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
sine1.frequency(9);
sine1.amplitude(1.0);
sine_fm1.frequency(440.0);
sine_fm1.amplitude(1.0);
sine_fm2.frequency(440.0);
sine_fm2.amplitude(1.0);
}
void loop() {
sine_fm1.amplitude(1.0);
sine_fm2.amplitude(1.0);
delay(1000);
sine_fm1.amplitude(0.0);
sine_fm2.amplitude(0.0);
delay(1000);
}