spandsp
0.0.6
|
00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * line_model.h - Model a telephone line. 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2004 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 00026 /*! \file */ 00027 00028 /*! \page line_model_page Telephone line model 00029 \section line_model_page_sec_1 What does it do? 00030 The telephone line modelling module provides simple modelling of one way and two 00031 way telephone lines. 00032 00033 The path being modelled is: 00034 00035 - terminal 00036 - | < hybrid echo (2-way models) 00037 - | 00038 - | < noise and filtering 00039 - | 00040 - | < hybrid echo (2-way models) 00041 - CO 00042 - | 00043 - | < A-law distortion + bulk delay 00044 - | 00045 - CO 00046 - | < hybrid echo (2-way models) 00047 - | 00048 - | < noise and filtering 00049 - | 00050 - | < hybrid echo (2-way models) 00051 - terminal 00052 */ 00053 00054 #if !defined(_SPANDSP_LINE_MODEL_H_) 00055 #define _SPANDSP_LINE_MODEL_H_ 00056 00057 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES 00058 #include <spandsp.h> 00059 00060 #define LINE_FILTER_SIZE 129 00061 00062 /*! 00063 One way line model descriptor. This holds the complete state of 00064 a line model with transmission in only one direction. 00065 */ 00066 typedef struct 00067 { 00068 codec_munge_state_t *munge; 00069 00070 /*! The coefficients for the near end analogue section simulation filter */ 00071 const float *near_filter; 00072 /*! The number of coefficients for the near end analogue section simulation filter */ 00073 int near_filter_len; 00074 /*! Last transmitted samples (ring buffer, used by the line filter) */ 00075 float near_buf[LINE_FILTER_SIZE]; 00076 /*! Pointer of the last transmitted sample in buf */ 00077 int near_buf_ptr; 00078 /*! The noise source for local analogue section of the line */ 00079 awgn_state_t near_noise; 00080 00081 /*! The bulk delay of the path, in samples */ 00082 int bulk_delay; 00083 /*! A pointer to the current write position in the bulk delay store. */ 00084 int bulk_delay_ptr; 00085 /*! The data store for simulating the bulk delay */ 00086 int16_t bulk_delay_buf[8000]; 00087 00088 /*! The coefficients for the far end analogue section simulation filter */ 00089 const float *far_filter; 00090 /*! The number of coefficients for the far end analogue section simulation filter */ 00091 int far_filter_len; 00092 /*! Last transmitted samples (ring buffer, used by the line filter) */ 00093 float far_buf[LINE_FILTER_SIZE]; 00094 /*! Pointer of the last transmitted sample in buf */ 00095 int far_buf_ptr; 00096 /*! The noise source for distant analogue section of the line */ 00097 awgn_state_t far_noise; 00098 00099 /*! The scaling factor for the local CPE hybrid echo */ 00100 float near_cpe_hybrid_echo; 00101 /*! The scaling factor for the local CO hybrid echo */ 00102 float near_co_hybrid_echo; 00103 00104 /*! The scaling factor for the far CPE hybrid echo */ 00105 float far_cpe_hybrid_echo; 00106 /*! The scaling factor for the far CO hybrid echo */ 00107 float far_co_hybrid_echo; 00108 /*! DC offset impairment */ 00109 float dc_offset; 00110 00111 /*! Mains pickup impairment */ 00112 int mains_interference; 00113 tone_gen_state_t mains_tone; 00114 } one_way_line_model_state_t; 00115 00116 /*! 00117 Two way line model descriptor. This holds the complete state of 00118 a line model with transmission in both directions. 00119 */ 00120 typedef struct 00121 { 00122 one_way_line_model_state_t line1; 00123 one_way_line_model_state_t line2; 00124 float fout1; 00125 float fout2; 00126 } both_ways_line_model_state_t; 00127 00128 #ifdef __cplusplus 00129 extern "C" 00130 { 00131 #endif 00132 00133 SPAN_DECLARE_DATA extern const float *line_models[]; 00134 00135 SPAN_DECLARE(void) both_ways_line_model(both_ways_line_model_state_t *s, 00136 int16_t output1[], 00137 const int16_t input1[], 00138 int16_t output2[], 00139 const int16_t input2[], 00140 int samples); 00141 00142 SPAN_DECLARE(void) both_ways_line_model_set_dc(both_ways_line_model_state_t *s, float dc1, float dc2); 00143 00144 SPAN_DECLARE(void) both_ways_line_model_set_mains_pickup(both_ways_line_model_state_t *s, int f, float level1, float level2); 00145 00146 SPAN_DECLARE(both_ways_line_model_state_t *) both_ways_line_model_init(int model1, 00147 float noise1, 00148 float echo_level_cpe1, 00149 float echo_level_co1, 00150 int model2, 00151 float noise2, 00152 float echo_level_cpe2, 00153 float echo_level_co2, 00154 int codec, 00155 int rbs_pattern); 00156 00157 SPAN_DECLARE(int) both_ways_line_model_release(both_ways_line_model_state_t *s); 00158 00159 SPAN_DECLARE(void) one_way_line_model(one_way_line_model_state_t *s, 00160 int16_t output[], 00161 const int16_t input[], 00162 int samples); 00163 00164 SPAN_DECLARE(void) one_way_line_model_set_dc(one_way_line_model_state_t *s, float dc); 00165 00166 SPAN_DECLARE(void) one_way_line_model_set_mains_pickup(one_way_line_model_state_t *s, int f, float level); 00167 00168 SPAN_DECLARE(one_way_line_model_state_t *) one_way_line_model_init(int model, float noise, int codec, int rbs_pattern); 00169 00170 SPAN_DECLARE(int) one_way_line_model_release(one_way_line_model_state_t *s); 00171 00172 #ifdef __cplusplus 00173 } 00174 #endif 00175 00176 #endif 00177 /*- End of file ------------------------------------------------------------*/