00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * tone_generate.h - General telephony tone generation. 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2001 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 Lesser General Public License version 2.1, 00014 * as 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 Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License 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_generate.h,v 1.34 2008/09/11 15:13:42 steveu Exp $ 00026 */ 00027 00028 /*! \file */ 00029 00030 #if !defined(_SPANDSP_TONE_GENERATE_H_) 00031 #define _SPANDSP_TONE_GENERATE_H_ 00032 00033 /*! \page tone_generation_page Tone generation 00034 \section tone_generation_page_sec_1 What does it do? 00035 The tone generation module provides for the generation of cadenced tones, 00036 suitable for a wide range of telephony applications. 00037 00038 \section tone_generation_page_sec_2 How does it work? 00039 Oscillators are a problem. They oscillate due to instability, and yet we need 00040 them to behave in a stable manner. A look around the web will reveal many papers 00041 on this subject. Many describe rather complex solutions to the problem. However, 00042 we are only concerned with telephony applications. It is possible to generate 00043 the tones we need with a very simple efficient scheme. It is also practical to 00044 use an exhaustive test to prove the oscillator is stable under all the 00045 conditions in which we will use it. 00046 */ 00047 00048 typedef struct 00049 { 00050 int32_t phase_rate; 00051 #if defined(SPANDSP_USE_FIXED_POINT) 00052 int16_t gain; 00053 #else 00054 float gain; 00055 #endif 00056 } tone_gen_tone_descriptor_t; 00057 00058 /*! 00059 Cadenced dual tone generator descriptor. 00060 */ 00061 typedef struct 00062 { 00063 tone_gen_tone_descriptor_t tone[4]; 00064 int duration[4]; 00065 int repeat; 00066 } tone_gen_descriptor_t; 00067 00068 /*! 00069 Cadenced dual tone generator state descriptor. This defines the state of 00070 a single working instance of a generator. 00071 */ 00072 typedef struct 00073 { 00074 tone_gen_tone_descriptor_t tone[4]; 00075 00076 uint32_t phase[4]; 00077 int duration[4]; 00078 int repeat; 00079 00080 int current_section; 00081 int current_position; 00082 } tone_gen_state_t; 00083 00084 #if defined(__cplusplus) 00085 extern "C" 00086 { 00087 #endif 00088 00089 /*! Create a tone generator descriptor 00090 \brief Create a tone generator descriptor 00091 \param s The descriptor 00092 \param f1 The first frequency, in Hz 00093 \param l1 The level of the first frequency, in dBm0 00094 \param f2 0 for no second frequency, a positive number for the second frequency, 00095 in Hz, or a negative number for an AM modulation frequency, in Hz 00096 \param l2 The level of the second frequency, in dBm0, or the percentage modulation depth 00097 for an AM modulated tone. 00098 \param d1 x 00099 \param d2 x 00100 \param d3 x 00101 \param d4 x 00102 \param repeat x */ 00103 void make_tone_gen_descriptor(tone_gen_descriptor_t *s, 00104 int f1, 00105 int l1, 00106 int f2, 00107 int l2, 00108 int d1, 00109 int d2, 00110 int d3, 00111 int d4, 00112 int repeat); 00113 00114 tone_gen_state_t *tone_gen_init(tone_gen_state_t *s, tone_gen_descriptor_t *t); 00115 00116 int tone_gen(tone_gen_state_t *s, int16_t amp[], int max_samples); 00117 00118 #if defined(__cplusplus) 00119 } 00120 #endif 00121 00122 #endif 00123 /*- End of file ------------------------------------------------------------*/