199 lines
5.5 KiB
C
199 lines
5.5 KiB
C
|
#pragma once
|
||
|
|
||
|
#include "../../EHS.h"
|
||
|
#include "../../DataType.h"
|
||
|
#include "../../Str.h"
|
||
|
#include "../../Serializer.h"
|
||
|
#include "../../Vector.h"
|
||
|
#include "../../Array.h"
|
||
|
#include "AudioCodec.h"
|
||
|
|
||
|
namespace lwe
|
||
|
{
|
||
|
class Audio : public Resource
|
||
|
{
|
||
|
private:
|
||
|
static Array<AudioCodec> codecs;
|
||
|
UInt_64 sampleRate;
|
||
|
DataType dataType;
|
||
|
UInt_8 byteDepth;
|
||
|
UInt_8 channels;
|
||
|
UInt_64 frames;
|
||
|
float length;
|
||
|
Byte* data;
|
||
|
Byte* peak;
|
||
|
|
||
|
public:
|
||
|
static bool HasCodec(const UInt_64 hashExt);
|
||
|
|
||
|
static bool HasCodec(const Str_8& ext);
|
||
|
|
||
|
static bool AddCodec(AudioCodec codec);
|
||
|
|
||
|
static const AudioCodec* GetCodec(const UInt_64 hashExt);
|
||
|
|
||
|
static const AudioCodec* GetCodec(const Str_8& ext);
|
||
|
|
||
|
~Audio() override;
|
||
|
|
||
|
Audio();
|
||
|
|
||
|
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const UInt_64 frames, const Byte* const data);
|
||
|
|
||
|
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Serializer<UInt_64>& data);
|
||
|
|
||
|
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Vector<Byte>& data);
|
||
|
|
||
|
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const Array<Byte>& data);
|
||
|
|
||
|
Audio(Str_8 id, const UInt_64 sampleRate, const DataType dataType, const UInt_8 channels, const UInt_64 frames);
|
||
|
|
||
|
Audio(Audio&& audio) noexcept;
|
||
|
|
||
|
Audio(const Audio& audio);
|
||
|
|
||
|
Audio& operator=(Audio&& audio) noexcept;
|
||
|
|
||
|
Audio& operator=(const Audio& audio);
|
||
|
|
||
|
operator const Byte*() const;
|
||
|
|
||
|
operator Byte*();
|
||
|
|
||
|
UInt_64 GetSampleRate() const;
|
||
|
|
||
|
DataType GetDataType() const;
|
||
|
|
||
|
UInt_8 GetByteDepth() const;
|
||
|
|
||
|
UInt_8 GetBitDepth() const;
|
||
|
|
||
|
UInt_8 GetChannels() const;
|
||
|
|
||
|
UInt_64 GetFrameCount() const;
|
||
|
|
||
|
UInt_64 GetSampleCount() const;
|
||
|
|
||
|
UInt_64 GetSize() const;
|
||
|
|
||
|
float GetLength() const;
|
||
|
|
||
|
Array<Byte> FrameAsMono(const UInt_64 frameIndex) const;
|
||
|
|
||
|
Array<Byte> FrameAsStereo(const UInt_64 frameIndex) const;
|
||
|
|
||
|
Array<Byte> FrameAsFive_One(const UInt_64 frameIndex) const;
|
||
|
|
||
|
Array<Byte> FrameAsSeven_One(const UInt_64 frameIndex) const;
|
||
|
|
||
|
SInt_8 SampleAsSInt_8(const UInt_64 sampleIndex) const;
|
||
|
|
||
|
SInt_16 SampleAsSInt_16(const UInt_64 sampleIndex) const;
|
||
|
|
||
|
float SampleAsFloat(const UInt_64 sampleIndex) const;
|
||
|
|
||
|
SInt_32 SampleAsSInt_32(const UInt_64 sampleIndex) const;
|
||
|
|
||
|
SInt_64 SampleAsSInt_64(const UInt_64 sampleIndex) const;
|
||
|
|
||
|
SInt_8 PeakAsSInt_8() const;
|
||
|
|
||
|
SInt_16 PeakAsSInt_16() const;
|
||
|
|
||
|
float PeakAsFloat() const;
|
||
|
|
||
|
SInt_32 PeakAsSInt_32() const;
|
||
|
|
||
|
SInt_64 PeakAsSInt_64() const;
|
||
|
|
||
|
void SetPeak(const UInt_64 size, const Byte* newPeak);
|
||
|
|
||
|
const Byte* GetPeak() const;
|
||
|
|
||
|
void ToDataType(const DataType newDataType);
|
||
|
|
||
|
Audio GetAsDataType(const DataType newDataType) const;
|
||
|
|
||
|
void ToChannels(const UInt_8 newChannels);
|
||
|
|
||
|
Audio GetAsChannels(const UInt_8 newChannels) const;
|
||
|
|
||
|
bool ToFile(const Str_8& filePath) const;
|
||
|
|
||
|
static Audio FromFile(const Str_8& filePath);
|
||
|
|
||
|
static Audio* FromFile_Heap(const Str_8& filePath);
|
||
|
|
||
|
static Audio FromFile(const Str_8& filePath, const DataType required);
|
||
|
|
||
|
static Audio* FromFile_Heap(const Str_8& filePath, const DataType required);
|
||
|
|
||
|
static Audio FromData(const Str_8& ext, const Str_8& id, Serializer<UInt_64>& data);
|
||
|
|
||
|
private:
|
||
|
void ToMono(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||
|
|
||
|
void Mono_to_Stereo(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||
|
|
||
|
void Five_One_to_Stereo(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||
|
|
||
|
void Seven_One_to_Stereo(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||
|
|
||
|
void Mono_to_Five_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||
|
|
||
|
void Stereo_to_Five_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||
|
|
||
|
void Seven_One_to_Five_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||
|
|
||
|
void Mono_to_Seven_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||
|
|
||
|
void Stereo_to_Seven_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||
|
|
||
|
void Five_One_to_Seven_One(const UInt_64 newFrameCount, Byte* newData, const UInt_64 frameOffset) const;
|
||
|
|
||
|
// To SInt_8
|
||
|
void SInt_16_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void Float_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void SInt_32_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void SInt_64_to_SInt_8(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
// To SInt_16
|
||
|
void SInt_8_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void Float_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void SInt_32_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void SInt_64_to_SInt_16(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
// To Float
|
||
|
void SInt_8_to_Float(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void SInt_16_to_Float(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void SInt_32_to_Float(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void SInt_64_to_Float(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
// To SInt_32
|
||
|
void SInt_8_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void SInt_16_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void Float_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void SInt_64_to_SInt_32(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
// To SInt_64
|
||
|
void SInt_8_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void SInt_16_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void Float_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||
|
|
||
|
void SInt_32_to_SInt_64(Byte* newData, Byte* newPeak) const;
|
||
|
};
|
||
|
}
|