00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * power_meter.h 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2003 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 2.1, 00014 * as published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 * 00025 * $Id: power_meter.h,v 1.19 2009/05/19 14:15:09 steveu Exp $ 00026 */ 00027 00028 #if !defined(_POWER_METER_H_) 00029 #define _POWER_METER_H_ 00030 00031 /*! \page power_meter_page Power metering 00032 00033 \section power_meter_page_sec_1 What does it do? 00034 The power metering module implements a simple IIR type running power meter. The damping 00035 factor of the IIR is selectable when the meter instance is created. 00036 00037 Note that the definition of dBOv is quite vague in most places - is it peak since wave, 00038 peak square wave, etc.? This code is based on the well defined wording in RFC3389: 00039 00040 "For example, in the case of a u-law system, the reference would be a square wave with 00041 values +/-8031, and this square wave represents 0dBov. This translates into 6.18dBm0". 00042 00043 \section power_meter_page_sec_2 How does it work? 00044 */ 00045 00046 /*! 00047 Power meter descriptor. This defines the working state for a 00048 single instance of a power measurement device. 00049 */ 00050 typedef struct 00051 { 00052 /*! The shift factor, which controls the damping of the power meter. */ 00053 int shift; 00054 00055 /*! The current power reading. */ 00056 int32_t reading; 00057 } power_meter_t; 00058 00059 typedef struct 00060 { 00061 power_meter_t short_term; 00062 power_meter_t medium_term; 00063 int signal_present; 00064 int32_t surge; 00065 int32_t sag; 00066 int32_t min; 00067 } power_surge_detector_state_t; 00068 00069 #if defined(__cplusplus) 00070 extern "C" 00071 { 00072 #endif 00073 00074 /*! Initialise a power meter context. 00075 \brief Initialise a power meter context. 00076 \param s The power meter context. 00077 \param shift The shift to be used by the IIR filter. 00078 \return The power meter context. */ 00079 SPAN_DECLARE(power_meter_t *) power_meter_init(power_meter_t *s, int shift); 00080 00081 SPAN_DECLARE(int) power_meter_release(power_meter_t *s); 00082 00083 SPAN_DECLARE(int) power_meter_free(power_meter_t *s); 00084 00085 /*! Change the damping factor of a power meter context. 00086 \brief Change the damping factor of a power meter context. 00087 \param s The power meter context. 00088 \param shift The new shift to be used by the IIR filter. 00089 \return The power meter context. */ 00090 SPAN_DECLARE(power_meter_t *) power_meter_damping(power_meter_t *s, int shift); 00091 00092 /*! Update a power meter. 00093 \brief Update a power meter. 00094 \param s The power meter context. 00095 \param amp The amplitude of the new audio sample. 00096 \return The current power meter reading. */ 00097 SPAN_DECLARE(int32_t) power_meter_update(power_meter_t *s, int16_t amp); 00098 00099 /*! Get the current power meter reading. 00100 \brief Get the current power meter reading. 00101 \param s The power meter context. 00102 \return The current power meter reading. */ 00103 SPAN_DECLARE(int32_t) power_meter_current(power_meter_t *s); 00104 00105 /*! Get the current power meter reading, in dBm0. 00106 \brief Get the current power meter reading, in dBm0. 00107 \param s The power meter context. 00108 \return The current power meter reading, in dBm0. */ 00109 SPAN_DECLARE(float) power_meter_current_dbm0(power_meter_t *s); 00110 00111 /*! Get the current power meter reading, in dBOv. 00112 \brief Get the current power meter reading, in dBOv. 00113 \param s The power meter context. 00114 \return The current power meter reading, in dBOv. */ 00115 SPAN_DECLARE(float) power_meter_current_dbov(power_meter_t *s); 00116 00117 /*! Get the power meter reading which represents a specified power level in dBm0. 00118 \brief Get the current power meter reading, in dBm0. 00119 \param level A power level, in dB0m. 00120 \return The equivalent power meter reading. */ 00121 SPAN_DECLARE(int32_t) power_meter_level_dbm0(float level); 00122 00123 /*! Get the power meter reading which represents a specified power level in dBOv. 00124 \brief Get the current power meter reading, in dBOv. 00125 \param level A power level, in dBOv. 00126 \return The equivalent power meter reading. */ 00127 SPAN_DECLARE(int32_t) power_meter_level_dbov(float level); 00128 00129 SPAN_DECLARE(int32_t) power_surge_detector(power_surge_detector_state_t *s, int16_t amp); 00130 00131 /*! Get the current surge detector short term meter reading, in dBm0. 00132 \brief Get the current surge detector meter reading, in dBm0. 00133 \param s The power surge detector context. 00134 \return The current power surge detector power reading, in dBm0. */ 00135 SPAN_DECLARE(float) power_surge_detector_current_dbm0(power_surge_detector_state_t *s); 00136 00137 /*! Get the current surge detector short term meter reading, in dBOv. 00138 \brief Get the current surge detector meter reading, in dBOv. 00139 \param s The power surge detector context. 00140 \return The current power surge detector power reading, in dBOv. */ 00141 SPAN_DECLARE(float) power_surge_detector_current_dbov(power_surge_detector_state_t *s); 00142 00143 SPAN_DECLARE(power_surge_detector_state_t *) power_surge_detector_init(power_surge_detector_state_t *s, float min, float surge); 00144 00145 SPAN_DECLARE(int) power_surge_detector_release(power_surge_detector_state_t *s); 00146 00147 SPAN_DECLARE(int) power_surge_detector_free(power_surge_detector_state_t *s); 00148 00149 #if defined(__cplusplus) 00150 } 00151 #endif 00152 00153 #endif 00154 /*- End of file ------------------------------------------------------------*/