line_model.h

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

Generated on Tue Oct 7 20:25:46 2008 for spandsp by  doxygen 1.5.6