Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/src/spandsp/dc_restore.h @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
| author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
|---|---|
| date | Fri, 25 Jun 2010 15:50:58 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
|---|---|
| 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 * $Id: dc_restore.h,v 1.24 2008/09/19 14:02:05 steveu Exp $ | |
| 27 */ | |
| 28 | |
| 29 /*! \file */ | |
| 30 | |
| 31 #if !defined(_SPANDSP_DC_RESTORE_H_) | |
| 32 #define _SPANDSP_DC_RESTORE_H_ | |
| 33 | |
| 34 /*! \page dc_restore_page Removing DC bias from a signal | |
| 35 | |
| 36 \section dc_restore_page_sec_1 What does it do? | |
| 37 | |
| 38 Telecoms signals often contain considerable DC, but DC upsets a lot of signal | |
| 39 processing functions. Placing a zero DC restorer at the front of the processing | |
| 40 chain can often simplify the downstream processing. | |
| 41 | |
| 42 \section dc_restore_page_sec_2 How does it work? | |
| 43 | |
| 44 The DC restorer uses a leaky integrator to provide a long-ish term estimate of | |
| 45 the DC bias in the signal. A 32 bit estimate is used for the 16 bit audio, so | |
| 46 the noise introduced by the estimation can be keep in the lower bits, and the 16 | |
| 47 bit DC value, which is subtracted from the signal, is fairly clean. The | |
| 48 following code fragment shows the algorithm used. dc_bias is a 32 bit integer, | |
| 49 while the sample and the resulting clean_sample are 16 bit integers. | |
| 50 | |
| 51 dc_bias += ((((int32_t) sample << 15) - dc_bias) >> 14); | |
| 52 clean_sample = sample - (dc_bias >> 15); | |
| 53 */ | |
| 54 | |
| 55 /*! | |
| 56 Zero DC restoration descriptor. This defines the working state for a single | |
| 57 instance of DC content filter. | |
| 58 */ | |
| 59 typedef struct | |
| 60 { | |
| 61 int32_t state; | |
| 62 } dc_restore_state_t; | |
| 63 | |
| 64 #if defined(__cplusplus) | |
| 65 extern "C" | |
| 66 { | |
| 67 #endif | |
| 68 | |
| 69 static __inline__ void dc_restore_init(dc_restore_state_t *dc) | |
| 70 { | |
| 71 dc->state = 0; | |
| 72 } | |
| 73 /*- End of function --------------------------------------------------------*/ | |
| 74 | |
| 75 static __inline__ int16_t dc_restore(dc_restore_state_t *dc, int16_t sample) | |
| 76 { | |
| 77 dc->state += ((((int32_t) sample << 15) - dc->state) >> 14); | |
| 78 return (int16_t) (sample - (dc->state >> 15)); | |
| 79 } | |
| 80 /*- End of function --------------------------------------------------------*/ | |
| 81 | |
| 82 static __inline__ int16_t dc_restore_estimate(dc_restore_state_t *dc) | |
| 83 { | |
| 84 return (int16_t) (dc->state >> 15); | |
| 85 } | |
| 86 /*- End of function --------------------------------------------------------*/ | |
| 87 | |
| 88 #if defined(__cplusplus) | |
| 89 } | |
| 90 #endif | |
| 91 | |
| 92 #endif | |
| 93 /*- End of file ------------------------------------------------------------*/ |
