1
/* $Id: tonegen.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJMEDIA_TONEGEN_PORT_H__
21
#define __PJMEDIA_TONEGEN_PORT_H__
25
* @brief Tone (sine, MF, DTMF) generator media port.
27
#include <pjmedia/port.h>
31
* @defgroup PJMEDIA_MF_DTMF_TONE_GENERATOR Multi-frequency tone generator
32
* @ingroup PJMEDIA_PORT
33
* @brief Multi-frequency tone generator
36
* This page describes tone generator media port. A tone generator can be
37
* used to generate a single frequency sine wave or dual frequency tones
40
* The tone generator media port provides two functions to generate tones.
41
* The function #pjmedia_tonegen_play() can be used to generate arbitrary
42
* single or dual frequency tone, and #pjmedia_tonegen_play_digits() is
43
* used to play digits such as DTMF. Each tone specified in the playback
44
* function has individual on and off signal duration that must be
45
* specified by application.
47
* In order to play digits such as DTMF, the tone generator is equipped
48
* with digit map, which contain information about the frequencies of
49
* the digits. The default digit map is DTMF (0-9,a-d,*,#), but application
50
* may specifiy different digit map to the tone generator by calling
51
* #pjmedia_tonegen_set_digit_map() function.
58
* This structure describes individual MF digits to be played
59
* with #pjmedia_tonegen_play().
61
typedef struct pjmedia_tone_desc
63
short freq1; /**< First frequency. */
64
short freq2; /**< Optional second frequency. */
65
short on_msec; /**< Playback ON duration, in miliseconds. */
66
short off_msec; /**< Playback OFF duration, ini miliseconds. */
67
short volume; /**< Volume (1-32767), or 0 for default, which
68
PJMEDIA_TONEGEN_VOLUME will be used. */
69
short flags; /**< Currently internal flags, must be 0 */
75
* This structure describes individual MF digits to be played
76
* with #pjmedia_tonegen_play_digits().
78
typedef struct pjmedia_tone_digit
80
char digit; /**< The ASCI identification for the digit. */
81
short on_msec; /**< Playback ON duration, in miliseconds. */
82
short off_msec; /**< Playback OFF duration, ini miliseconds. */
83
short volume; /**< Volume (1-32767), or 0 for default, which
84
PJMEDIA_TONEGEN_VOLUME will be used. */
89
* This structure describes the digit map which is used by the tone generator
90
* to produce tones from an ASCII digits.
91
* Digit map used by a particular tone generator can be retrieved/set with
92
* #pjmedia_tonegen_get_digit_map() and #pjmedia_tonegen_set_digit_map().
94
typedef struct pjmedia_tone_digit_map
96
unsigned count; /**< Number of digits in the map. */
99
char digit; /**< The ASCI identification for the digit. */
100
short freq1; /**< First frequency. */
101
short freq2; /**< Optional second frequency. */
102
} digits[16]; /**< Array of digits in the digit map. */
103
} pjmedia_tone_digit_map;
107
* Tone generator options.
112
* Play the tones in loop, restarting playing the first tone after
113
* the last tone has been played.
115
PJMEDIA_TONEGEN_LOOP = 1,
118
* Disable mutex protection to the tone generator.
120
PJMEDIA_TONEGEN_NO_LOCK = 2
125
* Create an instance of tone generator with the specified parameters.
126
* When the tone generator is first created, it will be loaded with the
129
* @param pool Pool to allocate memory for the port structure.
130
* @param clock_rate Sampling rate.
131
* @param channel_count Number of channels. Currently only mono and stereo
133
* @param samples_per_frame Number of samples per frame.
134
* @param bits_per_sample Number of bits per sample. This version of PJMEDIA
135
* only supports 16bit per sample.
136
* @param options Option flags. Application may specify
137
* PJMEDIA_TONEGEN_LOOP to play the tone in a loop.
138
* @param p_port Pointer to receive the port instance.
140
* @return PJ_SUCCESS on success, or the appropriate
143
PJ_DECL(pj_status_t) pjmedia_tonegen_create(pj_pool_t *pool,
145
unsigned channel_count,
146
unsigned samples_per_frame,
147
unsigned bits_per_sample,
149
pjmedia_port **p_port);
153
* Create an instance of tone generator with the specified parameters.
154
* When the tone generator is first created, it will be loaded with the
157
* @param pool Pool to allocate memory for the port structure.
158
* @param name Optional name for the tone generator.
159
* @param clock_rate Sampling rate.
160
* @param channel_count Number of channels. Currently only mono and stereo
162
* @param samples_per_frame Number of samples per frame.
163
* @param bits_per_sample Number of bits per sample. This version of PJMEDIA
164
* only supports 16bit per sample.
165
* @param options Option flags. Application may specify
166
* PJMEDIA_TONEGEN_LOOP to play the tone in a loop.
167
* @param p_port Pointer to receive the port instance.
169
* @return PJ_SUCCESS on success, or the appropriate
172
PJ_DECL(pj_status_t) pjmedia_tonegen_create2(pj_pool_t *pool,
173
const pj_str_t *name,
175
unsigned channel_count,
176
unsigned samples_per_frame,
177
unsigned bits_per_sample,
179
pjmedia_port **p_port);
183
* Check if the tone generator is still busy producing some tones.
185
* @param tonegen The tone generator instance.
187
* @return Non-zero if busy.
189
PJ_DECL(pj_bool_t) pjmedia_tonegen_is_busy(pjmedia_port *tonegen);
193
* Instruct the tone generator to stop current processing.
195
* @param tonegen The tone generator instance.
197
* @return PJ_SUCCESS on success.
199
PJ_DECL(pj_status_t) pjmedia_tonegen_stop(pjmedia_port *tonegen);
203
* Rewind the playback. This will start the playback to the first
204
* tone in the playback list.
206
* @param tonegen The tone generator instance.
208
* @return PJ_SUCCESS on success.
210
PJ_DECL(pj_status_t) pjmedia_tonegen_rewind(pjmedia_port *tonegen);
214
* Instruct the tone generator to play single or dual frequency tones
215
* with the specified duration. The new tones will be appended to currently
216
* playing tones, unless #pjmedia_tonegen_stop() is called before calling
217
* this function. The playback will begin as soon as the first get_frame()
218
* is called to the generator.
220
* @param tonegen The tone generator instance.
221
* @param count The number of tones in the array.
222
* @param tones Array of tones to be played.
223
* @param options Option flags. Application may specify
224
* PJMEDIA_TONEGEN_LOOP to play the tone in a loop.
226
* @return PJ_SUCCESS on success, or PJ_ETOOMANY if
227
* there are too many digits in the queue.
229
PJ_DECL(pj_status_t) pjmedia_tonegen_play(pjmedia_port *tonegen,
231
const pjmedia_tone_desc tones[],
235
* Instruct the tone generator to play multiple MF digits with each of
236
* the digits having individual ON/OFF duration. Each of the digit in the
237
* digit array must have the corresponding descriptor in the digit map.
238
* The new tones will be appended to currently playing tones, unless
239
* #pjmedia_tonegen_stop() is called before calling this function.
240
* The playback will begin as soon as the first get_frame() is called
243
* @param tonegen The tone generator instance.
244
* @param count Number of digits in the array.
245
* @param digits Array of MF digits.
246
* @param options Option flags. Application may specify
247
* PJMEDIA_TONEGEN_LOOP to play the tone in a loop.
249
* @return PJ_SUCCESS on success, or PJ_ETOOMANY if
250
* there are too many digits in the queue, or
251
* PJMEDIA_RTP_EINDTMF if invalid digit is
254
PJ_DECL(pj_status_t) pjmedia_tonegen_play_digits(pjmedia_port *tonegen,
256
const pjmedia_tone_digit digits[],
261
* Get the digit-map currently used by this tone generator.
263
* @param tonegen The tone generator instance.
264
* @param m On output, it will be filled with the pointer to
265
* the digitmap currently used by the tone generator.
267
* @return PJ_SUCCESS on success.
269
PJ_DECL(pj_status_t) pjmedia_tonegen_get_digit_map(pjmedia_port *tonegen,
270
const pjmedia_tone_digit_map **m);
274
* Set digit map to be used by the tone generator.
276
* @param tonegen The tone generator instance.
277
* @param m Digitmap to be used by the tone generator.
279
* @return PJ_SUCCESS on success.
281
PJ_DECL(pj_status_t) pjmedia_tonegen_set_digit_map(pjmedia_port *tonegen,
282
pjmedia_tone_digit_map *m);
292
#endif /* __PJMEDIA_TONEGEN_PORT_H__ */