spandsp: power_meter.h Source File

spandsp 0.0.6

power_meter.h
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * power_meter.h
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2003 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 2.1,
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#if !defined(_POWER_METER_H_)
27#define _POWER_METER_H_
28
29/*! \page power_meter_page Power metering
30
31\section power_meter_page_sec_1 What does it do?
32The power metering module implements a simple IIR type running power meter. The damping
33factor of the IIR is selectable when the meter instance is created.
34
35Note that the definition of dBOv is quite vague in most places - is it peak since wave,
36peak square wave, etc.? This code is based on the well defined wording in RFC3389:
37
38"For example, in the case of a u-law system, the reference would be a square wave with
39values +/-8031, and this square wave represents 0dBov. This translates into 6.18dBm0".
40
41\section power_meter_page_sec_2 How does it work?
42*/
43
44/*!
45 Power meter descriptor. This defines the working state for a
46 single instance of a power measurement device.
47*/
48 typedef struct
49{
50 /*! The shift factor, which controls the damping of the power meter. */
51 int shift;
52
53 /*! The current power reading. */
54 int32_t reading;
55} power_meter_t;
56
57 typedef struct
58{
59 power_meter_t short_term;
60 power_meter_t medium_term;
61 int signal_present;
62 int32_t surge;
63 int32_t sag;
64 int32_t min;
65} power_surge_detector_state_t;
66
67#if defined(__cplusplus)
68extern "C"
69{
70#endif
71
72/*! Initialise a power meter context.
73 \brief Initialise a power meter context.
74 \param s The power meter context.
75 \param shift The shift to be used by the IIR filter.
76 \return The power meter context. */
77SPAN_DECLARE(power_meter_t *) power_meter_init(power_meter_t *s, int shift);
78
79SPAN_DECLARE(int) power_meter_release(power_meter_t *s);
80
81SPAN_DECLARE(int) power_meter_free(power_meter_t *s);
82
83/*! Change the damping factor of a power meter context.
84 \brief Change the damping factor of a power meter context.
85 \param s The power meter context.
86 \param shift The new shift to be used by the IIR filter.
87 \return The power meter context. */
88SPAN_DECLARE(power_meter_t *) power_meter_damping(power_meter_t *s, int shift);
89
90/*! Update a power meter.
91 \brief Update a power meter.
92 \param s The power meter context.
93 \param amp The amplitude of the new audio sample.
94 \return The current power meter reading. */
95SPAN_DECLARE(int32_t) power_meter_update(power_meter_t *s, int16_t amp);
96
97/*! Get the current power meter reading.
98 \brief Get the current power meter reading.
99 \param s The power meter context.
100 \return The current power meter reading. */
101SPAN_DECLARE(int32_t) power_meter_current(power_meter_t *s);
102
103/*! Get the current power meter reading, in dBm0.
104 \brief Get the current power meter reading, in dBm0.
105 \param s The power meter context.
106 \return The current power meter reading, in dBm0. */
107SPAN_DECLARE(float) power_meter_current_dbm0(power_meter_t *s);
108
109/*! Get the current power meter reading, in dBOv.
110 \brief Get the current power meter reading, in dBOv.
111 \param s The power meter context.
112 \return The current power meter reading, in dBOv. */
113SPAN_DECLARE(float) power_meter_current_dbov(power_meter_t *s);
114
115/*! Get the power meter reading which represents a specified power level in dBm0.
116 \brief Get the current power meter reading, in dBm0.
117 \param level A power level, in dB0m.
118 \return The equivalent power meter reading. */
119SPAN_DECLARE(int32_t) power_meter_level_dbm0(float level);
120
121/*! Get the power meter reading which represents a specified power level in dBOv.
122 \brief Get the current power meter reading, in dBOv.
123 \param level A power level, in dBOv.
124 \return The equivalent power meter reading. */
125SPAN_DECLARE(int32_t) power_meter_level_dbov(float level);
126
127SPAN_DECLARE(int32_t) power_surge_detector(power_surge_detector_state_t *s, int16_t amp);
128
129/*! Get the current surge detector short term meter reading, in dBm0.
130 \brief Get the current surge detector meter reading, in dBm0.
131 \param s The power surge detector context.
132 \return The current power surge detector power reading, in dBm0. */
133SPAN_DECLARE(float) power_surge_detector_current_dbm0(power_surge_detector_state_t *s);
134
135/*! Get the current surge detector short term meter reading, in dBOv.
136 \brief Get the current surge detector meter reading, in dBOv.
137 \param s The power surge detector context.
138 \return The current power surge detector power reading, in dBOv. */
139SPAN_DECLARE(float) power_surge_detector_current_dbov(power_surge_detector_state_t *s);
140
141SPAN_DECLARE(power_surge_detector_state_t *) power_surge_detector_init(power_surge_detector_state_t *s, float min, float surge);
142
143SPAN_DECLARE(int) power_surge_detector_release(power_surge_detector_state_t *s);
144
145SPAN_DECLARE(int) power_surge_detector_free(power_surge_detector_state_t *s);
146
147#if defined(__cplusplus)
148}
149#endif
150
151#endif
152/*- End of file ------------------------------------------------------------*/
power_meter_current
int32_t power_meter_current(power_meter_t *s)
Get the current power meter reading.
Definition power_meter.c:114
power_meter_level_dbm0
int32_t power_meter_level_dbm0(float level)
Get the current power meter reading, in dBm0.
Definition power_meter.c:91
power_meter_level_dbov
int32_t power_meter_level_dbov(float level)
Get the current power meter reading, in dBOv.
Definition power_meter.c:103
power_meter_update
int32_t power_meter_update(power_meter_t *s, int16_t amp)
Update a power meter.
Definition power_meter.c:84
power_surge_detector_current_dbm0
float power_surge_detector_current_dbm0(power_surge_detector_state_t *s)
Get the current surge detector meter reading, in dBm0.
Definition power_meter.c:166
power_surge_detector_current_dbov
float power_surge_detector_current_dbov(power_surge_detector_state_t *s)
Get the current surge detector meter reading, in dBOv.
Definition power_meter.c:172
power_meter_init
power_meter_t * power_meter_init(power_meter_t *s, int shift)
Initialise a power meter context.
Definition power_meter.c:50
power_meter_current_dbm0
float power_meter_current_dbm0(power_meter_t *s)
Get the current power meter reading, in dBm0.
Definition power_meter.c:120
power_meter_current_dbov
float power_meter_current_dbov(power_meter_t *s)
Get the current power meter reading, in dBOv.
Definition power_meter.c:129
power_meter_damping
power_meter_t * power_meter_damping(power_meter_t *s, int shift)
Change the damping factor of a power meter context.
Definition power_meter.c:77
power_meter_t
Definition power_meter.h:49
power_meter_t::reading
int32_t reading
Definition power_meter.h:54
power_meter_t::shift
int shift
Definition power_meter.h:51
power_surge_detector_state_t
Definition power_meter.h:58