tone_detect.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * tone_detect.h - General telephony tone detection.
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2001, 2005 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 General Public License version 2, as
00014  * 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 General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  *
00025  * $Id: tone_detect.h,v 1.31 2007/04/08 08:16:18 steveu Exp $
00026  */
00027 
00028 #if !defined(_SPANDSP_TONE_DETECT_H_)
00029 #define _SPANDSP_TONE_DETECT_H_
00030 
00031 /*!
00032     Floating point Goertzel filter descriptor.
00033 */
00034 typedef struct
00035 {
00036     float fac;
00037     int samples;
00038 } goertzel_descriptor_t;
00039 
00040 /*!
00041     Floating point Goertzel filter state descriptor.
00042 */
00043 typedef struct
00044 {
00045     float v2;
00046     float v3;
00047     float fac;
00048     int samples;
00049     int current_sample;
00050 } goertzel_state_t;
00051 
00052 #if defined(__cplusplus)
00053 extern "C"
00054 {
00055 #endif
00056 
00057 /*! \brief Create a descriptor for use with either a Goertzel transform */
00058 void make_goertzel_descriptor(goertzel_descriptor_t *t,
00059                               float freq,
00060                               int samples);
00061 
00062 /*! \brief Initialise the state of a Goertzel transform.
00063     \param s The Goertzel context. If NULL, a context is allocated with malloc.
00064     \param t The Goertzel descriptor.
00065     \return A pointer to the Goertzel state. */
00066 goertzel_state_t *goertzel_init(goertzel_state_t *s,
00067                                 goertzel_descriptor_t *t);
00068 
00069 /*! \brief Reset the state of a Goertzel transform.
00070     \param s The Goertzel context.
00071     \param t The Goertzel descriptor.
00072     \return A pointer to the Goertzel state. */
00073 void goertzel_reset(goertzel_state_t *s);
00074 
00075 /*! \brief Update the state of a Goertzel transform.
00076     \param s The Goertzel context
00077     \param amp The samples to be transformed
00078     \param samples The number of samples
00079     \return The number of samples unprocessed */
00080 int goertzel_update(goertzel_state_t *s,
00081                     const int16_t amp[],
00082                     int samples);
00083 
00084 /*! \brief Evaluate the final result of a Goertzel transform.
00085     \param s The Goertzel context
00086     \return The result of the transform. */
00087 float goertzel_result(goertzel_state_t *s);
00088 
00089 /*! \brief Update the state of a Goertzel transform.
00090     \param s The Goertzel context
00091     \param amp The sample to be transformed. */
00092 static __inline__ void goertzel_sample(goertzel_state_t *s, int16_t amp)
00093 {
00094     float v1;
00095 
00096     v1 = s->v2;
00097     s->v2 = s->v3;
00098     s->v3 = s->fac*s->v2 - v1 + amp;
00099     s->current_sample++;
00100 }
00101 /*- End of function --------------------------------------------------------*/
00102 
00103 #if defined(__cplusplus)
00104 }
00105 #endif
00106 
00107 #endif
00108 /*- End of file ------------------------------------------------------------*/

Generated on Tue Jul 24 11:29:28 2007 for libspandsp by  doxygen 1.5.2