spandsp 0.0.6

dc_restore.h
Go to the documentation of this file.
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * dc_restore.h - General telephony routines to restore the zero D.C.
5 * level to audio which has a D.C. bias.
6 *
7 * Written by Steve Underwood <steveu@coppice.org>
8 *
9 * Copyright (C) 2001 Steve Underwood
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU Lesser General Public License version 2.1,
15 * as published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27/*! \file */
28
29#if !defined(_SPANDSP_DC_RESTORE_H_)
30#define _SPANDSP_DC_RESTORE_H_
31
32/*! \page dc_restore_page Removing DC bias from a signal
33
34\section dc_restore_page_sec_1 What does it do?
35
36 Telecoms signals often contain considerable DC, but DC upsets a lot of signal
37 processing functions. Placing a zero DC restorer at the front of the processing
38 chain can often simplify the downstream processing.
39
40\section dc_restore_page_sec_2 How does it work?
41
42 The DC restorer uses a leaky integrator to provide a long-ish term estimate of
43 the DC bias in the signal. A 32 bit estimate is used for the 16 bit audio, so
44 the noise introduced by the estimation can be keep in the lower bits, and the 16
45 bit DC value, which is subtracted from the signal, is fairly clean. The
46 following code fragment shows the algorithm used. dc_bias is a 32 bit integer,
47 while the sample and the resulting clean_sample are 16 bit integers.
48
49 dc_bias += ((((int32_t) sample << 15) - dc_bias) >> 14);
50 clean_sample = sample - (dc_bias >> 15);
51*/
52
53/*!
54 Zero DC restoration descriptor. This defines the working state for a single
55 instance of DC content filter.
56*/
57 typedef struct
58{
59 int32_t state;
60} dc_restore_state_t;
61
62#if defined(__cplusplus)
63 extern "C"
64{
65#endif
66
67 static __inline__ void dc_restore_init(dc_restore_state_t *dc)
68{
69 dc->state = 0;
70}
71/*- End of function --------------------------------------------------------*/
72
73 static __inline__ int16_t dc_restore(dc_restore_state_t *dc, int16_t sample)
74{
75 dc->state += ((((int32_t) sample << 15) - dc->state) >> 14);
76 return (int16_t) (sample - (dc->state >> 15));
77}
78/*- End of function --------------------------------------------------------*/
79
80 static __inline__ int16_t dc_restore_estimate(dc_restore_state_t *dc)
81{
82 return (int16_t) (dc->state >> 15);
83}
84/*- End of function --------------------------------------------------------*/
85
86#if defined(__cplusplus)
87}
88#endif
89
90#endif
91/*- End of file ------------------------------------------------------------*/
dc_restore_state_t
Definition dc_restore.h:58