EHS
Loading...
Searching...
No Matches
Audio.h
Go to the documentation of this file.
1#pragma once
2
3#include "ehs/Types.h"
4#include "ehs/DataType.h"
5#include "ehs/Str.h"
6#include "ehs/Serializer.h"
7#include "ehs/Vector.h"
8#include "ehs/Array.h"
9#include "ehs/io/Resource.h"
10#include "AudioCodec.h"
11
12namespace ehs
13{
14 class EHS_LIB_IO Audio : public Resource
15 {
16 private:
17 static Array<AudioCodec> codecs;
18 UInt_64 sampleRate;
19 DataType dataType;
20 UInt_8 byteDepth;
21 UInt_8 channels;
22 UInt_64 frames;
23 float length;
24 Byte* data;
25 Byte* peak;
26
27 public:
28 static bool HasCodec(UInt_64 hashExt);
29
30 static bool HasCodec(const Str_8& ext);
31
32 static bool AddCodec(AudioCodec codec);
33
34 static const AudioCodec* GetCodec(UInt_64 hashExt);
35
36 static const AudioCodec* GetCodec(const Str_8& ext);
37
38 ~Audio() override;
39
40 Audio();
41
42 Audio(const Str_8& filePath);
43
44 Audio(const Str_8& filePath, DataType type);
45
46 Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, UInt_64 frames, const Byte* data);
47
48 Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Serializer<UInt_64>& data);
49
50 Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Vector<Byte>& data);
51
52 Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, const Array<Byte>& data);
53
54 Audio(Str_8 id, UInt_64 sampleRate, DataType dataType, UInt_8 channels, UInt_64 frames);
55
56 Audio(Audio&& audio) noexcept;
57
58 Audio(const Audio& audio);
59
60 Audio& operator=(Audio&& audio) noexcept;
61
62 Audio& operator=(const Audio& audio);
63
64 operator const Byte*() const;
65
66 operator Byte*();
67
68 void Release() override;
69
70 UInt_64 GetSampleRate() const;
71
72 DataType GetDataType() const;
73
74 UInt_8 GetByteDepth() const;
75
76 UInt_8 GetBitDepth() const;
77
78 UInt_8 GetChannels() const;
79
80 UInt_64 GetFrameCount() const;
81
82 UInt_64 GetSampleCount() const;
83
84 UInt_8 GetFrameSize() const;
85
86 UInt_64 GetSize() const;
87
88 float GetLength() const;
89
90 Byte* GetFrame(UInt_64 frameIndex) const;
91
92 Array<Byte> FrameAsMono(UInt_64 frameIndex) const;
93
94 Array<Byte> FrameAsStereo(UInt_64 frameIndex) const;
95
96 Array<Byte> FrameAsFive_One(UInt_64 frameIndex) const;
97
98 Array<Byte> FrameAsSeven_One(UInt_64 frameIndex) const;
99
100 SInt_8 SampleAsSInt_8(UInt_64 sampleIndex) const;
101
102 SInt_16 SampleAsSInt_16(UInt_64 sampleIndex) const;
103
104 float SampleAsFloat(UInt_64 sampleIndex) const;
105
106 SInt_32 SampleAsSInt_32(UInt_64 sampleIndex) const;
107
108 SInt_64 SampleAsSInt_64(UInt_64 sampleIndex) const;
109
110 SInt_8 PeakAsSInt_8() const;
111
112 SInt_16 PeakAsSInt_16() const;
113
114 float PeakAsFloat() const;
115
116 SInt_32 PeakAsSInt_32() const;
117
118 SInt_64 PeakAsSInt_64() const;
119
120 void SetPeak(UInt_64 size, const Byte* newPeak);
121
122 const Byte* GetPeak() const;
123
124 void ToDataType(DataType newDataType);
125
126 Audio GetAsDataType(DataType newDataType) const;
127
128 void ToChannels(UInt_8 newChannels);
129
130 Audio GetAsChannels(UInt_8 newChannels) const;
131
132 bool Export(const Str_8& filePath) const;
133
134 private:
135 void ToMono(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
136
137 void Mono_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
138
139 void Five_One_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
140
141 void Seven_One_to_Stereo(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
142
143 void Mono_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
144
145 void Stereo_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
146
147 void Seven_One_to_Five_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
148
149 void Mono_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
150
151 void Stereo_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
152
153 void Five_One_to_Seven_One(UInt_64 newFrameCount, Byte* newData, UInt_64 frameOffset) const;
154
155 // To SInt_8
156 void SInt_16_to_SInt_8(Byte* newData, Byte* newPeak) const;
157
158 void Float_to_SInt_8(Byte* newData, Byte* newPeak) const;
159
160 void SInt_32_to_SInt_8(Byte* newData, Byte* newPeak) const;
161
162 void SInt_64_to_SInt_8(Byte* newData, Byte* newPeak) const;
163
164 // To SInt_16
165 void SInt_8_to_SInt_16(Byte* newData, Byte* newPeak) const;
166
167 void Float_to_SInt_16(Byte* newData, Byte* newPeak) const;
168
169 void SInt_32_to_SInt_16(Byte* newData, Byte* newPeak) const;
170
171 void SInt_64_to_SInt_16(Byte* newData, Byte* newPeak) const;
172
173 // To Float
174 void SInt_8_to_Float(Byte* newData, Byte* newPeak) const;
175
176 void SInt_16_to_Float(Byte* newData, Byte* newPeak) const;
177
178 void SInt_32_to_Float(Byte* newData, Byte* newPeak) const;
179
180 void SInt_64_to_Float(Byte* newData, Byte* newPeak) const;
181
182 // To SInt_32
183 void SInt_8_to_SInt_32(Byte* newData, Byte* newPeak) const;
184
185 void SInt_16_to_SInt_32(Byte* newData, Byte* newPeak) const;
186
187 void Float_to_SInt_32(Byte* newData, Byte* newPeak) const;
188
189 void SInt_64_to_SInt_32(Byte* newData, Byte* newPeak) const;
190
191 // To SInt_64
192 void SInt_8_to_SInt_64(Byte* newData, Byte* newPeak) const;
193
194 void SInt_16_to_SInt_64(Byte* newData, Byte* newPeak) const;
195
196 void Float_to_SInt_64(Byte* newData, Byte* newPeak) const;
197
198 void SInt_32_to_SInt_64(Byte* newData, Byte* newPeak) const;
199 };
200
201 bool EncodeEHA(const ehs::AudioCodec* codec, ehs::Serializer<ehs::UInt_64>& out, const ehs::Audio* in);
202
204
206}
Definition Array.h:16
Definition AudioCodec.h:12
Definition Audio.h:15
UInt_64 GetSampleRate() const
Definition Audio.cpp:258
static bool HasCodec(UInt_64 hashExt)
Definition Audio.cpp:9
void Release() override
Definition Audio.cpp:244
void SetPeak(UInt_64 size, const Byte *newPeak)
Definition Audio.cpp:603
Array< Byte > FrameAsFive_One(UInt_64 frameIndex) const
Definition Audio.cpp:351
void ToChannels(UInt_8 newChannels)
Definition Audio.cpp:733
Audio()
Definition Audio.cpp:53
SInt_8 SampleAsSInt_8(UInt_64 sampleIndex) const
Definition Audio.cpp:413
Array< Byte > FrameAsSeven_One(UInt_64 frameIndex) const
Definition Audio.cpp:382
UInt_8 GetBitDepth() const
Definition Audio.cpp:273
SInt_64 SampleAsSInt_64(UInt_64 sampleIndex) const
Definition Audio.cpp:489
Audio GetAsChannels(UInt_8 newChannels) const
Definition Audio.cpp:802
Byte * GetFrame(UInt_64 frameIndex) const
Definition Audio.cpp:308
SInt_16 PeakAsSInt_16() const
Definition Audio.cpp:527
void ToDataType(DataType newDataType)
Definition Audio.cpp:613
static const AudioCodec * GetCodec(UInt_64 hashExt)
Definition Audio.cpp:33
SInt_64 PeakAsSInt_64() const
Definition Audio.cpp:584
UInt_64 GetSize() const
Definition Audio.cpp:298
UInt_64 GetFrameCount() const
Definition Audio.cpp:283
UInt_8 GetByteDepth() const
Definition Audio.cpp:268
SInt_16 SampleAsSInt_16(UInt_64 sampleIndex) const
Definition Audio.cpp:432
UInt_8 GetFrameSize() const
Definition Audio.cpp:293
bool Export(const Str_8 &filePath) const
Definition Audio.cpp:907
UInt_8 GetChannels() const
Definition Audio.cpp:278
SInt_32 PeakAsSInt_32() const
Definition Audio.cpp:565
float GetLength() const
Definition Audio.cpp:303
Array< Byte > FrameAsMono(UInt_64 frameIndex) const
Definition Audio.cpp:313
float SampleAsFloat(UInt_64 sampleIndex) const
Definition Audio.cpp:451
UInt_64 GetSampleCount() const
Definition Audio.cpp:288
Audio GetAsDataType(DataType newDataType) const
Definition Audio.cpp:673
float PeakAsFloat() const
Definition Audio.cpp:546
DataType GetDataType() const
Definition Audio.cpp:263
const Byte * GetPeak() const
Definition Audio.cpp:608
SInt_32 SampleAsSInt_32(UInt_64 sampleIndex) const
Definition Audio.cpp:470
SInt_8 PeakAsSInt_8() const
Definition Audio.cpp:508
Audio & operator=(Audio &&audio) noexcept
Definition Audio.cpp:179
Array< Byte > FrameAsStereo(UInt_64 frameIndex) const
Definition Audio.cpp:320
static bool AddCodec(AudioCodec codec)
Definition Audio.cpp:23
Resource()
Definition Resource.cpp:5
Definition Serializer.h:25
Definition Vector.h:18
Definition Anchor.h:6
signed int SInt_32
Definition Types.h:50
unsigned char UInt_8
Definition Types.h:43
bool DecodeWAV(const ehs::AudioCodec *codec, ehs::Serializer< ehs::UInt_64 > &in, ehs::Audio *out)
Definition Audio.cpp:1961
bool DecodeEHA(const ehs::AudioCodec *codec, ehs::Serializer< ehs::UInt_64 > &in, ehs::Audio *out)
Definition Audio.cpp:1935
Str< Char_8, UInt_64 > Str_8
Definition Str.h:1953
DataType
Definition DataType.h:8
unsigned char Byte
Definition Types.h:39
signed char SInt_8
Definition Types.h:44
signed short SInt_16
Definition Types.h:47
bool EncodeEHA(const ehs::AudioCodec *codec, ehs::Serializer< ehs::UInt_64 > &out, const ehs::Audio *in)
Definition Audio.cpp:1913