// Copyright (C) 2020 Daniel Mall
#ifndef CAUDIOMIXMULTISOURCE_H
#define CAUDIOMIXMULTISOURCE_H
#include <vector>

//! wav audio file with 2 channels and 16-bit values at 44100 Hz
constexpr int WAV16_CHANNELS = 2;
constexpr int WAV16_FRAMESIZE = (sizeof(int16_t) * WAV16_CHANNELS);

//! maximum number of sounds to mix at the same time
constexpr int AUDIOMIXER_MAXSOUNDS = 25;

class CAudioMixMultiSource
{
public:
	void Reset();
	void NextSource();
	void AddSamplesWav16(const int16_t* pBuffer, const int nAudioFrames);
	void MixSourcesWav16();
	void AllocateWav16(const int nAudioFrames);
	void Deallocate();

public:
	//! mixed final sample values for sokol audio
	float* m_final = nullptr;

	//! mixed final sample frames for sokol audio
	int m_nFinalFrames = 0;

	//! allocated space in the sample values buffer
	int m_nAllocatedSizeInFrames = 0;

private:
	//! each of the individual samples from each source
	std::vector<float*> m_eachSamples;

	//! the number of frames in each sources
	std::vector<int> m_eachFrames;

	//! index of the current audio source
	int m_nIndexSource = 0;

	//! index of the current audio sample within the source
	int m_nIndexSample = 0;
};

#endif
