Hi guys,
Working on something at the moment with two audio channels being fed into a mixer. One is background music, one is an announcement or sound effect.
These two channels are mixed in a mixer4 and output via the T3.1 DAC.
My audio objects are defined as follows:
Initialisation:
Now, the structure of my 'play' functions is:
My loop function looks like this:
Now, the behaviour I'm getting, is that the volume of channel 1 of the mixer (music) is never returned to 1.0, despite isPlaying() working as intended. (Note the Serial.println() calls to verify this).
However, adding a small delay to the end of the loop seems to resolve it.
EG
Any ideas? Sorry this wasn't very clear; struggling to understand it myself, let alone explain it. Of course, I'm aware that I'm asking it to continuously update the gain of the channel (unnecessarily 90% of the time) and that there are likely better ways of doing this, but it just seems odd?
Working on something at the moment with two audio channels being fed into a mixer. One is background music, one is an announcement or sound effect.
These two channels are mixed in a mixer4 and output via the T3.1 DAC.
My audio objects are defined as follows:
Code:
AudioPlaySdWav sound_player;
AudioPlaySdWav music_player;
AudioOutputAnalog dac;
AudioMixer4 mixer;
AudioConnection sound_to_mixer(sound_player, 0, mixer, 0);
AudioConnection music_to_mixer(music_player, 0, mixer, 1);
AudioConnection mixer_to_output(mixer, 0, dac, 0);
Initialisation:
Code:
AudioMemory(10);
dac.analogReference(INTERNAL);
mixer.gain(0, 1.0);
mixer.gain(1, 1.0);
if (SD.begin(6)) //Hardcoded!
audioInitialised = true;
else
audioInitialised = false;
Now, the structure of my 'play' functions is:
Code:
void playSound() {
sound_player.play("test.wav");
if (music_player.isPlaying())
mixer.gain(1, 0.1); //quiet music volume if sound effect is playing.
}
My loop function looks like this:
Code:
elapsedMillis timer = 0;
void loop() {
//do some unrelated stuff.
if (!(sound_player.isPlaying())) {
mixer.gain(1, 1.0);
Serial.println("Not playing!");
}
else Serial.println("Playing");
if(timer > 5000) {
timer = 0;
playSound();
}
Now, the behaviour I'm getting, is that the volume of channel 1 of the mixer (music) is never returned to 1.0, despite isPlaying() working as intended. (Note the Serial.println() calls to verify this).
However, adding a small delay to the end of the loop seems to resolve it.
EG
Code:
elapsedMillis timer = 0;
void loop() {
//do some unrelated stuff.
if (!(sound_player.isPlaying())) {
mixer.gain(1, 1.0);
Serial.println("Not playing!");
}
else Serial.println("Playing");
if(timer > 5000) {
timer = 0;
playSound();
}
delay(50);
Any ideas? Sorry this wasn't very clear; struggling to understand it myself, let alone explain it. Of course, I'm aware that I'm asking it to continuously update the gain of the channel (unnecessarily 90% of the time) and that there are likely better ways of doing this, but it just seems odd?
Last edited: