diff --git a/include/ehs/io/audio/Audio.h b/include/ehs/io/audio/Audio.h index 4136da5..a1ca54d 100644 --- a/include/ehs/io/audio/Audio.h +++ b/include/ehs/io/audio/Audio.h @@ -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& data); diff --git a/src/io/audio/Audio.cpp b/src/io/audio/Audio.cpp index 4daf7cb..79ff885 100644 --- a/src/io/audio/Audio.cpp +++ b/src/io/audio/Audio.cpp @@ -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 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),