spandsp  0.0.6
silence_gen.h
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 
26 #if !defined(_SPANDSP_SILENCE_GEN_H_)
27 #define _SPANDSP_SILENCE_GEN_H_
28 
30 
31 #if defined(__cplusplus)
32 extern "C"
33 {
34 #endif
35 
36 /*! Generate a block of silent audio samples.
37  \brief Generate a block of silent audio samples.
38  \param s The silence generator context.
39  \param amp The audio sample buffer.
40  \param max_len The number of samples to be generated.
41  \return The number of samples actually generated. This will be zero when
42  there is nothing to send.
43 */
44 SPAN_DECLARE_NONSTD(int) silence_gen(silence_gen_state_t *s, int16_t *amp, int max_len);
45 
46 /*! Set a silence generator context to output continuous silence.
47  \brief Set a silence generator context to output continuous silence.
48  \param s The silence generator context.
49 */
50 SPAN_DECLARE(void) silence_gen_always(silence_gen_state_t *s);
51 
52 /*! Set a silence generator context to output a specified period of silence.
53  \brief Set a silence generator context to output a specified period of silence.
54  \param s The silence generator context.
55  \param silent_samples The number of samples to be generated.
56 */
57 SPAN_DECLARE(void) silence_gen_set(silence_gen_state_t *s, int silent_samples);
58 
59 /*! Alter the period of a silence generator context by a specified amount.
60  \brief Alter the period of a silence generator context by a specified amount.
61  \param s The silence generator context.
62  \param silent_samples The number of samples to change the setting by. A positive number
63  increases the duration. A negative number reduces it. The duration
64  is prevented from going negative.
65 */
66 SPAN_DECLARE(void) silence_gen_alter(silence_gen_state_t *s, int silent_samples);
67 
68 /*! Find how long a silence generator context has to run.
69  \brief Find how long a silence generator context has to run.
70  \param s The silence generator context.
71  \return The number of samples remaining.
72 */
73 SPAN_DECLARE(int) silence_gen_remainder(silence_gen_state_t *s);
74 
75 /*! Find the total silence generated to date by a silence generator context.
76  \brief Find the total silence generated to date.
77  \param s The silence generator context.
78  \return The number of samples generated.
79 */
80 SPAN_DECLARE(int) silence_gen_generated(silence_gen_state_t *s);
81 
82 /*! Change the status reporting function associated with a silence generator context.
83  \brief Change the status reporting function associated with a silence generator context.
84  \param s The silence generator context.
85  \param handler The callback routine used to report status changes.
86  \param user_data An opaque pointer. */
87 SPAN_DECLARE(void) silence_gen_status_handler(silence_gen_state_t *s, modem_status_func_t handler, void *user_data);
88 
89 /*! Initialise a timed silence generator context.
90  \brief Initialise a timed silence generator context.
91  \param s The silence generator context.
92  \param silent_samples The initial number of samples to set the silence to.
93  \return A pointer to the silence generator context.
94 */
95 SPAN_DECLARE(silence_gen_state_t *) silence_gen_init(silence_gen_state_t *s, int silent_samples);
96 
97 SPAN_DECLARE(int) silence_gen_release(silence_gen_state_t *s);
98 
99 SPAN_DECLARE(int) silence_gen_free(silence_gen_state_t *s);
100 
101 /* The following dummy routines, to absorb data, don't really have a proper home,
102  so they have been put here. */
103 
104 /*! A dummy routine to use as a receive callback, when we aren't really
105  trying to process what is received. It just absorbs and ignores the
106  data.
107  \brief Dummy receive callback.
108  \param user_data The context.
109  \param amp The signal.buffer
110  \param len The length of the signal buffer
111  \return 0.
112 */
113 SPAN_DECLARE_NONSTD(int) span_dummy_rx(void *user_data, const int16_t amp[], int len);
114 
115 /*! A dummy routine to use as a signal modifier callback, when we aren't
116  really trying to process the signal. It just returns without affecting
117  anything.
118  \brief Dummy signal modifier callback.
119  \param user_data The context.
120  \param amp The signal.buffer
121  \param len The length of the signal buffer
122  \return 0.
123 */
124 SPAN_DECLARE(int) span_dummy_mod(void *user_data, int16_t amp[], int len);
125 
126 /*! A dummy routine to use as a receive fillin callback, when we aren't really
127  trying to process what is received. It just absorbs and ignores the
128  request.
129  \brief Dummy receive fillin callback.
130  \param user_data The context.
131  \param len The length of the signal buffer
132  \return 0.
133 */
134 SPAN_DECLARE_NONSTD(int) span_dummy_rx_fillin(void *user_data, int len);
135 
136 #if defined(__cplusplus)
137 }
138 #endif
139 
140 #endif
141 /*- End of file ------------------------------------------------------------*/
Definition: private/silence_gen.h:29
void silence_gen_alter(silence_gen_state_t *s, int silent_samples)
Alter the period of a silence generator context by a specified amount.
Definition: silence_gen.c:86
SPAN_DECLARE_NONSTD(int) async_tx_get_bit(void *user_data)
Get the next bit of a transmitted serial bit stream.
int silence_gen_remainder(silence_gen_state_t *s)
Find how long a silence generator context has to run.
Definition: silence_gen.c:99
int span_dummy_mod(void *user_data, int16_t amp[], int len)
Dummy signal modifier callback.
Definition: silence_gen.c:154
void silence_gen_always(silence_gen_state_t *s)
Set a silence generator context to output continuous silence.
Definition: silence_gen.c:73
void(* modem_status_func_t)(void *user_data, int status)
Definition: async.h:114
silence_gen_state_t * silence_gen_init(silence_gen_state_t *s, int silent_samples)
Initialise a timed silence generator context.
Definition: silence_gen.c:118
void silence_gen_status_handler(silence_gen_state_t *s, modem_status_func_t handler, void *user_data)
Change the status reporting function associated with a silence generator context. ...
Definition: silence_gen.c:111
int silence_gen_generated(silence_gen_state_t *s)
Find the total silence generated to date.
Definition: silence_gen.c:105
void silence_gen_set(silence_gen_state_t *s, int silent_samples)
Set a silence generator context to output a specified period of silence.
Definition: silence_gen.c:79