This commit is contained in:
2024-09-03 05:37:23 -07:00
parent 6afa08df82
commit 25762b0c29
7 changed files with 163 additions and 309 deletions

View File

@@ -1879,6 +1879,9 @@ namespace ehs
/// @returns The character count.
static N Len(const T* const str)
{
if (!str)
return 0;
N count = 0;
while (str[count])
++count;

View File

@@ -3,14 +3,32 @@
#include "ehs/EHS.h"
#include "BaseAudioDevice.h"
#include <alsa/asoundlib.h>
#include <spa/param/audio/format-utils.h>
#include <pipewire/pipewire.h>
#include <pipewire/loop.h>
#include <pipewire/context.h>
#include <pipewire/stream.h>
#include <pipewire/keys.h>
namespace ehs
{
class EHS_LIB_IO AudioDevice : public BaseAudioDevice
{
private:
snd_pcm_t* hdl;
static Array<AudioDevice> devices;
static AudioDevice defOut;
static AudioDevice defIn;
UInt_32 id;
Str_8 name;
pw_loop *loop;
pw_context *context;
pw_core *core;
pw_stream *stream;
static void RegistryEventGlobal(void *user_data, UInt_32 id, UInt_32 permissions, const char *type, UInt_32 version, const spa_dict *props);
static void RegistryEventGlobalRemove(void *user_data, UInt_32 id);
public:
~AudioDevice() override;
@@ -31,16 +49,12 @@ namespace ehs
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;
UInt_64 SendStream(void *data, UInt_64 size) override;
bool IsValid() const override;
static AudioDevice GetDefault(const AudioDeviceType type);
static AudioDevice GetDefault(AudioDeviceType type);
static Array<AudioDevice> Get(const AudioDeviceType type, const AudioDeviceState state);
static Array<AudioDevice> Get(AudioDeviceType type, AudioDeviceState state);
};
}

View File

@@ -51,15 +51,17 @@ namespace ehs
virtual void CloseStream();
virtual UInt_64 SendStream(void *data, UInt_64 size);
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);
virtual void UnMap(UInt_64 offset, UInt_64 frames);
AudioDeviceType GetType() const;
void SetDataType(const DataType newDataType);
void SetDataType(DataType newDataType);
DataType GetDataType() const;
@@ -67,21 +69,21 @@ namespace ehs
UInt_16 GetBitDepth() const;
void SetSampleRate(const UInt_32 newSampleRate);
void SetSampleRate(UInt_32 newSampleRate);
UInt_32 GetSampleRate() const;
void SetChannels(const UInt_32 newChannels);
void SetChannels(UInt_32 newChannels);
UInt_16 GetChannels() const;
UInt_32 GetFrameSize() const;
void SetPeriod(const UInt_32 newPeriod);
void SetPeriod(UInt_32 newPeriod);
UInt_32 GetPeriod() const;
void SetLatency(const UInt_32 newLatency);
void SetLatency(UInt_32 newLatency);
UInt_32 GetLatency() const;
@@ -94,12 +96,12 @@ namespace ehs
/// 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);
static BaseAudioDevice GetDefault(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);
static Array<BaseAudioDevice> Get(AudioDeviceType type, AudioDeviceState state);
};
}