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 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: silence_gen.h,v 1.7 2007/04/08 08:16:18 steveu Exp $ 00026 */ 00027 00028 #if !defined(_SPANDSP_SILENCE_GEN_H_) 00029 #define _SPANDSP_SILENCE_GEN_H_ 00030 00031 typedef struct 00032 { 00033 int remaining_samples; 00034 int total_samples; 00035 } silence_gen_state_t; 00036 00037 #if defined(__cplusplus) 00038 extern "C" 00039 { 00040 #endif 00041 00042 /*! Generate a block of silent audio samples. 00043 \brief Generate a block of silent audio samples. 00044 \param s The silence generator context. 00045 \param amp The audio sample buffer. 00046 \param max_len The number of samples to be generated. 00047 \return The number of samples actually generated. This will be zero when 00048 there is nothing to send. 00049 */ 00050 int silence_gen(silence_gen_state_t *s, int16_t *amp, int max_len); 00051 00052 /*! Set a silence generator context to output continuous silence. 00053 \brief Set a silence generator context to output continuous silence. 00054 \param s The silence generator context. 00055 */ 00056 void silence_gen_always(silence_gen_state_t *s); 00057 00058 /*! Set a silence generator context to output a specified period of silence. 00059 \brief Set a silence generator context to output a specified period of silence. 00060 \param s The silence generator context. 00061 \param silent_samples The number of samples to be generated. 00062 */ 00063 void silence_gen_set(silence_gen_state_t *s, int silent_samples); 00064 00065 /*! Alter the period of a silence generator context by a specified amount. 00066 \brief Alter the period of a silence generator context by a specified amount. 00067 \param s The silence generator context. 00068 \param silent_samples The number of samples to change the setting by. A positive number 00069 increases the duration. A negative number reduces it. The duration 00070 is prevented from going negative. 00071 */ 00072 void silence_gen_alter(silence_gen_state_t *s, int silent_samples); 00073 00074 /*! Find how long a silence generator context has to run. 00075 \brief Find how long a silence generator context has to run. 00076 \param s The silence generator context. 00077 \return The number of samples remaining. 00078 */ 00079 int silence_gen_remainder(silence_gen_state_t *s); 00080 00081 /*! Find the total silence generated to date by a silence generator context. 00082 \brief Find the total silence generated to date. 00083 \param s The silence generator context. 00084 \return The number of samples generated. 00085 */ 00086 int silence_gen_generated(silence_gen_state_t *s); 00087 00088 /*! Initialise a timed silence generator context. 00089 \brief Initialise a timed silence generator context. 00090 \param s The silence generator context. 00091 \param the initial number of samples to set the silence to. 00092 \return A pointer to the silence generator context. 00093 */ 00094 silence_gen_state_t *silence_gen_init(silence_gen_state_t *s, int silent_samples); 00095 00096 #if defined(__cplusplus) 00097 } 00098 #endif 00099 00100 #endif 00101 /*- End of file ------------------------------------------------------------*/