[svn-commits] dvossel: branch dvossel/hd_confbridge r310586 - /team/dvossel/hd_confbridge/b...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Mar 14 09:31:24 CDT 2011


Author: dvossel
Date: Mon Mar 14 09:31:20 2011
New Revision: 310586

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=310586
Log:
Places the softmix silence detection outside of the mixing thread

Modified:
    team/dvossel/hd_confbridge/bridges/bridge_softmix.c

Modified: team/dvossel/hd_confbridge/bridges/bridge_softmix.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/hd_confbridge/bridges/bridge_softmix.c?view=diff&rev=310586&r1=310585&r2=310586
==============================================================================
--- team/dvossel/hd_confbridge/bridges/bridge_softmix.c (original)
+++ team/dvossel/hd_confbridge/bridges/bridge_softmix.c Mon Mar 14 09:31:20 2011
@@ -65,7 +65,7 @@
 
 /* This is the threshold in ms at which a channel's own audio will stop getting
  * mixed out its own write audio stream because it is not talking. */
-#define SILENCE_THRESHOLD 4000
+#define SILENCE_THRESHOLD 2500
 
 /*! \brief Structure which contains per-channel mixing information */
 struct softmix_channel {
@@ -79,8 +79,9 @@
 	struct ast_frame read_frame;
 	/*! DSP for detecting silence */
 	struct ast_dsp *dsp;
-	/*! The total amount of silence up until the last audio frame */
-	int totalsilence;
+	/*! Bit used to indicate if a channel is talking or not. This affects how
+	 * the channel's audio is mixed back to it. */
+	int talking:1;
 	/*! Bit used to indicate that the channel provided audio for this mixing interval */
 	int have_audio:1;
 	/*! Bit used to indicate that a frame is available to be written out to the channel */
@@ -195,17 +196,12 @@
  */
 static int16_t *softmix_process_read_audio(struct softmix_channel *sc, unsigned int num_samples)
 {
-	sc->have_audio = 0;
 	if ((ast_slinfactory_available(&sc->factory) >= num_samples) &&
 		ast_slinfactory_read(&sc->factory, sc->our_buf, num_samples)) {
-		sc->totalsilence = 0;
-		ast_dsp_silence(sc->dsp, &sc->read_frame, &sc->totalsilence);
-		if (sc->totalsilence < SILENCE_THRESHOLD) {
-			sc->have_audio = 1; /* tell the write process we have audio to be mixed out */
-		}
-		ast_mutex_unlock(&sc->lock);
+		sc->have_audio = 1;
 		return sc->our_buf;
 	}
+	sc->have_audio = 0;
 	return NULL;
 }
 
@@ -226,7 +222,7 @@
 
 	/* If we provided audio that was not determined to be silence,
 	 * then take it out while in slinear format. */
-	if (sc->have_audio) {
+	if (sc->have_audio && sc->talking) {
 		for (i = 0; i < sc->write_frame.samples; i++) {
 			ast_slinear_saturated_subtract(&sc->final_buf[i], &sc->our_buf[i]);
 		}
@@ -343,6 +339,8 @@
 
 	/* set up new DSP */
 	sc->dsp = ast_dsp_new_with_rate(rate);
+	/* we want to aggressively detect silence to avoid feedback */
+	ast_dsp_set_threshold(sc->dsp, 160);
 
 	ast_mutex_unlock(&sc->lock);
 }
@@ -399,6 +397,7 @@
 {
 	struct softmix_channel *sc = bridge_channel->bridge_pvt;
 	struct softmix_bridge_data *bridge_data = bridge->bridge_pvt;
+	int totalsilence = 0;
 
 	/* Only accept audio frames, all others are unsupported */
 	if (frame->frametype != AST_FRAME_VOICE) {
@@ -406,6 +405,12 @@
 	}
 
 	ast_mutex_lock(&sc->lock);
+
+	sc->talking = 0;
+	ast_dsp_silence(sc->dsp, frame, &totalsilence);
+	if (totalsilence < SILENCE_THRESHOLD) {
+		sc->talking = 1; /* tell the write process we have audio to be mixed out */
+	}
 
 	/* Before adding audio in, make sure we haven't fallen behind. If audio has fallen
 	 * behind 4 times the amount of samples mixed on every iteration of the mixer, Re-sync




More information about the svn-commits mailing list