Skip to content

Small click when using mixer #655

@ChuckMash

Description

@ChuckMash

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions