]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix teletone gen on multichannel
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 29 Mar 2019 21:54:19 +0000 (16:54 -0500)
committerAndrey Volk <andywolk@gmail.com>
Thu, 25 Jul 2019 19:31:08 +0000 (23:31 +0400)
libs/libteletone/src/libteletone_generate.c
src/switch_ivr_play_say.c

index 94ae14d2289f710d69a97539e22433c590220f25..7528620de0409f0f76b48d09e6fb7b8853b2844b 100644 (file)
@@ -206,7 +206,7 @@ static int ensure_buffer(teletone_generation_session_t *ts, int need)
 TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone_tone_map_t *map)
 {
        /*teletone_process_t period = (1.0 / ts->rate) / ts->channels;*/
-       int i, c;
+       int i;
        int freqlen = 0;
        teletone_dds_state_t tones[TELETONE_MAX_TONES+1];
        //int decay = 0;
@@ -215,6 +215,7 @@ TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone
        int32_t sample;
        int32_t dc = 0;
        float vol = ts->volume;
+
        ts->samples = 0;
        memset(tones, 0, sizeof(tones[0]) * TELETONE_MAX_TONES);
        duration = (ts->tmp_duration > -1) ? ts->tmp_duration : ts->duration;
@@ -225,13 +226,9 @@ TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone
                        teletone_dds_state_set_tone(&tones[freqlen], map->freqs[freqlen], ts->rate, 0);
                        teletone_dds_state_set_tx_level(&tones[freqlen], vol);
                }
-       
-               if (ts->channels > 1) {
-                       duration *= ts->channels;
-               }
 
                if (ts->dynamic) {
-                       if (ensure_buffer(ts, duration)) {
+                       if (ensure_buffer(ts, duration * ts->channels)) {
                                return -1;
                        }
                }
@@ -260,23 +257,17 @@ TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone
                                sample /= freqlen;
                        }
                        ts->buffer[ts->samples] = (teletone_audio_t)sample;
-                       
-                       for (c = 1; c < ts->channels; c++) {
-                               ts->buffer[ts->samples+1] = ts->buffer[ts->samples];
-                               ts->samples++;
-                       }
-                       
                }
        }
+
        if (ts->dynamic) {
-               if (ensure_buffer(ts, wait)) {
+               if (ensure_buffer(ts, wait * ts->channels)) {
                        return -1;
                }
        }
-       for (c = 0; c < ts->channels; c++) {
-               for (i = 0; i < wait && ts->samples < ts->datalen; i++) {
-                       ts->buffer[ts->samples++] = 0;
-               }
+
+       for (i = 0; i < wait && ts->samples < ts->datalen; i++) {
+               ts->buffer[ts->samples++] = 0;
        }
 
        if (ts->debug && ts->debug_stream) {
@@ -304,7 +295,7 @@ TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone
                                        ts->samples * 2);
                }
        }       
-       return ts->samples / ts->channels;
+       return ts->samples;
 }
 
 /* don't ask */
index 430357b3862286d5573ad29909b44e3a629493fe..c21903910b3af57b2a79b98ed3818664d101e46f 100644 (file)
@@ -1013,7 +1013,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *sessi
                                                           NULL,
                                                           read_impl.actual_samples_per_second,
                                                           read_impl.microseconds_per_packet / 1000,
-                                                          1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+                                                          read_impl.number_of_channels, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
                                                           NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
 
                return SWITCH_STATUS_FALSE;
@@ -1029,7 +1029,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *sessi
        switch_buffer_create_dynamic(&audio_buffer, 512, 1024, 0);
        teletone_init_session(&ts, 0, teletone_handler, audio_buffer);
        ts.rate = read_impl.actual_samples_per_second;
-       ts.channels = 1;
+       ts.channels = read_impl.number_of_channels;
        teletone_run(&ts, script);
 
        if (loops) {