Reorganized project again.

This commit is contained in:
2023-12-17 15:56:13 -08:00
parent 54b9e82789
commit 3acb78f247
250 changed files with 1586 additions and 1586 deletions

199
include/io/audio/Audio.h Normal file
View File

@@ -0,0 +1,199 @@
#pragma once
#include "EHS.h"
#include "DataType.h"
#include "Str.h"
#include "Serializer.h"
#include "Vector.h"
#include "Array.h"
#include "AudioCodec.h"
namespace ehs
{
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;
};
}

View File

@@ -0,0 +1,48 @@
#pragma once
#include "EHS.h"
#include "Str.h"
#include "io/File.h"
namespace ehs
{
class Audio;
class AudioCodec
{
private:
Str_8 id;
UInt_64 hashExt;
Str_8 ext;
Endianness endianness;
bool (*encodeCb)(const AudioCodec* const, Serializer<UInt_64>&, const Audio*);
bool (*decodeCb)(const AudioCodec* const, Serializer<UInt_64>&, Audio*);
public:
AudioCodec();
AudioCodec(Str_8 id, Str_8 ext, const Endianness end,
bool (*encodeCb)(const AudioCodec* const, Serializer<UInt_64>&, const Audio*),
bool (*decodeCb)(const AudioCodec* const, Serializer<UInt_64>&, Audio*));
AudioCodec(AudioCodec&& codec) noexcept;
AudioCodec(const AudioCodec& codec);
AudioCodec& operator=(AudioCodec&& codec) noexcept;
AudioCodec& operator=(const AudioCodec& codec);
Str_8 GetId() const;
UInt_64 GetHashExt() const;
Str_8 GetExt() const;
Endianness GetEndianness() const;
bool Encode(Serializer<UInt_64>& out, const Audio* in) const;
bool Decode(Serializer<UInt_64>& in, Audio* out) const;
};
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "EHS.h"
#if defined(EHS_OS_WINDOWS)
#include "AudioDevice_W32.h"
#elif defined(EHS_OS_LINUX)
#include "AudioDevice_ALSA.h"
#endif

View File

@@ -0,0 +1,46 @@
#pragma once
#include "EHS.h"
#include "BaseAudioDevice.h"
#include <alsa/asoundlib.h>
namespace ehs
{
class AudioDevice : public BaseAudioDevice
{
private:
snd_pcm_t* hdl;
public:
~AudioDevice() override;
AudioDevice();
AudioDevice(AudioDevice&& device) noexcept;
AudioDevice(const AudioDevice& device);
AudioDevice& operator=(AudioDevice&& device) noexcept;
AudioDevice& operator=(const AudioDevice& device);
void Release() override;
void OpenStream() override;
void CloseStream() override;
UInt_64 GetAvailFrames() const override;
Byte* Map(UInt_64* offset, UInt_64* frames) override;
void UnMap(const UInt_64 offset, const UInt_64 frames) override;
bool IsValid() const override;
static AudioDevice GetDefault(const AudioDeviceType type);
static Array<AudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
};
}

View File

@@ -0,0 +1,66 @@
#pragma once
#include "EHS.h"
#include "BaseAudioDevice.h"
#include <initguid.h>
#include <mmdeviceapi.h>
#include <functiondiscoverykeys_devpkey.h>
#include <Audioclient.h>
struct IMMDevice;
namespace ehs
{
class AudioDevice : public BaseAudioDevice
{
private:
IMMDevice* hdl;
IAudioClient* client;
IAudioRenderClient* playbackClient;
IAudioCaptureClient* captureClient;
public:
~AudioDevice() override;
AudioDevice();
AudioDevice(AudioDevice&& device) noexcept;
AudioDevice(const AudioDevice& device);
AudioDevice& operator=(AudioDevice&& device) noexcept;
AudioDevice& operator=(const AudioDevice& device);
void Release() override;
void OpenStream() override;
void CloseStream() override;
UInt_64 GetAvailFrames() const override;
Byte* Map(UInt_64* offset, UInt_64* frames) override;
void UnMap(const UInt_64 offset, const UInt_64 frames) override;
Str_32 GetInterfaceName_32() const;
Str_16 GetInterfaceName_16() const;
Str_8 GetInterfaceName_8() const;
Str_32 GetName_32() const;
Str_16 GetName_16() const;
Str_8 GetName_8() const;
bool IsValid() const override;
static AudioDevice GetDefault(const AudioDeviceType type);
static Array<AudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
};
}

View File

@@ -0,0 +1,105 @@
#pragma once
#include "EHS.h"
#include "Str.h"
#include "Vector.h"
#include "Array.h"
#include "DataType.h"
namespace ehs
{
enum class AudioDeviceType
{
OUTPUT = 0x0,
INPUT = 0x1,
ALL = 0x2
};
enum class AudioDeviceState
{
ACTIVE = 0x1,
DISABLED = 0x2,
NOT_PRESENT = 0x4,
UNPLUGGED = 0x8
};
class BaseAudioDevice
{
protected:
AudioDeviceType type;
DataType dataType;
UInt_16 bitDepth;
UInt_32 sampleRate;
UInt_32 channels;
UInt_32 period;
UInt_32 latency;
UInt_64 maxFrames;
bool streaming;
public:
virtual ~BaseAudioDevice() = default;
BaseAudioDevice();
BaseAudioDevice(const BaseAudioDevice& device);
BaseAudioDevice& operator=(const BaseAudioDevice& device);
virtual void Release();
virtual void OpenStream();
virtual void CloseStream();
virtual UInt_64 GetAvailFrames() const;
virtual Byte* Map(UInt_64* offset, UInt_64* frames);
virtual void UnMap(const UInt_64 offset, const UInt_64 frames);
AudioDeviceType GetType() const;
void SetDataType(const DataType newDataType);
DataType GetDataType() const;
UInt_8 GetByteDepth() const;
UInt_16 GetBitDepth() const;
void SetSampleRate(const UInt_32 newSampleRate);
UInt_32 GetSampleRate() const;
void SetChannels(const UInt_32 newChannels);
UInt_16 GetChannels() const;
UInt_32 GetFrameSize() const;
void SetPeriod(const UInt_32 newPeriod);
UInt_32 GetPeriod() const;
void SetLatency(const UInt_32 newLatency);
UInt_32 GetLatency() const;
UInt_64 GetMaxFrames() const;
bool IsStreaming() const;
virtual bool IsValid() const;
/// Retrieves the default audio input/output device.
/// @param [in] type The audio device type to retrieve.
/// @param [out] device The default audio device.
static BaseAudioDevice GetDefault(const AudioDeviceType type);
/// Retrieves a list of audio input/output devices.
/// @param [in] type The audio device type to retrieve.
/// @param [in] state The audio device state to retrieve.
/// @param [out] devices The list of audio devices.
static Array<BaseAudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
};
}