--- asterisk-11.0.1/apps/app_jack.c 2012-03-24 04:03:20.000000000 +0100 +++ asterisk-11.0.1-widebandjack/apps/app_jack.c 2012-11-18 17:06:03.053879363 +0100 @@ -5,6 +5,9 @@ * * Russell Bryant * + * Variable Bandwidth Modification by + * Mathis Schmieder + * * See http://www.asterisk.org for more information about * the Asterisk project. Please do not directly contact * any of the maintainers of this project for assistance; @@ -73,7 +76,9 @@ " n - Do not automatically start the JACK server if it is not already\n" \ " running.\n" \ " c() - By default, Asterisk will use the channel name for the jack client\n" \ -" name. Use this option to specify a custom client name.\n" +" name. Use this option to specify a custom client name.\n" \ +" r() - By default, the audiohook will be narrow band. Specify a\n" \ +" sample rate in Hz to change this.\n" /*** DOCUMENTATION @@ -103,6 +108,11 @@ Use this option to specify a custom client name. + @@ -115,6 +125,8 @@ ***/ static const char jack_app[] = "JACK"; +static double sample_rate = 8000.00; +static enum ast_format_id channel_format = AST_FORMAT_SLINEAR; struct jack_data { AST_DECLARE_STRING_FIELDS( @@ -201,10 +213,8 @@ jack_srate = jack_get_sample_rate(jack_data->client); - /* XXX Hard coded 8 kHz */ - - to_srate = input ? 8000.0 : jack_srate; - from_srate = input ? jack_srate : 8000.0; + to_srate = input ? sample_rate : jack_srate; + from_srate = input ? jack_srate : sample_rate; resample_factor = input ? &jack_data->input_resample_factor : &jack_data->output_resample_factor; @@ -610,7 +620,7 @@ .datalen = sizeof(buf), .samples = ARRAY_LEN(buf), }; - ast_format_set(&f.subclass.format, AST_FORMAT_SLINEAR, 0); + ast_format_set(&f.subclass.format, channel_format, 0); for (;;) { size_t res, read_len; @@ -653,6 +663,7 @@ OPT_OUTPUT_PORT = (1 << 2), OPT_NOSTART_SERVER = (1 << 3), OPT_CLIENT_NAME = (1 << 4), + OPT_SAMPLE_RATE = (1 << 5), }; enum { @@ -660,6 +671,7 @@ OPT_ARG_INPUT_PORT, OPT_ARG_OUTPUT_PORT, OPT_ARG_CLIENT_NAME, + OPT_ARG_SAMPLE_RATE, /* Must be the last element */ OPT_ARG_ARRAY_SIZE, @@ -671,6 +683,7 @@ AST_APP_OPTION_ARG('o', OPT_OUTPUT_PORT, OPT_ARG_OUTPUT_PORT), AST_APP_OPTION('n', OPT_NOSTART_SERVER), AST_APP_OPTION_ARG('c', OPT_CLIENT_NAME, OPT_ARG_CLIENT_NAME), + AST_APP_OPTION_ARG('r', OPT_SAMPLE_RATE, OPT_ARG_SAMPLE_RATE), END_OPTIONS ); static struct jack_data *jack_data_alloc(void) @@ -733,6 +746,17 @@ } } + if (ast_test_flag(&options, OPT_SAMPLE_RATE)) { + if (!ast_strlen_zero(option_args[OPT_ARG_SAMPLE_RATE])) { + sample_rate = atof(option_args[OPT_ARG_SAMPLE_RATE]); + channel_format = ast_format_slin_by_rate(sample_rate); + } + else { + ast_log(LOG_ERROR, "A sample rate must be provided with the r() option\n"); + return -1; + } + } + jack_data->no_start_server = ast_test_flag(&options, OPT_NOSTART_SERVER) ? 1 : 0; return 0; @@ -755,12 +779,12 @@ return -1; } - if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR)) { + if (ast_set_read_format_by_id(chan, channel_format)) { destroy_jack_data(jack_data); return -1; } - if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR)) { + if (ast_set_write_format_by_id(chan, channel_format)) { destroy_jack_data(jack_data); return -1; } @@ -824,8 +848,9 @@ if (frame->frametype != AST_FRAME_VOICE) return 0; - if (frame->subclass.format.id != AST_FORMAT_SLINEAR) { - ast_log(LOG_WARNING, "Expected frame in SLINEAR for the audiohook, but got format %s\n", + /* TODO get name of wanted format */ + if (frame->subclass.format.id != channel_format) { + ast_log(LOG_WARNING, "Audiohook format mismatch. Got unexpected format %s\n", ast_getformatname(&frame->subclass.format)); return 0; }