[Freeswitch-svn] [commit] r11658 - in freeswitch/trunk/src: . include mod/applications/mod_dptools

FreeSWITCH SVN anthm at freeswitch.org
Thu Feb 5 11:53:13 PST 2009


Author: anthm
Date: Thu Feb  5 13:53:13 2009
New Revision: 11658

Log:
sound_test app

Modified:
   freeswitch/trunk/src/include/switch_ivr.h
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/switch_ivr.c

Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h	(original)
+++ freeswitch/trunk/src/include/switch_ivr.h	Thu Feb  5 13:53:13 2009
@@ -794,6 +794,7 @@
 	 SWITCH_DECLARE(switch_say_method_t) switch_ivr_get_say_method_by_name(const char *name);
 	 SWITCH_DECLARE(switch_say_type_t) switch_ivr_get_say_type_by_name(const char *name);
      SWITCH_DECLARE(switch_status_t) switch_ivr_set_user(switch_core_session_t *session, const char *data);
+     SWITCH_DECLARE(switch_status_t) switch_ivr_sound_test(switch_core_session_t *session);
 /** @} */
 
 	 SWITCH_END_EXTERN_C

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Thu Feb  5 13:53:13 2009
@@ -912,6 +912,11 @@
 	}
 }
 
+SWITCH_STANDARD_APP(sound_test_function)
+{
+	switch_ivr_sound_test(session);
+}
+
 SWITCH_STANDARD_APP(event_function)
 {
 	switch_event_t *event;
@@ -2581,6 +2586,7 @@
 	SWITCH_ADD_APP(app_interface, "log", "Logs to the logger", LOG_LONG_DESC, log_function, "<log_level> <log_string>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "info", "Display Call Info", "Display Call Info", info_function, "", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "event", "Fire an event", "Fire an event", event_function, "", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "sound_test", "Analyze Audio", "Analyze Audio", sound_test_function, "", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "export", "Export a channel variable across a bridge", EXPORT_LONG_DESC, export_function, "<varname>=<value>",
 				   SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "set", "Set a channel variable", SET_LONG_DESC, set_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Thu Feb  5 13:53:13 2009
@@ -38,6 +38,91 @@
 #include <switch_ivr.h>
 #include "stfu.h"
 
+SWITCH_DECLARE(switch_status_t) switch_ivr_sound_test(switch_core_session_t *session)
+{
+
+	switch_codec_implementation_t imp = {0};
+	switch_codec_t codec = { 0 };
+	int16_t peak = 0;
+	int16_t *data;
+	switch_frame_t *read_frame = NULL;
+	int i;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
+	int64_t global_total = 0, global_sum = 0, period_sum = 0;
+	int period_total = 0;
+	int period_avg = 0, global_avg = 0;
+	int avg = 0;
+	int period_len;
+	
+	switch_core_session_get_read_impl(session, &imp);
+	
+	period_len = imp.actual_samples_per_second / imp.samples_per_packet;
+
+	if (switch_core_codec_init(&codec,
+							   "L16",
+							   NULL,
+							   imp.samples_per_second,
+							   imp.microseconds_per_packet / 1000,
+							   imp.number_of_channels, 
+							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, 
+							   switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n", 
+						  imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
+		return SWITCH_STATUS_FALSE;
+	}
+	
+	while(switch_channel_ready(channel)) {
+		status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
+	
+		if (!SWITCH_READ_ACCEPTABLE(status)) {
+			break;
+		}
+
+		if (switch_test_flag(read_frame, SFF_CNG) || !read_frame->samples) {
+			continue;
+		}
+
+
+		data = (int16_t *) read_frame->data;
+		peak = 0;
+		avg = 0;
+		for (i = 0; i < read_frame->samples; i++) {
+			const int16_t s = abs(data[i]);
+			if (s > peak) {
+				peak = s;
+			}
+			avg += s;
+		}
+		
+		avg /= read_frame->samples;
+
+		period_sum += peak;
+		global_sum += peak;
+		
+		global_total++;
+		period_total++;
+		
+		period_avg = period_sum / period_total;
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, 
+						  "\npacket_avg=%d packet_peak=%d period_avg=%d global_avg=%d\n\n", avg, peak, period_avg, global_avg); 
+		
+		if (period_total >= period_len) {			
+			global_avg = global_sum / global_total;
+			period_total = 0;
+			period_sum = 0;
+		}
+
+	}
+	
+
+	switch_core_codec_destroy(&codec);
+
+	return SWITCH_STATUS_SUCCESS;
+
+}
+
 SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_bool_t sync, switch_input_args_t *args)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);



More information about the Freeswitch-svn mailing list