[asterisk-commits] trunk r25059 - in /trunk/codecs: codec_a_mu.c codec_alaw.c codec_ulaw.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon May 8 04:11:07 MST 2006


Author: russell
Date: Fri May  5 16:36:17 2006
New Revision: 25059

URL: http://svn.digium.com/view/asterisk?rev=25059&view=rev
Log:
minor code optimizations to reduce the number of times that the ast_frame
and ast_trans_pvt pointers have to be dereferenced (issue #7069, Mithraen)

Modified:
    trunk/codecs/codec_a_mu.c
    trunk/codecs/codec_alaw.c
    trunk/codecs/codec_ulaw.c

Modified: trunk/codecs/codec_a_mu.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_a_mu.c?rev=25059&r1=25058&r2=25059&view=diff
==============================================================================
--- trunk/codecs/codec_a_mu.c (original)
+++ trunk/codecs/codec_a_mu.c Fri May  5 16:36:17 2006
@@ -55,28 +55,30 @@
 /*! \brief convert frame data and store into the buffer */
 static int alawtoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
-	int x;
+	int i;
+	int in_samples = f->samples;
 	unsigned char *src = f->data;
 	unsigned char *dst = (unsigned char *)pvt->outbuf + pvt->samples;
 
-	for ( x = 0 ; x < f->samples; x++)
-		dst[x] = a2mu[src[x]];
-	pvt->samples += f->samples;
-	pvt->datalen += f->datalen;
+	for (i = 0; i < in_samples; i++)
+		*dst++ = a2mu[*src++];
+	pvt->samples += in_samples;
+	pvt->datalen += in_samples;
 	return 0;
 }
 
 /*! \brief convert frame data and store into the buffer */
 static int ulawtoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
-	int x;
+	int i;
+	int in_samples = f->samples;
 	unsigned char *src = f->data;
 	unsigned char *dst = (unsigned char *)pvt->outbuf + pvt->samples;
 
-	for ( x = 0 ; x < f->samples; x++)
-		dst[x] = mu2a[src[x]];
-	pvt->samples += f->samples;
-	pvt->datalen += f->datalen;
+	for (i = 0; i < in_samples; i++)
+		*dst++ = mu2a[*src++];
+	pvt->samples += in_samples;
+	pvt->datalen += in_samples;
 	return 0;
 }
 

Modified: trunk/codecs/codec_alaw.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_alaw.c?rev=25059&r1=25058&r2=25059&view=diff
==============================================================================
--- trunk/codecs/codec_alaw.c (original)
+++ trunk/codecs/codec_alaw.c Fri May  5 16:36:17 2006
@@ -57,25 +57,29 @@
 	int i;
 	unsigned char *src = f->data;
 	int16_t *dst = (int16_t *)pvt->outbuf;
+	int in_samples = f->samples;
+	int out_samples = pvt->samples;
+	
+	for (i = 0; i < in_samples; i++)
+		dst[out_samples++] = AST_ALAW(src[i]);
 
-	for ( i = 0; i < f->samples; i++)
-		dst[pvt->samples + i] = AST_ALAW(src[i]);
-	pvt->samples += f->samples;
-	pvt->datalen += 2*f->samples;	/* 2 bytes/sample */
+	pvt->samples = out_samples;
+	pvt->datalen += in_samples * 2;	/* 2 bytes/sample */
 	return 0;
 }
 
 /*! \brief convert and store input samples in output buffer */
 static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
-	int x;
+	int i;
 	char *dst = pvt->outbuf + pvt->samples;
 	int16_t *src = f->data;
+	int in_samples = f->samples;
 
-	for ( x = 0; x < f->samples; x++) 
-		*dst++ = AST_LIN2A(src[x]);
-	pvt->samples += f->samples;
-	pvt->datalen += f->samples;	/* 1 byte/sample */
+	for (i = 0; i < in_samples; i++) 
+		*dst++ = AST_LIN2A(src[i]);
+	pvt->samples += in_samples;
+	pvt->datalen += in_samples;	/* 1 byte/sample */
 	return 0;
 }
 

Modified: trunk/codecs/codec_ulaw.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_ulaw.c?rev=25059&r1=25058&r2=25059&view=diff
==============================================================================
--- trunk/codecs/codec_ulaw.c (original)
+++ trunk/codecs/codec_ulaw.c Fri May  5 16:36:17 2006
@@ -57,13 +57,15 @@
 	int i;
 	unsigned char *src = f->data;
 	int16_t *dst = (int16_t *)pvt->outbuf;
+	int in_samples = f->samples;
+	int out_samples = pvt->samples;
 
 	/* convert and copy in outbuf */
-	for (i=0;  i<f->samples; i++)
-		dst[pvt->samples + i] = AST_MULAW(src[i]);
-
-	pvt->samples += f->samples;
-	pvt->datalen += 2 * f->samples;
+	for (i = 0; i < in_samples; i++)
+		dst[out_samples++] = AST_MULAW(src[i]);
+
+	pvt->samples = out_samples;
+	pvt->datalen += in_samples * 2;	/* 2 bytes/sample */
 	return 0;
 }
 
@@ -71,12 +73,14 @@
 static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
 	int i;
+	char *dst = pvt->outbuf + pvt->samples;
 	int16_t *src = f->data;
-
-	for (i=0 ; i < f->samples; i++) 
-		pvt->outbuf[pvt->samples + i] = AST_LIN2MU(src[i]);
-	pvt->samples += f->samples;
-	pvt->datalen += f->samples;	/* 1 byte/sample */
+	int in_samples = f->samples;
+
+	for (i = 0; i < in_samples; i++) 
+		*dst++ = AST_LIN2MU(src[i]);
+	pvt->samples += in_samples;
+	pvt->datalen += in_samples;	/* 1 byte/sample */
 	return 0;
 }
 
@@ -147,7 +151,7 @@
 {
 	struct ast_variable *var;
 	struct ast_config *cfg = ast_config_load("codecs.conf");
-	if (cfg == NULL)
+	if (!cfg)
 		return;
 	for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
 		if (!strcasecmp(var->name, "genericplc")) {



More information about the asterisk-commits mailing list