[svn-commits] russell: branch russell/jack r94395 - /team/russell/jack/apps/app_jack.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Dec 20 18:58:18 CST 2007


Author: russell
Date: Thu Dec 20 18:58:18 2007
New Revision: 94395

URL: http://svn.digium.com/view/asterisk?view=rev&rev=94395
Log:
Fix this application for the case when jackd is not running in 8 kHz mode.
This module now properly uses libresample to resample the audio going to and
coming from jack to the proper sample rates.  yay

Modified:
    team/russell/jack/apps/app_jack.c

Modified: team/russell/jack/apps/app_jack.c
URL: http://svn.digium.com/view/asterisk/team/russell/jack/apps/app_jack.c?view=diff&rev=94395&r1=94394&r2=94395
==============================================================================
--- team/russell/jack/apps/app_jack.c (original)
+++ team/russell/jack/apps/app_jack.c Thu Dec 20 18:58:18 2007
@@ -186,32 +186,34 @@
 	int i;
 
 	if (jack_data->input_resampler) {
-		int in_buf_used = 0;
-		int out_buf_used = 0;
-		float f_buf[nframes];
-
-		while (in_buf_used < nframes) {
-			int res;
-
-			res = resample_process(jack_data->input_resampler,
+		int total_in_buf_used = 0;
+		int total_out_buf_used = 0;
+		float f_buf[nframes + 1];
+
+		while (total_in_buf_used < nframes) {
+			int in_buf_used;
+			int out_buf_used;
+
+			out_buf_used = resample_process(jack_data->input_resampler,
 				jack_data->input_resample_factor,
-				&in_buf[in_buf_used], nframes - in_buf_used,
+				&in_buf[total_in_buf_used], nframes - total_in_buf_used,
 				0, &in_buf_used,
 				&f_buf[out_buf_used], ARRAY_LEN(f_buf) - out_buf_used);
 
-			if (res < 0)
+			if (out_buf_used < 0)
 				break;
 
-			out_buf_used += res;
+			total_out_buf_used += out_buf_used;
+			total_in_buf_used += in_buf_used;
 	
-			if (out_buf_used == ARRAY_LEN(f_buf)) {
+			if (total_out_buf_used == ARRAY_LEN(f_buf)) {
 				ast_log(LOG_ERROR, "Output buffer filled ... need to increase its size, "
-					"nframes '%d', out_buf_used '%d'\n", nframes, out_buf_used);
+					"nframes '%d', total_out_buf_used '%d'\n", nframes, total_out_buf_used);
 				break;
 			}
 		}
 
-		for (i = 0; i < out_buf_used; i++)
+		for (i = 0; i < total_out_buf_used; i++)
 			s_buf[i] = f_buf[i] * (SHRT_MAX / FLT_MAX);
 	} else {
 		/* No resampling needed */
@@ -396,27 +398,29 @@
 
 	if (jack_data->output_resampler) {
 		float in_buf[f->samples];
-		int in_buf_used = 0;
-		int out_buf_used = 0;
+		int total_in_buf_used = 0;
+		int total_out_buf_used = 0;
 
 		memset(in_buf, 0, sizeof(in_buf));
 
 		for (i = 0; i < f->samples; i++)
 			in_buf[i] = s_buf[i] * (FLT_MAX / SHRT_MAX);
 
-		while (in_buf_used < ARRAY_LEN(in_buf)) {
-			int res;
-
-			res = resample_process(jack_data->output_resampler, 
+		while (total_in_buf_used < ARRAY_LEN(in_buf)) {
+			int in_buf_used;
+			int out_buf_used;
+
+			out_buf_used = resample_process(jack_data->output_resampler, 
 				jack_data->output_resample_factor,
-				&in_buf[in_buf_used], ARRAY_LEN(in_buf) - in_buf_used, 
+				&in_buf[total_in_buf_used], ARRAY_LEN(in_buf) - total_in_buf_used, 
 				0, &in_buf_used, 
-				&f_buf[out_buf_used], ARRAY_LEN(f_buf) - out_buf_used);
-
-			if (res < 0)
+				&f_buf[out_buf_used], ARRAY_LEN(f_buf) - total_out_buf_used);
+
+			if (out_buf_used < 0)
 				break;
 
-			out_buf_used += res;
+			total_out_buf_used += out_buf_used;
+			total_in_buf_used += in_buf_used;
 
 			if (out_buf_used == ARRAY_LEN(f_buf)) {
 				ast_log(LOG_ERROR, "Output buffer filled ... need to increase its size\n");
@@ -424,7 +428,7 @@
 			}
 		}
 
-		f_buf_used = out_buf_used;
+		f_buf_used = total_out_buf_used;
 		if (f_buf_used > ARRAY_LEN(f_buf))
 			f_buf_used = ARRAY_LEN(f_buf);
 	} else {




More information about the svn-commits mailing list