mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-14 01:49:05 +00:00
Ringback (sponsored by Front Logic)
This addition lets you set artifical ringback on a channel that is waiting for an originated call to be answered. the syntax is <action application="set" data="ringback=[data]"/> where data is either the full path to an audio file or a teletone generation script.. syntax of teletone scripts LEGEND: 0-9,a-d,*,# (standard dtmf tones) variables: c,r,d,v,>,<,+,w,l,L,% c (channels) - Sets the number of channels. r (rate) - Sets the sample rate. d (duration) - Sets the default tone duration. v (volume) - Sets the default volume. > (decrease vol) - factor to decrease volume by per frame (0 for even decrease across duration). < (increase vol) - factor to increase volume by per frame (0 for even increase across duration). + (step) - factor to step by used by < and >. w (wait) - default silence after each tone. l (loops) - number of times to repeat each tone in the script. L (LOOPS) - number of times to repeat the the whole script. % (manual tone) - a generic tone specified by a duration, a wait and a list of frequencies. standard tones can have custom duration per use with the () modifier 7(1000, 500) to generate DTMF 7 for 1 second then pause .5 seconds EXAMPLES UK Ring Tone [400+450 hz on for 400ms off for 200ms then 400+450 hz on for 400ms off for 2200ms] %(400,200,400,450);%(400,2200,400,450) US Ring Tone [440+480 hz on for 2000ms off for 4000ms] %(2000,4000,440,480) ATT BONG [volume level 4000, even decay, step by 2, # key for 60ms with no wait, volume level 2000, 350+440hz {us dialtone} for 940ms v=4000;>=0;+=2;#(60,0);v=2000;%(940,0,350,440) SIT Tone 913.8 hz for 274 ms with no wait, 1370.6 hz for 274 ms with no wait, 1776.7 hz for 380ms with no wait %(274,0,913.8);%(274,0,1370.6);%(380,0,1776.7) ATTN TONE (phone's off the hook!) 1400+2060+2450+2600 hz for 100ms with 100ms wait %(100,100,1400,2060,2450,2600) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3408 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -84,11 +84,14 @@ int teletone_init_session(teletone_generation_session_t *ts, int buflen, tone_ha
|
||||
ts->user_data = user_data;
|
||||
ts->volume = 1500;
|
||||
ts->decay_step = 0;
|
||||
if ((ts->buffer = calloc(buflen, sizeof(teletone_audio_t))) == 0) {
|
||||
return -1;
|
||||
if (buflen) {
|
||||
if ((ts->buffer = calloc(buflen, sizeof(teletone_audio_t))) == 0) {
|
||||
return -1;
|
||||
}
|
||||
ts->datalen = buflen;
|
||||
} else {
|
||||
ts->dynamic = 1024;
|
||||
}
|
||||
ts->datalen = buflen;
|
||||
|
||||
/* Add Standard DTMF Tones */
|
||||
teletone_set_tone(ts, '1', 697.0, 1209.0, 0.0);
|
||||
teletone_set_tone(ts, '2', 697.0, 1336.0, 0.0);
|
||||
@@ -120,8 +123,21 @@ int teletone_destroy_session(teletone_generation_session_t *ts)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Generate a specified number of samples containing the three specified
|
||||
* frequencies (in hertz) and dump to the file descriptor audio_fd. */
|
||||
static int ensure_buffer(teletone_generation_session_t *ts, int need)
|
||||
{
|
||||
need += ts->samples;
|
||||
need *= sizeof(teletone_audio_t);
|
||||
need *= ts->channels;
|
||||
|
||||
if (need > ts->datalen) {
|
||||
ts->datalen = need + ts->dynamic;
|
||||
if (!(ts->buffer = realloc(ts->buffer, ts->datalen))) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map)
|
||||
{
|
||||
@@ -159,6 +175,11 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m
|
||||
duration *= ts->channels;
|
||||
}
|
||||
|
||||
if (ts->dynamic) {
|
||||
if (ensure_buffer(ts, duration)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
for (ts->samples = 0; ts->samples < ts->datalen && ts->samples < duration; ts->samples++) {
|
||||
if (ts->decay_step && !(ts->samples % ts->decay_step) && ts->volume > 0 && ts->samples > decay) {
|
||||
ts->volume += ts->decay_direction;
|
||||
@@ -179,6 +200,11 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m
|
||||
|
||||
}
|
||||
}
|
||||
if (ts->dynamic) {
|
||||
if (ensure_buffer(ts, wait)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
for (c = 0; c < ts->channels; c++) {
|
||||
for (i = 0; i < wait && ts->samples < ts->datalen; i++) {
|
||||
ts->buffer[ts->samples++] = 0;
|
||||
@@ -211,19 +237,37 @@ int teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *m
|
||||
return ts->samples;
|
||||
}
|
||||
|
||||
/* don't ask */
|
||||
static char *my_strdup (const char *s)
|
||||
{
|
||||
size_t len = strlen (s) + 1;
|
||||
void *new = malloc (len);
|
||||
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (char *) memcpy (new, s, len);
|
||||
}
|
||||
|
||||
int teletone_run(teletone_generation_session_t *ts, char *cmd)
|
||||
{
|
||||
char *data, *cur, *end;
|
||||
char *data = NULL, *cur = NULL, *end = NULL;
|
||||
int var = 0, LOOPING = 0;
|
||||
|
||||
if (!cmd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
do {
|
||||
data = strdup(cmd);
|
||||
if (!(data = my_strdup(cmd))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cur = data;
|
||||
|
||||
|
||||
while (*cur) {
|
||||
var = 0;
|
||||
|
||||
if (*cur == ' ' || *cur == '\r' || *cur == '\n') {
|
||||
cur++;
|
||||
continue;
|
||||
|
Reference in New Issue
Block a user