2016-01-06 20:02:06 +00:00
|
|
|
#pragma once
|
2015-09-17 19:47:58 +00:00
|
|
|
|
2021-06-18 20:00:01 +00:00
|
|
|
#include <filesystem>
|
2016-07-20 18:42:27 +00:00
|
|
|
#include "AudioClip.h"
|
2015-09-17 19:47:58 +00:00
|
|
|
|
|
|
|
enum class SampleFormat {
|
|
|
|
UInt8,
|
|
|
|
Int16,
|
|
|
|
Int24,
|
|
|
|
Float32
|
|
|
|
};
|
|
|
|
|
2016-07-20 18:42:27 +00:00
|
|
|
class WaveFileReader : public AudioClip {
|
2015-09-17 19:47:58 +00:00
|
|
|
public:
|
2021-06-18 20:00:01 +00:00
|
|
|
WaveFileReader(const std::filesystem::path& filePath);
|
2016-07-20 18:42:27 +00:00
|
|
|
std::unique_ptr<AudioClip> clone() const override;
|
|
|
|
int getSampleRate() const override;
|
|
|
|
size_type size() const override;
|
2015-09-17 19:47:58 +00:00
|
|
|
|
|
|
|
private:
|
2016-07-20 18:42:27 +00:00
|
|
|
SampleReader createUnsafeSampleReader() const override;
|
|
|
|
|
|
|
|
struct WaveFormatInfo {
|
|
|
|
int bytesPerFrame;
|
|
|
|
SampleFormat sampleFormat;
|
|
|
|
int frameRate;
|
|
|
|
int64_t frameCount;
|
|
|
|
int channelCount;
|
|
|
|
std::streampos dataOffset;
|
|
|
|
};
|
2016-03-07 20:28:31 +00:00
|
|
|
|
2021-06-18 20:00:01 +00:00
|
|
|
std::filesystem::path filePath;
|
2016-07-20 18:42:27 +00:00
|
|
|
WaveFormatInfo formatInfo;
|
2015-09-17 19:47:58 +00:00
|
|
|
};
|
2016-07-20 18:42:27 +00:00
|
|
|
|
|
|
|
inline int WaveFileReader::getSampleRate() const {
|
|
|
|
return formatInfo.frameRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline AudioClip::size_type WaveFileReader::size() const {
|
|
|
|
return formatInfo.frameCount;
|
|
|
|
}
|