Extract WAVE format parsing into its own function

This commit is contained in:
Daniel Wolf 2021-09-21 19:47:53 +02:00
parent 33c542f2e8
commit 5f293cdd33
2 changed files with 20 additions and 13 deletions

View File

@ -33,10 +33,9 @@ namespace Codec {
string codecToString(int codec);
WaveFileReader::WaveFileReader(const path& filePath) :
filePath(filePath),
formatInfo {}
{
WaveFormatInfo getWaveFormatInfo(const path& filePath) {
WaveFormatInfo formatInfo {};
auto file = openFile(filePath);
file.seekg(0, std::ios_base::end);
@ -139,8 +138,14 @@ WaveFileReader::WaveFileReader(const path& filePath) :
}
}
}
return formatInfo;
}
WaveFileReader::WaveFileReader(const path& filePath) :
filePath(filePath),
formatInfo(getWaveFormatInfo(filePath)) {}
unique_ptr<AudioClip> WaveFileReader::clone() const {
return make_unique<WaveFileReader>(*this);
}

View File

@ -10,6 +10,17 @@ enum class SampleFormat {
Float32
};
struct WaveFormatInfo {
int bytesPerFrame;
SampleFormat sampleFormat;
int frameRate;
int64_t frameCount;
int channelCount;
std::streampos dataOffset;
};
WaveFormatInfo getWaveFormatInfo(const std::filesystem::path& filePath);
class WaveFileReader : public AudioClip {
public:
WaveFileReader(const std::filesystem::path& filePath);
@ -20,15 +31,6 @@ public:
private:
SampleReader createUnsafeSampleReader() const override;
struct WaveFormatInfo {
int bytesPerFrame;
SampleFormat sampleFormat;
int frameRate;
int64_t frameCount;
int channelCount;
std::streampos dataOffset;
};
std::filesystem::path filePath;
WaveFormatInfo formatInfo;
};