Glitch when starting my audio mixer


#1

I am trying to develop a audio mixer and would like to get some help. This is my setup.

  • Create 4 audio transport sources
  • Add all 4 transport sources to a mixer
  • Set the gains for all the transport source to be at 0.0 and start them

At this point all the 4 tracks will start to play but the user will not hear any audio. Then when the user clicks on a button, i will set the gain for all 4 tracks to be 1.0. I move from gain value of 0.0 for all 4 tracks to gain value of 1.0 for all 4 tracks.

In this scenario, i hear a distinct noise/glitch for very short duration. Can any one suggest some method to remove the glitch.

I tried setting the gain in steps for 0.25, 0.5 , 0.75 and 1.0 sequentially without any delay in between. But in this also the glitch is observer.


#2

I think we might need to see at least some of the code to help with this…


#3

The core mixer code looks like this

` namespace PSMixer
{
const static int read_ahead_buffer_size = 128 * 1024;
const static double stem_sample_rate = 44100.0;
const static int stem_max_channels = 2;

class DeviceManager
{
	AudioFormatManager	formatManager;
	AudioSourcePlayer	sourcePlayer;
	AudioDeviceManager	deviceManager;
public:
	DeviceManager()
	{
		formatManager.registerBasicFormats();
		deviceManager.initialiseWithDefaultDevices(0, 2);
	}

	~DeviceManager()
	{
		deviceManager.closeAudioDevice();
	}

	void setMixer(juce::AudioSource *mixerSource)
	{
		sourcePlayer.setSource(mixerSource);
		deviceManager.addAudioCallback(&sourcePlayer);
	}

	void resetMixer()
	{
		sourcePlayer.setSource(nullptr);
		deviceManager.removeAudioCallback(&sourcePlayer);
	}

	AudioFormatReader* getAudioFormatReader(String file_name)
	{
		if (File(file_name).existsAsFile())
		{
			return formatManager.createReaderFor(File(file_name));
		}
		else
		{
			return nullptr;
		}
	}

	AudioFormatReader* getAudioFormatReader(File file_name)
	{
		if (file_name.existsAsFile())
		{
			return formatManager.createReaderFor(file_name);
		}
		else
		{
			return nullptr;
		}
	}
};

class PSAudioSource : public AudioTransportSource
{
	AudioFormatReader		*fileReader;
	AudioFormatReaderSource *sourceReader;
	juce::TimeSliceThread	readerThread;

public:
	PSAudioSource() : readerThread("Stem Reader Thread")
	{
		readerThread.startThread(5);
	}

	~PSAudioSource()
	{
		delete sourceReader;
	}

	void setAudioFormatReader(AudioFormatReader * audio_reader)
	{
		fileReader = audio_reader;
		sourceReader = new AudioFormatReaderSource(fileReader, true);
		setSource(sourceReader, read_ahead_buffer_size, &readerThread, stem_sample_rate, stem_max_channels);
		sourceReader->setLooping(true);
	}
};

class Mixer : public MixerAudioSource
{
public:
	void addStem(PSAudioSource *stem)
	{
		addInputSource(stem, false);
	}
};
}`

And the main program using the mixer looks like this

`
PSMixer::DeviceManager deviceManager;

File file_01("H:\\audio_data\\01.ogg");
File file_02("H:\\audio_data\\02.ogg");
File file_03("H:\\audio_data\\03.ogg");
PSMixer::PSAudioSource audio_source_01;
audio_source_01.setAudioFormatReader(deviceManager.getAudioFormatReader(file_01));

PSMixer::PSAudioSource audio_source_02;
audio_source_02.setAudioFormatReader(deviceManager.getAudioFormatReader(file_02));

PSMixer::PSAudioSource audio_source_03;
audio_source_03.setAudioFormatReader(deviceManager.getAudioFormatReader(file_03));

PSMixer::Mixer mixer;
mixer.addStem(&audio_source_01);
mixer.addStem(&audio_source_02);
mixer.addStem(&audio_source_03);

deviceManager.setMixer(&mixer);

audio_source_01.setGain(0.0);
audio_source_02.setGain(0.0);
audio_source_03.setGain(0.0);

audio_source_01.start();
audio_source_02.start();
audio_source_03.start();

getchar();

audio_source_01.setGain(1.0);
audio_source_02.setGain(1.0);
audio_source_03.setGain(1.0);
`

#4

What do you mean with “without any delay” - do you mean that the 0.25, 0.5, 0.75 and 1.0 are one sample after another? Also I still think this is too steep. You probably want to fade in the audio over a hundred samples or so.


#5

Thank you Fabian

I will read up on how to set the gains for 100 samples or so.


#6

look for LinearSmoothedValue


#7

Not able to solve this issue yet.

Can anyone review my code structure and comment if I have the right design. In my audio chain the audio device and the mixer are started first. Then i add files to the mixer with zero gain. And on the start of a user input i set the gain to one. I not sure where to apply the gain ramp.

Please advise.