[asterisk-commits] oej: branch oej/silence-detection-games-1.8 r411918 - /team/oej/silence-detec...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 8 08:02:03 CDT 2014


Author: oej
Date: Tue Apr  8 08:01:53 2014
New Revision: 411918

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=411918
Log:
Adding working detection.

Now I just wonder where my writes are gone?

Modified:
    team/oej/silence-detection-games-1.8/main/silencedetection.c

Modified: team/oej/silence-detection-games-1.8/main/silencedetection.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/silence-detection-games-1.8/main/silencedetection.c?view=diff&rev=411918&r1=411917&r2=411918
==============================================================================
--- team/oej/silence-detection-games-1.8/main/silencedetection.c (original)
+++ team/oej/silence-detection-games-1.8/main/silencedetection.c Tue Apr  8 08:01:53 2014
@@ -92,7 +92,10 @@
 	.destroy = destroy_callback
 };
 
-/*! \brief The callback from the audiohook subsystem. We basically get a frame to have fun with */
+/*! \brief The callback from the audiohook subsystem. We basically get a frame to have fun with 
+	Return TRUE to keep original packet
+	Return FALSE to use our packet
+*/
 static int silence_detection_callback(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
 {
 	struct ast_datastore *datastore = NULL;
@@ -102,7 +105,7 @@
 	/* If the audiohook is stopping it means the channel is shutting down.... but we let the datastore destroy take care of it */
 	if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE) {
 		ast_debug(7, "Audiohook giving up - STATUS_DONE \n");
-		return 0;
+		return 1;
 	}
 
 	ast_channel_lock(chan);
@@ -110,10 +113,15 @@
 	if (!(datastore = ast_channel_datastore_find(chan, &sildet_datastore, NULL))) {
 		ast_channel_unlock(chan);
 		ast_debug(2, "Can't find any datastore to use. Bad. \n");
-		return 0;
+		return 1;
 	}
 
 	sildet = datastore->data;
+	if (!sildet || !sildet->dsp) {
+		ast_channel_unlock(chan);
+		ast_debug(2, "Can't find any DSP to use. Bad. \n");
+		return 1;
+	}
 
 	/* If this is audio then allow them to increase/decrease the gains */
 	if (frame->frametype == AST_FRAME_VOICE) {
@@ -122,44 +130,47 @@
 		/* Based on direction of frame grab the gain, and confirm it is applicable */
 		if (direction == AST_AUDIOHOOK_DIRECTION_WRITE) {
 			ast_dsp_silence(sildet->dsp, frame, &dsptime);	/* Checking for silence */
-			if (option_debug && sildet->silencecounter == 0 && dsptime) {
-				ast_debug(8, " ++++ Silence started ++++ on chan %s\n", chan->name);
-			}
 			if (!dsptime) {
 				if (option_debug && sildet->silencecounter > 0) {
 					ast_debug(8, " ++++ Silence stopped ++++ on chan %s\n", chan->name);
 				}
-				sildet->silencecounter = 0;		/* No more silence */
-				sildet->detect = 0;		/* No more silence */
+				if (sildet->silencecounter > 0) {
+					sildet->silencecounter = 0;		/* No more silence */
+					sildet->detect = 0;		/* No more silence */
+				}
+				ast_debug(9, " ++++ We are not silent on write to %s (dsptime %d)\n", chan->name, dsptime);
 			} else {
+				if (option_debug && sildet->silencecounter == 0) {
+					ast_debug(9, "          ++++ Silence starts here %d ++++ on chan %s dsptime %d\n", sildet->silencecounter, chan->name, dsptime);
+				}
 				if (option_debug && sildet->silencecounter > 0) {
-					ast_debug(9, "          ++++ Silence continues %d ++++ on chan %s\n", sildet->silencecounter, chan->name);
-				}
-				if (sildet_detect == 1 && sildet->silencecounter > sildet->silenceframes) {
-					sildet->silencecounter++;
+					ast_debug(9, "          ++++ Silence continues %d ++++ on chan %s dsptime %d\n", sildet->silencecounter, chan->name, dsptime);
+				}
+				sildet->silencecounter++;
+				if (sildet->detect == 1 && sildet->silencecounter > sildet->silenceframes) {
 					ast_frame_clear(frame);		/* Should really be dropped. */
-					frame->frametype = AST_FRAME_DROP;
+					
+					//frame->frametype = AST_FRAME_DROP;
 					ast_channel_unlock(chan);
-					return 1;	/* Return TRUE since we manipulated the frame */
+					return 0;	/* Return TRUE since we manipulated the frame */
 				}
 			}
 			if (sildet->detect == 0 && sildet->silencecounter > sildet->silenceframes) {
-				ast_debug(8, "          ++++ Silence suppression should start now ++++ on chan %s\n", chan->name);
+				ast_debug(8, "++++ Silence suppression should start now ++++ on chan %s\n", chan->name);
 				sildet->detect = 1;
 				ast_frame_clear(frame);
 				frame->frametype = AST_FRAME_CNG;
-        			frame->subclass.integer = data[0] & 0x7f;
+        			frame->subclass.integer =  0x7f;
         			frame->samples = 0;
-        			rframe->delivery.tv_usec = fram.delivery.tv_sec = 0;
 				ast_channel_unlock(chan);
-				return 1;	/* Return TRUE since we manipulated the frame */
+				return 0;	/* Return TRUE since we manipulated the frame */
 			}
 			/* Do not touch the frame yet */
 		}
 	}
 	ast_channel_unlock(chan);
 
-	return 0;
+	return 1;
 }
 
 /*! \brief Initialize mute hook on channel, but don't activate it
@@ -188,10 +199,9 @@
 		ast_datastore_free(datastore);
 		return NULL;
 	}
-	ast_dsp_set_threshold(sildet->dsp, ast_dsp_get_threshold_from_settings(sildet->silencelevel));
 	ast_audiohook_init(&sildet->audiohook, AST_AUDIOHOOK_TYPE_MANIPULATE, "Sildet");
 	sildet->audiohook.manipulate_callback = silence_detection_callback;
-	sildet->active = 0;
+	sildet->active = 1;
 	sildet->silencecounter = 0;
 	sildet->detect = 0;
 	datastore->data = sildet;
@@ -228,6 +238,7 @@
 	if (silenceframes < 3) {
 		ast_log(LOG_WARNING, "Silenceframes is set very low. Are you sure? Value=%d\n", silenceframes);
 	}
+	ast_debug(4, "----> Setting up silence detection/suppression with silence level %d and silence frames %d for chan %s\n", silencelevel, silenceframes, chan->name);
 
 	ast_channel_lock(chan);
 	ast_debug(4, "----> Looking for silence detection datastore for %s\n", chan->name);
@@ -253,14 +264,12 @@
 		return 0;
 	}
 	ast_debug(4, "----> Looking for silence detection datastore for %s\n", chan->name);
+	ast_dsp_set_threshold(sildet->dsp, silencelevel);
 	sildet->silencelevel = silencelevel;
 	sildet->silenceframes = silenceframes;
 	sildet->active = 1;
 	sildet->silencecounter = 0;
 	sildet->detect = 0;
-
-	/* Reset the DSP */
-	ast_dsp_set_threshold(sildet->dsp, ast_dsp_get_threshold_from_settings(sildet->silencelevel));
 
 	if (is_new) {
 		if (sildet_add_audiohook(chan, sildet, datastore)) {




More information about the asterisk-commits mailing list