spandsp  0.0.6
line_model.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * line_model.h - Model a telephone line.
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2004 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 /*! \file */
27 
28 /*! \page line_model_page Telephone line model
29 \section line_model_page_sec_1 What does it do?
30 The telephone line modelling module provides simple modelling of one way and two
31 way telephone lines.
32 
33 The path being modelled is:
34 
35  - terminal
36  - | < hybrid echo (2-way models)
37  - |
38  - | < noise and filtering
39  - |
40  - | < hybrid echo (2-way models)
41  - CO
42  - |
43  - | < A-law distortion + bulk delay
44  - |
45  - CO
46  - | < hybrid echo (2-way models)
47  - |
48  - | < noise and filtering
49  - |
50  - | < hybrid echo (2-way models)
51  - terminal
52 */
53 
54 #if !defined(_SPANDSP_LINE_MODEL_H_)
55 #define _SPANDSP_LINE_MODEL_H_
56 
57 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
58 #include <spandsp.h>
59 
60 #define LINE_FILTER_SIZE 129
61 
62 /*!
63  One way line model descriptor. This holds the complete state of
64  a line model with transmission in only one direction.
65 */
66 typedef struct
67 {
68  codec_munge_state_t *munge;
69 
70  /*! The coefficients for the near end analogue section simulation filter */
71  const float *near_filter;
72  /*! The number of coefficients for the near end analogue section simulation filter */
74  /*! Last transmitted samples (ring buffer, used by the line filter) */
75  float near_buf[LINE_FILTER_SIZE];
76  /*! Pointer of the last transmitted sample in buf */
78  /*! The noise source for local analogue section of the line */
80 
81  /*! The bulk delay of the path, in samples */
83  /*! A pointer to the current write position in the bulk delay store. */
85  /*! The data store for simulating the bulk delay */
86  int16_t bulk_delay_buf[8000];
87 
88  /*! The coefficients for the far end analogue section simulation filter */
89  const float *far_filter;
90  /*! The number of coefficients for the far end analogue section simulation filter */
92  /*! Last transmitted samples (ring buffer, used by the line filter) */
93  float far_buf[LINE_FILTER_SIZE];
94  /*! Pointer of the last transmitted sample in buf */
96  /*! The noise source for distant analogue section of the line */
98 
99  /*! The scaling factor for the local CPE hybrid echo */
101  /*! The scaling factor for the local CO hybrid echo */
103 
104  /*! The scaling factor for the far CPE hybrid echo */
106  /*! The scaling factor for the far CO hybrid echo */
108  /*! DC offset impairment */
109  float dc_offset;
110 
111  /*! Mains pickup impairment */
113  tone_gen_state_t mains_tone;
115 
116 /*!
117  Two way line model descriptor. This holds the complete state of
118  a line model with transmission in both directions.
119 */
120 typedef struct
121 {
124  float fout1;
125  float fout2;
127 
128 #ifdef __cplusplus
129 extern "C"
130 {
131 #endif
132 
133 SPAN_DECLARE_DATA extern const float *line_models[];
134 
135 SPAN_DECLARE(void) both_ways_line_model(both_ways_line_model_state_t *s,
136  int16_t output1[],
137  const int16_t input1[],
138  int16_t output2[],
139  const int16_t input2[],
140  int samples);
141 
142 SPAN_DECLARE(void) both_ways_line_model_set_dc(both_ways_line_model_state_t *s, float dc1, float dc2);
143 
144 SPAN_DECLARE(void) both_ways_line_model_set_mains_pickup(both_ways_line_model_state_t *s, int f, float level1, float level2);
145 
146 SPAN_DECLARE(both_ways_line_model_state_t *) both_ways_line_model_init(int model1,
147  float noise1,
148  float echo_level_cpe1,
149  float echo_level_co1,
150  int model2,
151  float noise2,
152  float echo_level_cpe2,
153  float echo_level_co2,
154  int codec,
155  int rbs_pattern);
156 
157 SPAN_DECLARE(int) both_ways_line_model_release(both_ways_line_model_state_t *s);
158 
159 SPAN_DECLARE(void) one_way_line_model(one_way_line_model_state_t *s,
160  int16_t output[],
161  const int16_t input[],
162  int samples);
163 
164 SPAN_DECLARE(void) one_way_line_model_set_dc(one_way_line_model_state_t *s, float dc);
165 
166 SPAN_DECLARE(void) one_way_line_model_set_mains_pickup(one_way_line_model_state_t *s, int f, float level);
167 
168 SPAN_DECLARE(one_way_line_model_state_t *) one_way_line_model_init(int model, float noise, int codec, int rbs_pattern);
169 
170 SPAN_DECLARE(int) one_way_line_model_release(one_way_line_model_state_t *s);
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif
177 /*- End of file ------------------------------------------------------------*/
int mains_interference
Definition: line_model.h:112
int far_buf_ptr
Definition: line_model.h:95
Definition: private/tone_generate.h:53
Definition: line_model.h:66
int bulk_delay_ptr
Definition: line_model.h:84
Definition: private/awgn.h:32
float far_cpe_hybrid_echo
Definition: line_model.h:105
int16_t noise(noise_state_t *s)
Generate a sample of audio noise.
Definition: noise.c:52
Definition: line_model.h:120
awgn_state_t far_noise
Definition: line_model.h:97
const float * far_filter
Definition: line_model.h:89
float near_cpe_hybrid_echo
Definition: line_model.h:100
float near_co_hybrid_echo
Definition: line_model.h:102
float far_co_hybrid_echo
Definition: line_model.h:107
awgn_state_t near_noise
Definition: line_model.h:79
int near_filter_len
Definition: line_model.h:73
Definition: test_utils.c:53
int bulk_delay
Definition: line_model.h:82
int far_filter_len
Definition: line_model.h:91
int near_buf_ptr
Definition: line_model.h:77
float dc_offset
Definition: line_model.h:109
const float * near_filter
Definition: line_model.h:71