Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small click when using mixer #655

Open
ChuckMash opened this issue Dec 12, 2023 · 3 comments
Open

Small click when using mixer #655

ChuckMash opened this issue Dec 12, 2023 · 3 comments

Comments

@ChuckMash
Copy link
Contributor

ChuckMash commented Dec 12, 2023

Hello,

I am using mixer to mix 2 stubs with MP3s from an SD card, one is an long ongoing background track and the other is various sound clips played at various times.

The issue is that there is a audible click each time the second stub with the sound clip is used.

I have searched the repo and found a few other issues commenting on such clicks, but have so far been unable to implement any of the suggested fixes or mitigations while also using mixer.

Here I have a reduced version of the example code


#include <Arduino.h>
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2S.h"
#include "AudioFileSourceSD.h"
#include "AudioOutputMixer.h"

#include <SD.h>13.0
#include <SPI.h>
#include <FS.h>

AudioFileSourceSD    *play_file1;
AudioFileSourceSD    *play_file2;
AudioGeneratorMP3    *mp31;
AudioGeneratorMP3    *mp32;
AudioOutputMixer     *mixer;
AudioOutputMixerStub *stub[2];
AudioOutputI2S       *out;

long lastTime = millis();

void setup() {
  Serial.begin(115200);
 
  SD.begin(5, SPI, 25000000); 
  //SD.begin(5, SPI, 4000000); 
  audioLogger = &Serial;
 
  mp31  = new AudioGeneratorMP3();
  mp32  = new AudioGeneratorMP3();

  out   = new AudioOutputI2S(0,0);
  out->SetOutputModeMono(true);

  mixer = new AudioOutputMixer(1024, out);

  stub[0] = mixer->NewInput();
  stub[0]->SetGain(.1);
  
  stub[1] = mixer->NewInput();
  stub[1]->SetGain(.1);
   
  play_file1 = new AudioFileSourceSD("/underwater.mp3");
  play_file2 = new AudioFileSourceSD("/sonar_ping.mp3");

  mp31->begin(play_file1, stub[0]);

}



void loop() {  

  // Background Audio
  if (mp31->isRunning()) {
    if (!mp31->loop()){
      mp31->stop();
      delete play_file1;
      delete mp31;
      delete stub[0];
      stub[0] = mixer->NewInput();
      stub[0]->SetGain(.1);
      mp31 = new AudioGeneratorMP3();
    }
  }

  // Sound Clip
  if (mp32->isRunning()) {
    if (!mp32->loop()){
      mp32->stop();
      delete play_file2;
      delete mp32;
      delete stub[1];
      stub[1] = mixer->NewInput();
      stub[1]->SetGain(.1);
      mp32 = new AudioGeneratorMP3();
    }
  }

  // Background Audio
  if(!mp31->isRunning()){
    play_file1 = new AudioFileSourceSD("/underwater.mp3");
    mp31->begin(play_file1, stub[0]);
  }

  // Sound Clip
  if(millis()-lastTime > 8000){ 
    if(!mp32->isRunning()){
      play_file2 = new AudioFileSourceSD("/sonar_ping.mp3");
      mp32->begin(play_file2, stub[1]);
      lastTime = millis();
    }
  }

}

My hope is that I have overlooked something obvious

The only thing coming from audioLogger is

MP3:ERROR_BUFLEN 0

sounds.zip

@ChuckMash
Copy link
Contributor Author

ChuckMash commented Dec 15, 2023

Some more information:

The click remains when trying with other generator file formats.

If I set stub[0] (background audio) to gain of 0, it sounds like there is no click.

If I set all stubs to gain of 0, there is a barely perceivable short duration change in the (lack of) audio, a momentary shift in the silent hiss where the click would be. I'm not sure what this is indicative of, but I found it interesting

@ChuckMash
Copy link
Contributor Author

The issue seems to be from SetRate()

Found a workaround in #329

By adding custom AudioOutput layer AudioOutputFixedRates between each generator and mixer stub, the click is removed.

@ChuckMash
Copy link
Contributor Author

PR #656 fixes the above issue by adding a quick check to see if rate actually needs updating or if it matches what is currently set, eliminating the issue as long as rates match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant