[asterisk-commits] russell: branch russell/jack r93170 - /team/russell/jack/apps/app_jack.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Dec 16 11:54:22 CST 2007


Author: russell
Date: Sun Dec 16 11:54:21 2007
New Revision: 93170

URL: http://svn.digium.com/view/asterisk?view=rev&rev=93170
Log:
Implement handle_input(), which handles audio from the jack input port.  It
resamples it if necessary, converts the sample values from float to short,
and writes it into a ringbuffer.  Add a stub for where the data from this
ringbuffer needs to get consumed.

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=93170&r1=93169&r2=93170
==============================================================================
--- team/russell/jack/apps/app_jack.c (original)
+++ team/russell/jack/apps/app_jack.c Sun Dec 16 11:54:21 2007
@@ -177,7 +177,50 @@
 static void handle_input(void *buf, jack_nframes_t nframes, 
 	struct jack_data *jack_data)
 {
-
+	short s_buf[nframes];
+	float *in_buf = buf;
+	size_t res;
+	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 * sizeof(float))) {
+			int res;
+
+			res = resample_process(jack_data->input_resampler,
+				jack_data->input_resample_factor,
+				&in_buf[in_buf_used / sizeof(in_buf[0])], (nframes * sizeof(float)) - in_buf_used,
+				0, &in_buf_used,
+				&f_buf[out_buf_used / sizeof(f_buf[0])], sizeof(f_buf) - out_buf_used);
+
+			if (res < 0)
+				break;
+
+			out_buf_used += res;
+	
+			if (out_buf_used == sizeof(f_buf)) {
+				ast_log(LOG_ERROR, "Output buffer filled ... need to increase its size\n");
+				break;
+			}
+		}
+
+		for (i = 0; i < nframes; i++)
+			s_buf[i] = f_buf[i] * (SHRT_MAX / FLT_MAX);
+	} else {
+		/* No resampling needed */
+
+		for (i = 0; i < nframes; i++)
+			s_buf[i] = in_buf[i] * (SHRT_MAX / FLT_MAX);
+	}
+
+	res = jack_ringbuffer_write(jack_data->input_rb, (const char *) s_buf, sizeof(s_buf));
+	if (res != sizeof(s_buf)) {
+		ast_log(LOG_WARNING, "Tried to write %d bytes to the ringbuffer, but only wrote %d\n",
+			sizeof(s_buf), res);
+	}
 }
 
 /*!
@@ -383,6 +426,18 @@
 	}
 
 	return 0;
+}
+
+/*!
+ * \brief handle jack audio
+ *
+ * Read data from the input ringbuffer, which is the properly resampled audio
+ * that was read from the jack input port.  Feed it through a smoother and write
+ * frames to the channel.
+ */
+static void handle_jack_audio(struct ast_channel *chan, struct jack_data *jack_data)
+{
+	/* XXX */
 }
 
 static int jack_exec(struct ast_channel *chan, void *data)
@@ -422,6 +477,8 @@
 		}
 
 		ast_frfree(f);
+
+		handle_jack_audio(chan, &jack_data);
 	}
 
 	destroy_jack_data(&jack_data);




More information about the asterisk-commits mailing list