2023-12-17 03:29:08 -08:00
|
|
|
#pragma once
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
#include "Types.h"
|
|
|
|
#include "BaseObj.h"
|
2023-12-17 15:00:08 -08:00
|
|
|
#include "DataType.h"
|
|
|
|
#include "Str.h"
|
|
|
|
#include "Serializer.h"
|
|
|
|
#include "Vector.h"
|
|
|
|
#include "Array.h"
|
2023-12-17 03:29:08 -08:00
|
|
|
#include "AudioCodec.h"
|
|
|
|
|
2023-12-17 15:56:13 -08:00
|
|
|
namespace ehs
|
2023-12-17 03:29:08 -08:00
|
|
|
{
|
2023-12-18 02:13:20 -08:00
|
|
|
class Audio : public BaseObj
|
2023-12-17 03:29:08 -08:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
static Array<AudioCodec> codecs;
|
2023-12-18 02:13:20 -08:00
|
|
|
UInt_64 hashId;
|
|
|
|
Str_8 id;
|
2023-12-17 03:29:08 -08:00
|
|
|
UInt_64 sampleRate;
|
|
|
|
DataType dataType;
|
|
|
|
UInt_8 byteDepth;
|
|
|
|
UInt_8 channels;
|
|
|
|
UInt_64 frames;
|
|
|
|
float length;
|
|
|
|
Byte* data;
|
|
|
|
Byte* peak;
|
|
|
|
|
|
|
|
public:
|
2023-12-18 02:13:20 -08:00
|
|
|
static bool HasCodec(UInt_64 hashExt);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
|
|
|
static bool HasCodec(const Str_8& ext);
|
|
|
|
|
|
|
|
static bool AddCodec(AudioCodec codec);
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
static const AudioCodec* GetCodec(UInt_64 hashExt);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
|
|
|
static const AudioCodec* GetCodec(const Str_8& ext);
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
~Audio();
|
2023-12-17 03:29:08 -08:00
|
|
|
|
|
|
|
Audio();
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Audio(Str_8 id);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, UInt_64 frames, const Byte* data);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Serializer<UInt_64>& data);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Vector<Byte>& data);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Array<Byte>& data);
|
|
|
|
|
|
|
|
Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, UInt_64 frames);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
|
|
|
Audio(Audio&& audio) noexcept;
|
|
|
|
|
|
|
|
Audio(const Audio& audio);
|
|
|
|
|
|
|
|
Audio& operator=(Audio&& audio) noexcept;
|
|
|
|
|
|
|
|
Audio& operator=(const Audio& audio);
|
|
|
|
|
|
|
|
operator const Byte*() const;
|
|
|
|
|
|
|
|
operator Byte*();
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void Release();
|
|
|
|
|
|
|
|
UInt_64 GetHashId() const;
|
|
|
|
|
|
|
|
void SetId(Str_8 newId);
|
|
|
|
|
|
|
|
Str_8 GetId() const;
|
|
|
|
|
2023-12-17 03:29:08 -08:00
|
|
|
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;
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Array<Byte> FrameAsMono(UInt_64 frameIndex) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Array<Byte> FrameAsStereo(UInt_64 frameIndex) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Array<Byte> FrameAsFive_One(UInt_64 frameIndex) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Array<Byte> FrameAsSeven_One(UInt_64 frameIndex) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
SInt_8 SampleAsSInt_8(UInt_64 sampleIndex) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
SInt_16 SampleAsSInt_16(UInt_64 sampleIndex) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
float SampleAsFloat(UInt_64 sampleIndex) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
SInt_32 SampleAsSInt_32(UInt_64 sampleIndex) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
SInt_64 SampleAsSInt_64(UInt_64 sampleIndex) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
|
|
|
SInt_8 PeakAsSInt_8() const;
|
|
|
|
|
|
|
|
SInt_16 PeakAsSInt_16() const;
|
|
|
|
|
|
|
|
float PeakAsFloat() const;
|
|
|
|
|
|
|
|
SInt_32 PeakAsSInt_32() const;
|
|
|
|
|
|
|
|
SInt_64 PeakAsSInt_64() const;
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void SetPeak(UInt_64 size, const Byte* newPeak);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
|
|
|
const Byte* GetPeak() const;
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void ToDataType(DataType newDataType);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Audio GetAsDataType(DataType newDataType) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void ToChannels(UInt_8 newChannels);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Audio GetAsChannels(UInt_8 newChannels) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
|
|
|
bool ToFile(const Str_8& filePath) const;
|
|
|
|
|
|
|
|
static Audio FromFile(const Str_8& filePath);
|
|
|
|
|
|
|
|
static Audio* FromFile_Heap(const Str_8& filePath);
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
static Audio FromFile(const Str_8& filePath, DataType required);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
static Audio* FromFile_Heap(const Str_8& filePath, DataType required);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
static Audio FromData(Str_8 id, const Str_8& ext, Serializer<UInt_64>& data);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
|
|
|
private:
|
2023-12-18 02:13:20 -08:00
|
|
|
void ToMono(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void Mono_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void Five_One_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void Seven_One_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void Mono_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void Stereo_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void Seven_One_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void Mono_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void Stereo_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
void Five_One_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
|
2023-12-17 03:29:08 -08:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
}
|