2022-10-04 07:27:27 +00:00
|
|
|
// lasp_ppm.h
|
|
|
|
//
|
|
|
|
// Author: J.A. de Jong - ASCEE
|
|
|
|
//
|
|
|
|
// Description: Peak Programme Meter
|
|
|
|
#pragma once
|
|
|
|
#include "lasp_filter.h"
|
|
|
|
#include "lasp_mathtypes.h"
|
|
|
|
#include "lasp_threadedindatahandler.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \addtogroup dsp
|
|
|
|
* @{
|
2022-10-04 07:48:32 +00:00
|
|
|
*
|
|
|
|
* \addtogroup rt
|
|
|
|
* @{
|
2022-10-04 07:27:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Digital Peak Programme Meter (PPM). Let the latest maximum flow away
|
|
|
|
* with a certain amount of dB/s. If a new peak is found, it goes up again.
|
|
|
|
* Also detects clipping.
|
|
|
|
* */
|
2023-06-09 08:43:04 +00:00
|
|
|
class PPMHandler : public ThreadedInDataHandler<PPMHandler> {
|
2022-10-04 07:27:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Assuming full scale of a signal is +/- 1.0. If a value is found
|
|
|
|
*/
|
|
|
|
static inline const d clip_point = 0.98;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief How long it takes in [s] after a clip event has happened, that we
|
|
|
|
* are actually still in 'clip' mode.
|
|
|
|
*/
|
|
|
|
static inline const d clip_indication_time = 3.0;
|
|
|
|
|
|
|
|
const d _decay_dBps;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Inverse of block sampling frequency [s]: (framesPerBlock/fs)
|
|
|
|
*/
|
|
|
|
d _dt;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 1st order low_pass value of levels, based on _decay_dBps;
|
|
|
|
*/
|
|
|
|
d _alpha;
|
|
|
|
|
|
|
|
mutable std::mutex _mtx;
|
|
|
|
/**
|
|
|
|
* @brief Current maximum values
|
|
|
|
*/
|
2022-10-10 17:17:38 +00:00
|
|
|
vd _cur_max;
|
2022-10-04 07:27:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief How long ago the last clip has happened. Negative in case no clip
|
|
|
|
* has happened.
|
|
|
|
*/
|
|
|
|
vd _clip_time;
|
|
|
|
|
2022-10-17 17:37:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Storage for maximum values
|
|
|
|
*/
|
|
|
|
vd _max_range;
|
|
|
|
|
2022-10-04 07:27:27 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Constructs Peak Programme Meter
|
|
|
|
*
|
2023-06-09 08:43:04 +00:00
|
|
|
* @param mgr Stream Mgr to install callbacks for
|
2022-10-04 07:27:27 +00:00
|
|
|
* @param decay_dBps The level decay in units dB/s, after a peak has been
|
|
|
|
* hit.
|
|
|
|
*/
|
2023-06-07 19:49:07 +00:00
|
|
|
PPMHandler(SmgrHandle mgr,const d decay_dBps = 20.0);
|
2022-10-04 07:27:27 +00:00
|
|
|
~PPMHandler();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the current values of the PPM. Returns an array of levels in dB
|
|
|
|
* and a vector of True's.
|
|
|
|
*
|
|
|
|
* @return Current levels in [dB], clipping indication
|
|
|
|
*/
|
|
|
|
std::tuple<vd,arma::uvec> getCurrentValue() const;
|
|
|
|
|
2023-01-20 14:59:08 +00:00
|
|
|
/**
|
|
|
|
* @brief Implements callback on thread
|
|
|
|
*
|
|
|
|
* @param d DaqData to work with
|
|
|
|
*
|
|
|
|
* @return true when stream should continue.
|
|
|
|
*/
|
2023-06-09 08:43:04 +00:00
|
|
|
void inCallback(const DaqData& d);
|
|
|
|
void reset(const Daq*);
|
2022-10-04 07:27:27 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @} */
|
2022-10-04 07:48:32 +00:00
|
|
|
/** @} */
|