#pragma once

#include <Windows.h>
#include <mmsystem.h>
#include <vector>
#include <cstdint>
#include <initializer_list>

using namespace std;

class sound_handler
{
public:
	struct PeakData {
		vector<double> times;
	};

private:
	HINSTANCE m_hInst;
	vector<int> m_wavIds;
	vector<PeakData> m_peaks;

	int m_currentWave = -1;
	double m_soundStart = 0.0; // time of playsound
	int m_nextPeak = 0;
	double m_screamUntil = 0.0;

	static constexpr double p_hold = 0.10;
	static constexpr double p_thresh = 0.65;
	static constexpr int p_max = 64;

public:
	sound_handler(HINSTANCE hInst, initializer_list<int> waveIds);
	void PlayRandom();
	void Update(double now);
	bool IsAwAwA(double now) const;

private:
	PeakData AnalyzeWavResource(int resId);
	static double Now();
};