I want to control a mixer's gain with a joystick, but I get a lot of audio clicking even though I'm changing the gain smoothly (increase/decrease of 0.001).
I guess this is because this isn't meant to be called too fast, but is there a way to avoid the clicks and have a smooth update?
Unfortunately I cannot use faders as I know these work well.
I tried adjusting the change rate (0.1, 0.05 etc.) and the frequency of the update (500 us, 1ms, 10ms etc.) but can't get anything decent.
See simple code below that reproduces this issue with a sine wave.
Thanks for your help
I guess this is because this isn't meant to be called too fast, but is there a way to avoid the clicks and have a smooth update?
Unfortunately I cannot use faders as I know these work well.
I tried adjusting the change rate (0.1, 0.05 etc.) and the frequency of the update (500 us, 1ms, 10ms etc.) but can't get anything decent.
See simple code below that reproduces this issue with a sine wave.
Thanks for your help
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioSynthWaveformSine sine1; //xy=244.1999969482422,133.1999969482422
AudioMixer4 mixer1; //xy=429.1999969482422,134.1999969482422
AudioOutputTDM tdm1; //xy=610.2000122070312,208.1999969482422
AudioConnection patchCord1(sine1, 0, mixer1, 0);
AudioConnection patchCord2(mixer1, 0, tdm1, 0);
AudioControlCS42448 cs42448_1; //xy=273.20001220703125,249.20001220703125
// GUItool: end automatically generated code
unsigned long prevMillis = 0;
float gVal = 0.;
bool goUp = true;
void setup() {
AudioMemory(64);
cs42448_1.enable();
cs42448_1.volume(1);
sine1.frequency(440);
}
void loop() {
if ((millis() - prevMillis) > 2) {
if (goUp) {
gVal += 0.01;
}
else {
gVal -= 0.01;
}
if (gVal > 0.9) {
goUp = false;
}
else if (gVal < 0) {
goUp = true;
gVal = 0.;
}
mixer1.gain(0, gVal);
prevMillis = millis();
}
}
Last edited: