////////////////////////////////////////////////////////////////////////////////
// Sound.h
// Class to represent a sound
// Copyright Bjoern Ganster
// Developed since 2021
////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "BGBase.h"
#include "MemoryBlock.h"

// Get number of bytes used by a sample, per channel
int getBytesPerSample(int sdlFormat);

class Sound: public VirtualClass {
public:
	SDL_AudioSpec mAudioFormat;
	MemoryBlock mData;

	// Constructor
	Sound();

	// Destructor
	~Sound() OVERRIDE;

	// Decode Compact Disc Digital Audio
	#ifdef MECHVM
	void decodeCDDA(const MemoryBlock& data);
	#endif

	// Decode MW2 SFL file
	#ifdef MECHVM
	void decodeSFL(const MemoryBlock& data);
	#endif

	// Decode RIFF WAV file
	bool decodeWAV(const MemoryBlock& data);

	// Save to WAV
	bool saveToWave(const PathChar* fn) const;

	// Convert to new audio specification
	void copyConvert(const Sound& sound, const SDL_AudioSpec& newSpec);

	// Get sample as a float
	float getSampleF(int sample, int channel) const;

	// Set sample to new float
	void setSampleF(int sample, int channel, float newVal);

	// Adjust audio frequency
	void adjustFrequency(int newFreq);

	// Calculate duration of the current sound in milliseconds
	DWORD getDurationMS() const;
};
