tone2wav.c File Reference

#include <switch.h>
#include <switch_version.h>

Include dependency graph for tone2wav.c:

Go to the source code of this file.

Defines

#define _XOPEN_SOURCE   600
#define fail()   r = 255; goto end

Functions

static int teletone_handler (teletone_generation_session_t *ts, teletone_tone_map_t *map)
int main (int argc, char *argv[])


Define Documentation

#define _XOPEN_SOURCE   600

Definition at line 37 of file tone2wav.c.

 
#define fail (  )     r = 255; goto end

Definition at line 73 of file tone2wav.c.

Referenced by main(), print_array(), print_object(), switch_core_perform_file_open(), and switch_ivr_activate_unicast().


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 76 of file tone2wav.c.

References teletone_generation_session::channels, teletone_generation_session::debug, teletone_generation_session::debug_stream, teletone_generation_session::duration, fail, switch_directories::mod_dir, teletone_generation_session::rate, SCF_MINIMAL, switch_core_destroy(), switch_core_file_close(), switch_core_file_open, switch_core_init(), SWITCH_FALSE, SWITCH_FILE_DATA_SHORT, SWITCH_FILE_FLAG_WRITE, SWITCH_GLOBAL_dirs, switch_loadable_module_init(), switch_loadable_module_load_module(), SWITCH_STATUS_SUCCESS, SWITCH_TRUE, teletone_destroy_session(), teletone_handler(), teletone_init_session(), teletone_run(), and teletone_generation_session::wait.

00077 {
00078         teletone_generation_session_t ts;
00079         int file_flags = SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT;
00080         int r = 0;
00081         int rate = 8000;
00082         char *file = NULL, *script = NULL;
00083         switch_file_handle_t fh = { 0 };
00084         const char *err = NULL;
00085         switch_bool_t verbose = SWITCH_FALSE;
00086         int i = 0, c = 1, help = 0;
00087 
00088         for(i = 1; i < argc; i++) {
00089                 if (!strstr(argv[i], "-")) break;
00090                 
00091                 if (!strcmp(argv[i], "-v")) {
00092                         verbose = SWITCH_TRUE;
00093                 }
00094 
00095                 if (!strcmp(argv[i], "-s")) {
00096                         c = 2;
00097                 }
00098 
00099                 if (!strcmp(argv[i], "-h")) {
00100                         help = 1;
00101                 }
00102 
00103                 if (!strncmp(argv[i], "-R", 2)) {
00104                         char *p = argv[i] + 2;
00105 
00106                         if (p) {
00107                                 int tmp = atoi(p);
00108                                 if (tmp > 0) {
00109                                         rate = tmp;
00110                                 }
00111                         }
00112                 }
00113         }
00114 
00115         if (argc - i != 2 || help) {
00116                 char *app = NULL;
00117 
00118                 if (!help) printf("Invalid input!\n");
00119 
00120                 if ((app = strrchr(argv[0], '/'))) {
00121                         app++;
00122                 } else {
00123                         app = argv[0];
00124                 }
00125 
00126 
00127                 printf("USAGE: %s [options] <file> <tones>\n", app);
00128                 printf("================================================================================\n");
00129                 printf("Options:\n"
00130                            "-s\t\tStereo\n"
00131                            "-h\t\tHelp\n"
00132                            "-R<rate>\tSet Rate (8000,16000,32000,48000) etc.\n"
00133                            "-v\t\tVerbose Logging\n"
00134                            "<file>\t\tAny file supported by libsndfile\n"
00135                            "<tones>\t\tA valid teletone script http://wiki.freeswitch.org/wiki/TGML"
00136                            "\n\n\n"
00137                            );
00138                 return 255;
00139         }
00140         
00141         file = argv[i];
00142         script = argv[i+1];
00143 
00144         if (switch_core_init(SCF_MINIMAL, verbose, &err) != SWITCH_STATUS_SUCCESS) {
00145                 printf("Cannot init core [%s]\n", err);
00146                 fail();
00147         }
00148 
00149         switch_loadable_module_init(SWITCH_FALSE);
00150 
00151         if (switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) "mod_sndfile", SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) {
00152                 printf("Cannot init mod_sndfile [%s]\n", err);
00153                 fail();
00154         }
00155         
00156         if (switch_core_file_open(&fh, file, c, rate, file_flags, NULL) != SWITCH_STATUS_SUCCESS) {
00157                 printf("Cannot open file %s\n", file);
00158                 fail();
00159         }
00160         
00161         teletone_init_session(&ts, 0, teletone_handler, &fh);
00162         ts.rate = rate;
00163         ts.channels = c;
00164         ts.duration = 250 * (rate / 1000 / c);
00165         ts.wait = 50 * (rate / 1000 / c);
00166         if (verbose) {
00167                 ts.debug = 10;
00168                 ts.debug_stream = stdout;
00169         }
00170         teletone_run(&ts, script);
00171         teletone_destroy_session(&ts);
00172         switch_core_file_close(&fh);
00173         
00174         printf("File: %s generated...\n\nPlease support:\nFreeSWITCH http://www.freeswitch.org\nClueCon http://www.cluecon.com\n", file);
00175 
00176  end:
00177 
00178         switch_core_destroy();
00179 
00180         return r;
00181 
00182 }

static int teletone_handler ( teletone_generation_session_t ts,
teletone_tone_map_t map 
) [static]

Definition at line 57 of file tone2wav.c.

References teletone_generation_session::buffer, switch_core_file_write(), SWITCH_STATUS_SUCCESS, teletone_mux_tones(), and teletone_generation_session::user_data.

00058 {
00059         switch_file_handle_t *fh = (switch_file_handle_t *) ts->user_data;
00060         int wrote;
00061         switch_size_t len;
00062 
00063         wrote = teletone_mux_tones(ts, map);
00064 
00065         len = wrote;
00066         if (switch_core_file_write(fh, ts->buffer, &len) != SWITCH_STATUS_SUCCESS) {
00067                 return -1;
00068         }
00069 
00070         return 0;
00071 }


Generated on Sun May 20 04:00:16 2012 for FreeSWITCH API Documentation by  doxygen 1.4.7