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 */
73 int near_filter_len;
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 */
77 int near_buf_ptr;
78 /*! The noise source for local analogue section of the line */
79 awgn_state_t near_noise;
80
81 /*! The bulk delay of the path, in samples */
82 int bulk_delay;
83 /*! A pointer to the current write position in the bulk delay store. */
84 int bulk_delay_ptr;
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 */
91 int far_filter_len;
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 */
95 int far_buf_ptr;
96 /*! The noise source for distant analogue section of the line */
97 awgn_state_t far_noise;
98
99 /*! The scaling factor for the local CPE hybrid echo */
100 float near_cpe_hybrid_echo;
101 /*! The scaling factor for the local CO hybrid echo */
102 float near_co_hybrid_echo;
103
104 /*! The scaling factor for the far CPE hybrid echo */
105 float far_cpe_hybrid_echo;
106 /*! The scaling factor for the far CO hybrid echo */
107 float far_co_hybrid_echo;
108 /*! DC offset impairment */
109 float dc_offset;
110
111 /*! Mains pickup impairment */
112 int mains_interference;
113 tone_gen_state_t mains_tone;
114} one_way_line_model_state_t;
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{
122 one_way_line_model_state_t line1;
123 one_way_line_model_state_t line2;
124 float fout1;
125 float fout2;
126} both_ways_line_model_state_t;
127
128#ifdef __cplusplus
129 extern "C"
130{
131#endif
132
133SPAN_DECLARE_DATA extern const float *line_models[];
134
135SPAN_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
142SPAN_DECLARE(void) both_ways_line_model_set_dc(both_ways_line_model_state_t *s, float dc1, float dc2);
143
144SPAN_DECLARE(void) both_ways_line_model_set_mains_pickup(both_ways_line_model_state_t *s, int f, float level1, float level2);
145
146SPAN_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
157SPAN_DECLARE(int) both_ways_line_model_release(both_ways_line_model_state_t *s);
158
159SPAN_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
164SPAN_DECLARE(void) one_way_line_model_set_dc(one_way_line_model_state_t *s, float dc);
165
166SPAN_DECLARE(void) one_way_line_model_set_mains_pickup(one_way_line_model_state_t *s, int f, float level);
167
168SPAN_DECLARE(one_way_line_model_state_t *) one_way_line_model_init(int model, float noise, int codec, int rbs_pattern);
169
170SPAN_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 ------------------------------------------------------------*/
awgn_state_t
struct awgn_state_s awgn_state_t
Definition awgn.h:72
noise
int16_t noise(noise_state_t *s)
Generate a sample of audio noise.
Definition noise.c:52
both_ways_line_model_state_t
Definition line_model.h:121
one_way_line_model_state_t
Definition line_model.h:67
one_way_line_model_state_t::near_noise
awgn_state_t near_noise
Definition line_model.h:79
one_way_line_model_state_t::mains_interference
int mains_interference
Definition line_model.h:112
one_way_line_model_state_t::near_filter_len
int near_filter_len
Definition line_model.h:73
one_way_line_model_state_t::near_cpe_hybrid_echo
float near_cpe_hybrid_echo
Definition line_model.h:100
one_way_line_model_state_t::near_buf_ptr
int near_buf_ptr
Definition line_model.h:77
one_way_line_model_state_t::far_buf
float far_buf[129]
Definition line_model.h:93
one_way_line_model_state_t::far_filter_len
int far_filter_len
Definition line_model.h:91
one_way_line_model_state_t::far_filter
const float * far_filter
Definition line_model.h:89
one_way_line_model_state_t::bulk_delay_buf
int16_t bulk_delay_buf[8000]
Definition line_model.h:86
one_way_line_model_state_t::near_buf
float near_buf[129]
Definition line_model.h:75
one_way_line_model_state_t::far_cpe_hybrid_echo
float far_cpe_hybrid_echo
Definition line_model.h:105
one_way_line_model_state_t::far_noise
awgn_state_t far_noise
Definition line_model.h:97
one_way_line_model_state_t::bulk_delay
int bulk_delay
Definition line_model.h:82
one_way_line_model_state_t::far_buf_ptr
int far_buf_ptr
Definition line_model.h:95
one_way_line_model_state_t::far_co_hybrid_echo
float far_co_hybrid_echo
Definition line_model.h:107
one_way_line_model_state_t::bulk_delay_ptr
int bulk_delay_ptr
Definition line_model.h:84
one_way_line_model_state_t::near_filter
const float * near_filter
Definition line_model.h:71
one_way_line_model_state_t::near_co_hybrid_echo
float near_co_hybrid_echo
Definition line_model.h:102
one_way_line_model_state_t::dc_offset
float dc_offset
Definition line_model.h:109
tone_gen_state_t
struct tone_gen_state_s tone_gen_state_t
Definition tone_generate.h:57