Audio System + Drivers (#562)

This commit is contained in:
Shadowtrance
2026-07-14 16:34:29 +10:00
committed by GitHub
parent fa4a6e255c
commit 955416dac8
137 changed files with 8847 additions and 387 deletions
@@ -0,0 +1,48 @@
#pragma once
#include <Tactility/PubSub.h>
#include <memory>
namespace tt::service::audio {
enum class AudioEvent {
InputEnabledChanged,
OutputEnabledChanged,
InputVolumeChanged,
OutputVolumeChanged,
InputMuteChanged,
OutputMuteChanged
};
/** @return the audio pubsub that broadcasts AudioEvent objects */
std::shared_ptr<PubSub<AudioEvent>> getPubsub();
/** @return true when an AUDIO_STREAM_TYPE device is bound and ready */
bool isAvailable();
/** @return true if a codec supporting input (microphone) is bound, e.g. a device with a speaker but no mic returns false */
bool isInputAvailable();
/** @return true if a codec supporting output (speaker) is bound, e.g. a device with a mic but no speaker returns false */
bool isOutputAvailable();
bool isInputEnabled();
void setInputEnabled(bool enabled);
bool isOutputEnabled();
void setOutputEnabled(bool enabled);
float getInputVolume();
void setInputVolume(float percent);
float getOutputVolume();
void setOutputVolume(float percent);
bool isInputMuted();
void setInputMuted(bool muted);
bool isOutputMuted();
void setOutputMuted(bool muted);
} // namespace tt::service::audio
@@ -0,0 +1,68 @@
#pragma once
#include <Tactility/Mutex.h>
#include <Tactility/PubSub.h>
#include <Tactility/Timer.h>
#include <Tactility/service/Service.h>
#include <Tactility/service/ServiceContext.h>
#include <Tactility/service/audio/Audio.h>
#include <tactility/drivers/audio_stream.h>
#include <memory>
struct Device;
namespace tt::service::audio {
class AudioService final : public Service {
Mutex mutex;
Device* streamDevice = nullptr;
std::shared_ptr<PubSub<AudioEvent>> pubsub = std::make_shared<PubSub<AudioEvent>>();
std::unique_ptr<Timer> persistTimer;
bool persistPending = false;
void findStreamDevice();
void primeFromSettings() const;
void schedulePersist();
void persistIfPending();
void onDriverChanged(enum AudioCodecDirection direction, enum AudioStreamChange change);
static void onDriverChangedCallback(Device* device, enum AudioCodecDirection direction, enum AudioStreamChange change, void* userData);
public:
bool onStart(ServiceContext& serviceContext) override;
void onStop(ServiceContext& serviceContext) override;
bool isAvailable() const;
/** @return true if a codec supporting input (microphone) is bound for this device */
bool isInputAvailable() const;
/** @return true if a codec supporting output (speaker) is bound for this device */
bool isOutputAvailable() const;
bool isInputEnabled() const;
void setInputEnabled(bool enabled);
bool isOutputEnabled() const;
void setOutputEnabled(bool enabled);
float getInputVolume() const;
void setInputVolume(float percent);
float getOutputVolume() const;
void setOutputVolume(float percent);
bool isInputMuted() const;
void setInputMuted(bool muted);
bool isOutputMuted() const;
void setOutputMuted(bool muted);
std::shared_ptr<PubSub<AudioEvent>> getPubsub() const { return pubsub; }
};
std::shared_ptr<AudioService> findAudioService();
} // namespace tt::service::audio
@@ -0,0 +1,22 @@
#pragma once
namespace tt::settings::audio {
struct AudioSettings {
bool inputEnabled;
bool outputEnabled;
bool inputMuted;
bool outputMuted;
float inputVolume; // 0..100
float outputVolume; // 0..100
};
bool load(AudioSettings& settings);
AudioSettings loadOrGetDefault();
AudioSettings getDefault();
bool save(const AudioSettings& settings);
} // namespace tt::settings::audio