From 450300013cdcc34570365832b31024959e19b107 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 25 Apr 2014 11:34:46 +0200 Subject: Add peak audio levels to statistics --- src/StatsServer.cpp | 28 ++++++++++++++++++++++++++++ src/StatsServer.h | 14 ++++++++++++-- src/dabInputZmq.cpp | 3 +++ 3 files changed, 43 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/StatsServer.cpp b/src/StatsServer.cpp index 2e89134..be40920 100644 --- a/src/StatsServer.cpp +++ b/src/StatsServer.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include "StatsServer.h" #include "Log.h" @@ -69,6 +70,27 @@ void StatsServer::notifyBuffer(std::string id, long bufsize) } } +void StatsServer::notifyPeakLevels(std::string id, int peak_left, int peak_right) +{ + boost::mutex::scoped_lock lock(m_mutex); + + if (m_inputStats.count(id) == 0) { + etiLog.level(error) << + "Stats Server id '" << + id << "' does was not registered"; + return; + } + + InputStat& is = m_inputStats[id]; + if (peak_left > is.peak_left) { + is.peak_left = peak_left; + } + + if (peak_right > is.peak_right) { + is.peak_right = peak_right; + } +} + void StatsServer::notifyUnderrun(std::string id) { boost::mutex::scoped_lock lock(m_mutex); @@ -252,10 +274,16 @@ std::string InputStat::encodeJSON() { std::ostringstream ss; + /* convert to dB */ + int dB_l = peak_left ? round(20*log10((double)peak_left / INT16_MAX)) : -90; + int dB_r = peak_right ? round(20*log10((double)peak_right / INT16_MAX)) : -90; + ss << "{ \"inputstat\" : {" "\"min_fill\": " << min_fill_buffer << ", " "\"max_fill\": " << max_fill_buffer << ", " + "\"peak_left\": " << dB_l << ", " + "\"peak_right\": " << dB_r << ", " "\"num_underruns\": " << num_underruns << ", " "\"num_overruns\": " << num_overruns << " } }"; diff --git a/src/StatsServer.h b/src/StatsServer.h index 9510520..9eb08df 100644 --- a/src/StatsServer.h +++ b/src/StatsServer.h @@ -65,6 +65,10 @@ struct InputStat long num_underruns; long num_overruns; + // peak audio levels (linear 16-bit PCM) for the two channels + int peak_left; + int peak_right; + void reset() { min_fill_buffer = MIN_FILL_BUFFER_UNDEF; @@ -72,6 +76,9 @@ struct InputStat num_underruns = 0; num_overruns = 0; + + peak_left = 0; + peak_right = 0; } std::string encodeJSON(); @@ -99,9 +106,12 @@ class StatsServer } void registerInput(std::string id); - // The input notifies the StatsServer about a new buffer size - void notifyBuffer(std::string id, long bufsize); + /* The following notify functions are used by the input to + * inform the StatsServer about new values + */ + void notifyBuffer(std::string id, long bufsize); + void notifyPeakLevels(std::string id, int peak_left, int peak_right); void notifyUnderrun(std::string id); void notifyOverrun(std::string id); diff --git a/src/dabInputZmq.cpp b/src/dabInputZmq.cpp index 2a18588..1b45960 100644 --- a/src/dabInputZmq.cpp +++ b/src/dabInputZmq.cpp @@ -425,6 +425,9 @@ int DabInputZmqAAC::readFromSocket(size_t framesize) frame->encoder == ZMQ_ENCODER_FDK) { datalen = frame->datasize; data = ZMQ_FRAME_DATA(frame); + + global_stats->notifyPeakLevels(m_name, frame->audiolevel_left, + frame->audiolevel_right); } -- cgit v1.2.3