Skip to content

Commit

Permalink
Make PeakMeter decay itself
Browse files Browse the repository at this point in the history
  • Loading branch information
ryze312 committed Jun 2, 2024
1 parent dffe44e commit 486fec9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
9 changes: 0 additions & 9 deletions src/audio/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ AudioManager::AudioManager(const Glib::ustring &backends_string, DiscordClient &
#endif
}

Glib::signal_timeout().connect(sigc::mem_fun(*this, &AudioManager::DecayVolumeMeters), 40);

m_ok = true;
}

Expand All @@ -91,13 +89,6 @@ void AudioManager::Enumerate() {
);
}

bool AudioManager::DecayVolumeMeters() {
m_voice->GetCapture().GetPeakMeter().Decay();
m_voice->GetPlayback().GetClientStore().DecayPeakMeters();

return true;
}

bool AudioManager::OK() const {
return m_ok;
}
Expand Down
2 changes: 0 additions & 2 deletions src/audio/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class AudioManager {
void Enumerate();
static std::vector<ma_backend> ParseBackendsList(const Glib::ustring &list);

bool DecayVolumeMeters();

AudioDevices m_devices;

std::optional<AbaddonClient::Audio::Context> m_context;
Expand Down
12 changes: 8 additions & 4 deletions src/audio/voice/peak_meter/peak_meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace AbaddonClient::Audio::Voice {

PeakMeter::PeakMeter() noexcept {
Glib::signal_timeout().connect(sigc::mem_fun(*this, &PeakMeter::Decay), 40);
}

void PeakMeter::UpdatePeak(InputBuffer buffer) noexcept {
// Cache to prevent atomic operations in the loop
float peak = m_peak;
Expand All @@ -13,10 +17,6 @@ void PeakMeter::UpdatePeak(InputBuffer buffer) noexcept {
m_peak = peak;
}

void PeakMeter::Decay() noexcept {
m_peak = std::max(m_peak - 0.05f, 0.0f);
}

void PeakMeter::SetPeak(float peak) noexcept {
m_peak = std::max(m_peak.load(), peak);
}
Expand All @@ -25,5 +25,9 @@ float PeakMeter::GetPeak() const noexcept {
return m_peak;
}

bool PeakMeter::Decay() noexcept {
m_peak = std::max(m_peak - 0.05f, 0.0f);
return true;
}

}
8 changes: 7 additions & 1 deletion src/audio/voice/peak_meter/peak_meter.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#pragma once

#include <glibmm.h>

#include "audio/utils.hpp"


namespace AbaddonClient::Audio::Voice {

class PeakMeter {
public:
PeakMeter() noexcept;

void UpdatePeak(InputBuffer buffer) noexcept;
void Decay() noexcept;

void SetPeak(float peak) noexcept;
float GetPeak() const noexcept;
private:
bool Decay() noexcept;

std::atomic<float> m_peak = 0;
};

Expand Down
8 changes: 0 additions & 8 deletions src/audio/voice/playback/client_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ void ClientStore::WriteMixed(OutputBuffer buffer) noexcept {
}
}

void ClientStore::DecayPeakMeters() noexcept {
auto clients = m_clients.Lock();

for (auto& [_, client] : clients) {
client.GetPeakMeter().Decay();
}
}

void ClientStore::SetClientVolume(ClientID id, float volume) noexcept {
auto clients = m_clients.Lock();
auto client = clients->find(id);
Expand Down
1 change: 0 additions & 1 deletion src/audio/voice/playback/client_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class ClientStore {
void RemoveClient(ClientID id) noexcept;
void Clear() noexcept;

void DecayPeakMeters() noexcept;
void ClearAllBuffers() noexcept;

void SetClientVolume(ClientID id, float volume) noexcept;
Expand Down

0 comments on commit 486fec9

Please sign in to comment.