Mercurial > hg > audiostuff
comparison spandsp-0.0.3/spandsp-0.0.3/src/spandsp/tone_detect.h @ 5:f762bf195c4b
import spandsp-0.0.3
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 16:00:21 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:26cd8f1ef0b1 | 5:f762bf195c4b |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * tone_detect.h - General telephony tone detection, and specific | |
5 * detection of Bell MF, and MFC/R2. | |
6 * | |
7 * Written by Steve Underwood <steveu@coppice.org> | |
8 * | |
9 * Copyright (C) 2001, 2005 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 General Public License version 2, as | |
15 * 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 General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with this program; if not, write to the Free Software | |
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 * | |
26 * $Id: tone_detect.h,v 1.27 2006/10/24 13:45:28 steveu Exp $ | |
27 */ | |
28 | |
29 #if !defined(_TONE_DETECT_H_) | |
30 #define _TONE_DETECT_H_ | |
31 | |
32 /*! | |
33 Floating point Goertzel filter descriptor. | |
34 */ | |
35 typedef struct | |
36 { | |
37 float fac; | |
38 int samples; | |
39 } goertzel_descriptor_t; | |
40 | |
41 /*! | |
42 Floating point Goertzel filter state descriptor. | |
43 */ | |
44 typedef struct | |
45 { | |
46 float v2; | |
47 float v3; | |
48 float fac; | |
49 int samples; | |
50 int current_sample; | |
51 } goertzel_state_t; | |
52 | |
53 #ifdef __cplusplus | |
54 extern "C" { | |
55 #endif | |
56 | |
57 /*! \brief Create a descriptor for use with either a Goertzel transform */ | |
58 void make_goertzel_descriptor(goertzel_descriptor_t *t, | |
59 float freq, | |
60 int samples); | |
61 | |
62 /*! \brief Initialise the state of a Goertzel transform. | |
63 \param s The Goertzel context. If NULL, a context is allocated with malloc. | |
64 \param t The Goertzel descriptor. | |
65 \return A pointer to the Goertzel state. */ | |
66 goertzel_state_t *goertzel_init(goertzel_state_t *s, | |
67 goertzel_descriptor_t *t); | |
68 | |
69 /*! \brief Reset the state of a Goertzel transform. | |
70 \param s The Goertzel context. | |
71 \param t The Goertzel descriptor. | |
72 \return A pointer to the Goertzel state. */ | |
73 void goertzel_reset(goertzel_state_t *s); | |
74 | |
75 /*! \brief Update the state of a Goertzel transform. | |
76 \param s The Goertzel context | |
77 \param amp The samples to be transformed | |
78 \param samples The number of samples | |
79 \return The number of samples unprocessed */ | |
80 int goertzel_update(goertzel_state_t *s, | |
81 const int16_t amp[], | |
82 int samples); | |
83 | |
84 /*! \brief Evaluate the final result of a Goertzel transform. | |
85 \param s The Goertzel context | |
86 \return The result of the transform. */ | |
87 float goertzel_result(goertzel_state_t *s); | |
88 | |
89 /*! \brief Update the state of a Goertzel transform. | |
90 \param s The Goertzel context | |
91 \param amp The sample to be transformed. */ | |
92 static __inline__ void goertzel_sample(goertzel_state_t *s, int16_t amp) | |
93 { | |
94 float v1; | |
95 | |
96 v1 = s->v2; | |
97 s->v2 = s->v3; | |
98 s->v3 = s->fac*s->v2 - v1 + amp; | |
99 s->current_sample++; | |
100 } | |
101 /*- End of function --------------------------------------------------------*/ | |
102 | |
103 #ifdef __cplusplus | |
104 } | |
105 #endif | |
106 | |
107 #endif | |
108 /*- End of file ------------------------------------------------------------*/ |