comparison spandsp-0.0.6pre17/src/spandsp/power_meter.h @ 4:26cd8f1ef0b1

import spandsp-0.0.6pre17
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 15:50:58 +0200
parents
children
comparison
equal deleted inserted replaced
3:c6c5a16ce2f2 4:26cd8f1ef0b1
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 * $Id: power_meter.h,v 1.19 2009/05/19 14:15:09 steveu Exp $
26 */
27
28 #if !defined(_POWER_METER_H_)
29 #define _POWER_METER_H_
30
31 /*! \page power_meter_page Power metering
32
33 \section power_meter_page_sec_1 What does it do?
34 The power metering module implements a simple IIR type running power meter. The damping
35 factor of the IIR is selectable when the meter instance is created.
36
37 Note that the definition of dBOv is quite vague in most places - is it peak since wave,
38 peak square wave, etc.? This code is based on the well defined wording in RFC3389:
39
40 "For example, in the case of a u-law system, the reference would be a square wave with
41 values +/-8031, and this square wave represents 0dBov. This translates into 6.18dBm0".
42
43 \section power_meter_page_sec_2 How does it work?
44 */
45
46 /*!
47 Power meter descriptor. This defines the working state for a
48 single instance of a power measurement device.
49 */
50 typedef struct
51 {
52 /*! The shift factor, which controls the damping of the power meter. */
53 int shift;
54
55 /*! The current power reading. */
56 int32_t reading;
57 } power_meter_t;
58
59 typedef struct
60 {
61 power_meter_t short_term;
62 power_meter_t medium_term;
63 int signal_present;
64 int32_t surge;
65 int32_t sag;
66 int32_t min;
67 } power_surge_detector_state_t;
68
69 #if defined(__cplusplus)
70 extern "C"
71 {
72 #endif
73
74 /*! Initialise a power meter context.
75 \brief Initialise a power meter context.
76 \param s The power meter context.
77 \param shift The shift to be used by the IIR filter.
78 \return The power meter context. */
79 SPAN_DECLARE(power_meter_t *) power_meter_init(power_meter_t *s, int shift);
80
81 SPAN_DECLARE(int) power_meter_release(power_meter_t *s);
82
83 SPAN_DECLARE(int) power_meter_free(power_meter_t *s);
84
85 /*! Change the damping factor of a power meter context.
86 \brief Change the damping factor of a power meter context.
87 \param s The power meter context.
88 \param shift The new shift to be used by the IIR filter.
89 \return The power meter context. */
90 SPAN_DECLARE(power_meter_t *) power_meter_damping(power_meter_t *s, int shift);
91
92 /*! Update a power meter.
93 \brief Update a power meter.
94 \param s The power meter context.
95 \param amp The amplitude of the new audio sample.
96 \return The current power meter reading. */
97 SPAN_DECLARE(int32_t) power_meter_update(power_meter_t *s, int16_t amp);
98
99 /*! Get the current power meter reading.
100 \brief Get the current power meter reading.
101 \param s The power meter context.
102 \return The current power meter reading. */
103 SPAN_DECLARE(int32_t) power_meter_current(power_meter_t *s);
104
105 /*! Get the current power meter reading, in dBm0.
106 \brief Get the current power meter reading, in dBm0.
107 \param s The power meter context.
108 \return The current power meter reading, in dBm0. */
109 SPAN_DECLARE(float) power_meter_current_dbm0(power_meter_t *s);
110
111 /*! Get the current power meter reading, in dBOv.
112 \brief Get the current power meter reading, in dBOv.
113 \param s The power meter context.
114 \return The current power meter reading, in dBOv. */
115 SPAN_DECLARE(float) power_meter_current_dbov(power_meter_t *s);
116
117 /*! Get the power meter reading which represents a specified power level in dBm0.
118 \brief Get the current power meter reading, in dBm0.
119 \param level A power level, in dB0m.
120 \return The equivalent power meter reading. */
121 SPAN_DECLARE(int32_t) power_meter_level_dbm0(float level);
122
123 /*! Get the power meter reading which represents a specified power level in dBOv.
124 \brief Get the current power meter reading, in dBOv.
125 \param level A power level, in dBOv.
126 \return The equivalent power meter reading. */
127 SPAN_DECLARE(int32_t) power_meter_level_dbov(float level);
128
129 SPAN_DECLARE(int32_t) power_surge_detector(power_surge_detector_state_t *s, int16_t amp);
130
131 /*! Get the current surge detector short term meter reading, in dBm0.
132 \brief Get the current surge detector meter reading, in dBm0.
133 \param s The power surge detector context.
134 \return The current power surge detector power reading, in dBm0. */
135 SPAN_DECLARE(float) power_surge_detector_current_dbm0(power_surge_detector_state_t *s);
136
137 /*! Get the current surge detector short term meter reading, in dBOv.
138 \brief Get the current surge detector meter reading, in dBOv.
139 \param s The power surge detector context.
140 \return The current power surge detector power reading, in dBOv. */
141 SPAN_DECLARE(float) power_surge_detector_current_dbov(power_surge_detector_state_t *s);
142
143 SPAN_DECLARE(power_surge_detector_state_t *) power_surge_detector_init(power_surge_detector_state_t *s, float min, float surge);
144
145 SPAN_DECLARE(int) power_surge_detector_release(power_surge_detector_state_t *s);
146
147 SPAN_DECLARE(int) power_surge_detector_free(power_surge_detector_state_t *s);
148
149 #if defined(__cplusplus)
150 }
151 #endif
152
153 #endif
154 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.