00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * silence_gen.c - A silence generator, for inserting timed silences. 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2006 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: silence_gen.h,v 1.12 2008/07/26 04:53:00 steveu Exp $ 00026 */ 00027 00028 #if !defined(_SPANDSP_SILENCE_GEN_H_) 00029 #define _SPANDSP_SILENCE_GEN_H_ 00030 00031 typedef struct 00032 { 00033 /*! \brief The callback function used to report status changes. */ 00034 modem_tx_status_func_t status_handler; 00035 /*! \brief A user specified opaque pointer passed to the status function. */ 00036 void *status_user_data; 00037 00038 int remaining_samples; 00039 int total_samples; 00040 } silence_gen_state_t; 00041 00042 #if defined(__cplusplus) 00043 extern "C" 00044 { 00045 #endif 00046 00047 /*! Generate a block of silent audio samples. 00048 \brief Generate a block of silent audio samples. 00049 \param s The silence generator context. 00050 \param amp The audio sample buffer. 00051 \param max_len The number of samples to be generated. 00052 \return The number of samples actually generated. This will be zero when 00053 there is nothing to send. 00054 */ 00055 int silence_gen(silence_gen_state_t *s, int16_t *amp, int max_len); 00056 00057 /*! Set a silence generator context to output continuous silence. 00058 \brief Set a silence generator context to output continuous silence. 00059 \param s The silence generator context. 00060 */ 00061 void silence_gen_always(silence_gen_state_t *s); 00062 00063 /*! Set a silence generator context to output a specified period of silence. 00064 \brief Set a silence generator context to output a specified period of silence. 00065 \param s The silence generator context. 00066 \param silent_samples The number of samples to be generated. 00067 */ 00068 void silence_gen_set(silence_gen_state_t *s, int silent_samples); 00069 00070 /*! Alter the period of a silence generator context by a specified amount. 00071 \brief Alter the period of a silence generator context by a specified amount. 00072 \param s The silence generator context. 00073 \param silent_samples The number of samples to change the setting by. A positive number 00074 increases the duration. A negative number reduces it. The duration 00075 is prevented from going negative. 00076 */ 00077 void silence_gen_alter(silence_gen_state_t *s, int silent_samples); 00078 00079 /*! Find how long a silence generator context has to run. 00080 \brief Find how long a silence generator context has to run. 00081 \param s The silence generator context. 00082 \return The number of samples remaining. 00083 */ 00084 int silence_gen_remainder(silence_gen_state_t *s); 00085 00086 /*! Find the total silence generated to date by a silence generator context. 00087 \brief Find the total silence generated to date. 00088 \param s The silence generator context. 00089 \return The number of samples generated. 00090 */ 00091 int silence_gen_generated(silence_gen_state_t *s); 00092 00093 /*! Change the status reporting function associated with a silence generator context. 00094 \brief Change the status reporting function associated with a silence generator context. 00095 \param s The silence generator context. 00096 \param handler The callback routine used to report status changes. 00097 \param user_data An opaque pointer. */ 00098 void silence_gen_status_handler(silence_gen_state_t *s, modem_tx_status_func_t handler, void *user_data); 00099 00100 /*! Initialise a timed silence generator context. 00101 \brief Initialise a timed silence generator context. 00102 \param s The silence generator context. 00103 \param silent_samples The initial number of samples to set the silence to. 00104 \return A pointer to the silence generator context. 00105 */ 00106 silence_gen_state_t *silence_gen_init(silence_gen_state_t *s, int silent_samples); 00107 00108 /* The following dummy routines, to absorb data, don't really have a proper home, 00109 so they have been put here. */ 00110 00111 /*! A dummy routine to use as a receive callback, when we aren't really 00112 trying to process what is received. It just absorbs and ignores the 00113 data. 00114 \brief Dummy receive callback. 00115 \param user_data The context. 00116 \param amp The signal.buffer 00117 \param len The length of the signal buffer 00118 \return 0. 00119 */ 00120 int span_dummy_rx(void *user_data, const int16_t amp[], int len); 00121 00122 /*! A dummy routine to use as a signal modifier callback, when we aren't 00123 really trying to process the signal. It just returns without affecting 00124 anything. 00125 \brief Dummy signal modifier callback. 00126 \param user_data The context. 00127 \param amp The signal.buffer 00128 \param len The length of the signal buffer 00129 \return 0. 00130 */ 00131 int span_dummy_mod(void *user_data, int16_t amp[], int len); 00132 00133 #if defined(__cplusplus) 00134 } 00135 #endif 00136 00137 #endif 00138 /*- End of file ------------------------------------------------------------*/