TeaSpeak-Client/native/serverconnection/src/audio/AudioLevelMeter.h

37 lines
1.3 KiB
C++

#pragma once
#include "./driver/AudioDriver.h"
namespace tc::audio {
/**
* Note: Within the observer callback no methods of the level meter should be called nor the level meter should be destructed.
*/
class AudioLevelMeter : public AudioDeviceRecord::Consumer {
public:
struct Observer {
public:
virtual void input_level_changed(float /* new level */) = 0;
};
explicit AudioLevelMeter(std::shared_ptr<AudioDevice> /* target device */);
virtual ~AudioLevelMeter();
[[nodiscard]] bool start(std::string& /* error */);
void stop();
[[nodiscard]] bool running() const;
[[nodiscard]] inline float current_volume() const { return this->current_audio_volume; }
void register_observer(Observer* /* observer */);
bool unregister_observer(Observer* /* observer */);
private:
std::shared_ptr<AudioDevice> target_device{};
mutable std::mutex recorder_mutex{};
std::shared_ptr<AudioDeviceRecord> recorder_instance{};
std::vector<Observer*> registered_observer{};
float current_audio_volume{0.f};
void consume(const void *, size_t, size_t) override;
};
}