[asterisk-addons-commits] tilghman: branch tilghman/app_speak_1.4 r435 - /team/tilghman/app_speak_1.4/

SVN commits to the Asterisk addons project asterisk-addons-commits at lists.digium.com
Sun Aug 26 00:50:41 CDT 2007


Author: tilghman
Date: Sun Aug 26 00:50:39 2007
New Revision: 435

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=435
Log:
Suggested change from Russell

Modified:
    team/tilghman/app_speak_1.4/app_speak.c

Modified: team/tilghman/app_speak_1.4/app_speak.c
URL: http://svn.digium.com/view/asterisk-addons/team/tilghman/app_speak_1.4/app_speak.c?view=diff&rev=435&r1=434&r2=435
==============================================================================
--- team/tilghman/app_speak_1.4/app_speak.c (original)
+++ team/tilghman/app_speak_1.4/app_speak.c Sun Aug 26 00:50:39 2007
@@ -63,6 +63,10 @@
 "plays that audio back to the channel.  When DTMF is detected on the channel,\n"
 "SpeakUntilExten pauses and waits for a complete new extension to be entered.\n";
 
+/* This is an ugly hack to get around the fact that certain Cepstral libraries
+ * seem to be broken on this platform.  This module is also loaded with global
+ * symbols for this reason.
+ */
 typedef struct cst_item_contents_struct cst_item_contents;
 typedef struct cst_relation_struct cst_relation;
 typedef struct cst_item_struct cst_item;
@@ -87,7 +91,6 @@
 {
     return ( r == NULL ? NULL : r->head);
 }
-
 typedef struct cst_regex_struct {
     char regstart;		/* Internal use only. */
     char reganch;		/* Internal use only. */
@@ -114,6 +117,7 @@
 };
 const cst_regex *cst_rx_int = &cst_rx_int_rx;
 
+
 struct callback_data {
 	/* Raw buffer */
 	int buflen;
@@ -124,6 +128,10 @@
 	/* Cepstral pointers */
 	swift_port *port;
 	void *tid;
+	/* Frame */
+	struct ast_frame fr;
+	char unused[AST_FRIENDLY_OFFSET];
+	short frdata[100];
 	/* Flag for which DTMF digit was pressed */
 	int dtmf;
 	/* Flag for cancelling on DTMF */
@@ -137,37 +145,24 @@
 	int multiplier = cbd->voice_rate / 8000;
 	struct ast_frame *f;
 	int ms;
-	/* Frame */
-	struct ast_frame fr = {
-		.frametype = AST_FRAME_VOICE,
-		.subclass = AST_FORMAT_SLINEAR,
-		.datalen = 200,
-		.samples = 100,
-		.offset = AST_FRIENDLY_OFFSET,
-		.src = __PRETTY_FUNCTION__
-	};
-	char __attribute__((unused)) unused[AST_FRIENDLY_OFFSET] = "";
-	short frdata[100];
-
-	fr.data = frdata;
 
 	for (starting_sample = (void *)cbd->buf;
-		 (void *)starting_sample < (void *)cbd->buf + cbd->buflen - sizeof(frdata) * multiplier;
-		 starting_sample += sizeof(frdata) * multiplier) {
+		 (void *)starting_sample < (void *)cbd->buf + cbd->buflen - sizeof(cbd->frdata) * multiplier;
+		 starting_sample += sizeof(cbd->frdata) * multiplier) {
 		if (multiplier == 1) {
-			memcpy(frdata, starting_sample, sizeof(frdata));
-			unconsumed = (void *)starting_sample + sizeof(frdata);
+			memcpy(cbd->frdata, starting_sample, sizeof(cbd->frdata));
+			unconsumed = (void *)starting_sample + sizeof(cbd->frdata);
 		} else {
 			int offset = 0;
 			for (sample = starting_sample;
-				 (void *)sample < (void *)starting_sample + sizeof(frdata) * multiplier;
+				 (void *)sample < (void *)starting_sample + sizeof(cbd->frdata) * multiplier;
 				 sample += multiplier)
-				frdata[offset++] = *sample;
+				cbd->frdata[offset++] = *sample;
 			unconsumed = sample;
 		}
 
 		/* Write the frame */
-		if (ast_write(cbd->chan, &fr) < 0)
+		if (ast_write(cbd->chan, &cbd->fr) < 0)
 			break;
 
 		/* Wait for this sample to complete */
@@ -198,23 +193,23 @@
 
 	if (final) {
 		/* Queue any remaining data in the buffer */
-		fr.datalen = ((void *)cbd->buf + cbd->buflen - unconsumed) / multiplier;
-		fr.samples = fr.datalen / 2;
+		cbd->fr.datalen = ((void *)cbd->buf + cbd->buflen - unconsumed) / multiplier;
+		cbd->fr.samples = cbd->fr.datalen / 2;
 
 		if (multiplier == 1)
-			memcpy(frdata, unconsumed, fr.datalen);
+			memcpy(cbd->frdata, unconsumed, cbd->fr.datalen);
 		else {
 			int offset = 0;
 			for (sample = unconsumed;
-				 (void *)sample < unconsumed + fr.datalen * multiplier;
+				 (void *)sample < unconsumed + cbd->fr.datalen * multiplier;
 				 sample += multiplier)
-				frdata[offset++] = *sample;
-		}
-
-		unconsumed += fr.datalen * multiplier;
+				cbd->frdata[offset++] = *sample;
+		}
+
+		unconsumed += cbd->fr.datalen * multiplier;
 
 		/* Write the last frame */
-		ast_write(cbd->chan, &fr);
+		ast_write(cbd->chan, &cbd->fr);
 	}
 
 	/* Update buffer pointers */
@@ -285,7 +280,14 @@
 	struct callback_data cbd = {
 		.chan = chan,
 		.wantdtmf = wantdtmf ? 1 : 0,
+		.fr.frametype = AST_FRAME_VOICE,
+		.fr.subclass = AST_FORMAT_SLINEAR,
+		.fr.datalen = 200,
+		.fr.samples = 100,
+		.fr.offset = AST_FRIENDLY_OFFSET,
+		.fr.src = __PRETTY_FUNCTION__,
 	};
+	cbd.fr.data = cbd.frdata;
 
 	if (!data)
 		return 0;




More information about the asterisk-addons-commits mailing list