[asterisk-commits] markster: trunk r39886 - /trunk/channel.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Aug 15 13:25:13 MST 2006


Author: markster
Date: Tue Aug 15 15:25:13 2006
New Revision: 39886

URL: http://svn.digium.com/view/asterisk?rev=39886&view=rev
Log:
Make tonepair generated through fixed point

Modified:
    trunk/channel.c

Modified: trunk/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/channel.c?rev=39886&r1=39885&r2=39886&view=diff
==============================================================================
--- trunk/channel.c (original)
+++ trunk/channel.c Tue Aug 15 15:25:13 2006
@@ -3807,12 +3807,18 @@
 };
 
 struct tonepair_state {
-	float freq1;
-	float freq2;
-	float vol;
+	int fac1;
+	int fac2;
+	int v1_1;
+	int v2_1;
+	int v3_1;
+	int v1_2;
+	int v2_2;
+	int v3_2;
+	int origwfmt;
+	int pos;
 	int duration;
-	int pos;
-	int origwfmt;
+	int modulate;
 	struct ast_frame f;
 	unsigned char offset[AST_FRIENDLY_OFFSET];
 	short data[4000];
@@ -3840,10 +3846,16 @@
 		tonepair_release(NULL, ts);
 		ts = NULL;
 	} else {
-		ts->freq1 = td->freq1;
-		ts->freq2 = td->freq2;
+		ts->fac1 = 2.0 * cos(2.0 * M_PI * (td->freq1 / 8000.0)) * 32768.0;
+		ts->v1_1 = 0;
+		ts->v2_1 = sin(-4.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
+		ts->v3_1 = sin(-2.0 * M_PI * (td->freq1 / 8000.0)) * td->vol;
+		ts->v2_1 = 0;
+		ts->fac2 = 2.0 * cos(2.0 * M_PI * (td->freq2 / 8000.0)) * 32768.0;
+		ts->v2_2 = sin(-4.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
+		ts->v3_2 = sin(-2.0 * M_PI * (td->freq2 / 8000.0)) * td->vol;
 		ts->duration = td->duration;
-		ts->vol = td->vol;
+		ts->modulate = 0;
 	}
 	/* Let interrupts interrupt :) */
 	ast_set_flag(chan, AST_FLAG_WRITE_INT);
@@ -3865,12 +3877,23 @@
 		return -1;
 	}
 	memset(&ts->f, 0, sizeof(ts->f));
-	for (x = 0; x < (len / 2); x++) {
-		ts->data[x] = ts->vol * (
-				sin((ts->freq1 * 2.0 * M_PI / 8000.0) * (ts->pos + x)) +
-				sin((ts->freq2 * 2.0 * M_PI / 8000.0) * (ts->pos + x))
-			);
-	}
+ 	for (x=0;x<len/2;x++) {
+ 		ts->v1_1 = ts->v2_1;
+ 		ts->v2_1 = ts->v3_1;
+ 		ts->v3_1 = (ts->fac1 * ts->v2_1 >> 15) - ts->v1_1;
+ 		
+ 		ts->v1_2 = ts->v2_2;
+ 		ts->v2_2 = ts->v3_2;
+ 		ts->v3_2 = (ts->fac2 * ts->v2_2 >> 15) - ts->v1_2;
+ 		if (ts->modulate) {
+ 			int p;
+ 			p = ts->v3_2 - 32768;
+ 			if (p < 0) p = -p;
+ 			p = ((p * 9) / 10) + 1;
+ 			ts->data[x] = (ts->v3_1 * p) >> 15;
+ 		} else
+ 			ts->data[x] = ts->v3_1 + ts->v3_2; 
+ 	}
 	ts->f.frametype = AST_FRAME_VOICE;
 	ts->f.subclass = AST_FORMAT_SLINEAR;
 	ts->f.datalen = len;



More information about the asterisk-commits mailing list