1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * silence_gen.c - A silence generator, for inserting timed silences.
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2006 Steve Underwood
9  *
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 2.1,
14  * as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  * $Id: silence_gen.h,v 1.11 2008/07/16 17:54:23 steveu Exp $
26  */
27 
28 #if !defined(_SPANDSP_SILENCE_GEN_H_)
29 #define _SPANDSP_SILENCE_GEN_H_
30 
31 typedef struct
32 {
33     /*! \brief The callback function used to report status changes. */
34     modem_tx_status_func_t status_handler;
35     /*! \brief A user specified opaque pointer passed to the status function. */
36     void *status_user_data;
37 
38     int remaining_samples;
39     int total_samples;
40 } silence_gen_state_t;
41 
42 #if defined(__cplusplus)
43 extern "C"
44 {
45 #endif
46 
47 /*! Generate a block of silent audio samples.
48     \brief Generate a block of silent audio samples.
49     \param s The silence generator context.
50     \param amp The audio sample buffer.
51     \param max_len The number of samples to be generated.
52     \return The number of samples actually generated. This will be zero when
53             there is nothing to send.
54 */
55 int silence_gen(silence_gen_state_t *s, int16_t *amp, int max_len);
56 
57 /*! Set a silence generator context to output continuous silence.
58     \brief Set a silence generator context to output continuous silence.
59     \param s The silence generator context.
60 */
61 void silence_gen_always(silence_gen_state_t *s);
62 
63 /*! Set a silence generator context to output a specified period of silence.
64     \brief Set a silence generator context to output a specified period of silence.
65     \param s The silence generator context.
66     \param silent_samples The number of samples to be generated.
67 */
68 void silence_gen_set(silence_gen_state_t *s, int silent_samples);
69 
70 /*! Alter the period of a silence generator context by a specified amount.
71     \brief Alter the period of a silence generator context by a specified amount.
72     \param s The silence generator context.
73     \param silent_samples The number of samples to change the setting by. A positive number
74                           increases the duration. A negative number reduces it. The duration
75                           is prevented from going negative.
76 */
77 void silence_gen_alter(silence_gen_state_t *s, int silent_samples);
78 
79 /*! Find how long a silence generator context has to run.
80     \brief Find how long a silence generator context has to run.
81     \param s The silence generator context.
82     \return The number of samples remaining.
83 */
84 int silence_gen_remainder(silence_gen_state_t *s);
85 
86 /*! Find the total silence generated to date by a silence generator context.
87     \brief Find the total silence generated to date.
88     \param s The silence generator context.
89     \return The number of samples generated.
90 */
91 int silence_gen_generated(silence_gen_state_t *s);
92 
93 /*! Change the status reporting function associated with a silence generator context.
94     \brief Change the status reporting function associated with a silence generator context.
95     \param s The silence generator context.
96     \param handler The callback routine used to report status changes.
97     \param user_data An opaque pointer. */
98 void silence_gen_status_handler(silence_gen_state_t *s, modem_tx_status_func_t handler, void *user_data);
99 
100 /*! Initialise a timed silence generator context.
101     \brief Initialise a timed silence generator context.
102     \param s The silence generator context.
103     \param silent_samples The initial number of samples to set the silence to.
104     \return A pointer to the silence generator context.
105 */
106 silence_gen_state_t *silence_gen_init(silence_gen_state_t *s, int silent_samples);
107 
108 #if defined(__cplusplus)
109 }
110 #endif
111 
112 #endif
113 /*- End of file ------------------------------------------------------------*/
114