Added Audio(const Str_8& filePath, DataType type) to force a specific data type.

This commit is contained in:
Arron David Nelson 2024-02-20 22:52:40 -08:00
parent 93f881cf03
commit 58f624a18a
2 changed files with 25 additions and 0 deletions

View File

@ -41,6 +41,8 @@ namespace ehs
Audio(const Str_8& filePath);
Audio(const Str_8& filePath, DataType type);
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, UInt_64 frames, const Byte* data);
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Serializer<UInt_64>& data);

View File

@ -80,6 +80,29 @@ namespace ehs
codec->Decode(data, this);
}
Audio::Audio(const Str_8& filePath, DataType type)
{
AddType("Audio");
File file(filePath, Mode::READ, Disposition::OPEN);
Str_8 ext = file.GetExtension();
const AudioCodec* codec = GetCodec(ext);
if (!codec)
{
EHS_LOG_INT("Error", 0, "Codec not found for file extension, \"" + ext + "\".");
return;
}
Serializer<UInt_64> data = file.ReadSerializer_64(codec->GetEndianness(), file.Size());
file.Release();
codec->Decode(data, this);
ToDataType(type);
}
Audio::Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const UInt_64 frames, const Byte* const data)
: Resource((Str_8&&)id), dataType(dataType), byteDepth(ToByteDepth(dataType)), sampleRate(sampleRate),
channels(channels), frames(frames), length((float)frames / (float)sampleRate),