5
|
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 General Public License version 2, as
|
|
14 * 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 General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * 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.4 2006/10/24 13:45:28 steveu Exp $
|
|
26 */
|
|
27
|
|
28 #if !defined(_SILENCE_GEN_H_)
|
|
29 #define _SILENCE_GEN_H_
|
|
30
|
|
31 typedef struct
|
|
32 {
|
|
33 int remaining_samples;
|
|
34 int total_samples;
|
|
35 } silence_gen_state_t;
|
|
36
|
|
37 #ifdef __cplusplus
|
|
38 extern "C" {
|
|
39 #endif
|
|
40
|
|
41 /*! Generate a block of silent audio samples.
|
|
42 \brief Generate a block of silent audio samples.
|
|
43 \param s The silence generator context.
|
|
44 \param amp The audio sample buffer.
|
|
45 \param max_len The number of samples to be generated.
|
|
46 \return The number of samples actually generated. This will be zero when
|
|
47 there is nothing to send.
|
|
48 */
|
|
49 int silence_gen(silence_gen_state_t *s, int16_t *amp, int max_len);
|
|
50
|
|
51 /*! Set a silence generator context to output continuous silence.
|
|
52 \brief Set a silence generator context to output continuous silence.
|
|
53 \param s The silence generator context.
|
|
54 */
|
|
55 void silence_gen_always(silence_gen_state_t *s);
|
|
56
|
|
57 /*! Set a silence generator context to output a specified period of silence.
|
|
58 \brief Set a silence generator context to output a specified period of silence.
|
|
59 \param s The silence generator context.
|
|
60 \param silent_samples The number of samples to be generated.
|
|
61 */
|
|
62 void silence_gen_set(silence_gen_state_t *s, int silent_samples);
|
|
63
|
|
64 /*! Alter the period of a silence generator context by a specified amount.
|
|
65 \brief Alter the period of a silence generator context by a specified amount.
|
|
66 \param s The silence generator context.
|
|
67 \param silent_samples The number of samples to change the setting by. A positive number
|
|
68 increases the duration. A negative number reduces it. The duration
|
|
69 is prevented from going negative.
|
|
70 */
|
|
71 void silence_gen_alter(silence_gen_state_t *s, int silent_samples);
|
|
72
|
|
73 /*! Find how long a silence generator context has to run.
|
|
74 \brief Find how long a silence generator context has to run.
|
|
75 \param s The silence generator context.
|
|
76 \return The number of samples remaining.
|
|
77 */
|
|
78 int silence_gen_remainder(silence_gen_state_t *s);
|
|
79
|
|
80 /*! Find the total silence generated to date by a silence generator context.
|
|
81 \brief Find the total silence generated to date.
|
|
82 \param s The silence generator context.
|
|
83 \return The number of samples generated.
|
|
84 */
|
|
85 int silence_gen_generated(silence_gen_state_t *s);
|
|
86
|
|
87 /*! Initialise a timed silence generator context.
|
|
88 \brief Initialise a timed silence generator context.
|
|
89 \param s The silence generator context.
|
|
90 \param the initial number of samples to set the silence to.
|
|
91 \return A pointer to the silence generator context.
|
|
92 */
|
|
93 silence_gen_state_t *silence_gen_init(silence_gen_state_t *s, int silent_samples);
|
|
94
|
|
95 #ifdef __cplusplus
|
|
96 }
|
|
97 #endif
|
|
98
|
|
99 #endif
|
|
100 /*- End of file ------------------------------------------------------------*/
|