[asterisk-commits] trunk r29018 - /trunk/codecs/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat May 20 06:37:11 MST 2006


Author: russell
Date: Sat May 20 08:37:11 2006
New Revision: 29018

URL: http://svn.digium.com/view/asterisk?rev=29018&view=rev
Log:
add some code optimizations, see the report for an explanation 
(issue #7105, Mithraen)

Modified:
    trunk/codecs/codec_a_mu.c
    trunk/codecs/codec_adpcm.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=29018&r1=29017&r2=29018&view=diff
==============================================================================
--- trunk/codecs/codec_a_mu.c (original)
+++ trunk/codecs/codec_a_mu.c Sat May 20 08:37:11 2006
@@ -55,12 +55,12 @@
 /*! \brief convert frame data and store into the buffer */
 static int alawtoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
-	int i;
+	int x = f->samples;
 	int in_samples = f->samples;
 	unsigned char *src = f->data;
 	unsigned char *dst = (unsigned char *)pvt->outbuf + pvt->samples;
 
-	for (i = 0; i < in_samples; i++)
+	while (x--)
 		*dst++ = a2mu[*src++];
 	pvt->samples += in_samples;
 	pvt->datalen += in_samples;
@@ -70,12 +70,12 @@
 /*! \brief convert frame data and store into the buffer */
 static int ulawtoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
-	int i;
+	int x = f->samples;
 	int in_samples = f->samples;
 	unsigned char *src = f->data;
 	unsigned char *dst = (unsigned char *)pvt->outbuf + pvt->samples;
 
-	for (i = 0; i < in_samples; i++)
+	while (x--)
 		*dst++ = mu2a[*src++];
 	pvt->samples += in_samples;
 	pvt->datalen += in_samples;

Modified: trunk/codecs/codec_adpcm.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_adpcm.c?rev=29018&r1=29017&r2=29018&view=diff
==============================================================================
--- trunk/codecs/codec_adpcm.c (original)
+++ trunk/codecs/codec_adpcm.c Sat May 20 08:37:11 2006
@@ -239,13 +239,13 @@
 static int adpcmtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
 	struct adpcm_decoder_pvt *tmp = pvt->pvt;
-	int x;
+	int x = f->datalen;
 	unsigned char *src = f->data;
 	int16_t *dst = (int16_t *)pvt->outbuf + pvt->samples;
 
-	for (x=0; x < f->datalen; x++) {
-		*dst++ = decode((src[x] >> 4) & 0xf, &tmp->state);
-		*dst++ = decode(src[x] & 0x0f, &tmp->state);
+	while (x--) {
+		*dst++ = decode((*src >> 4) & 0xf, &tmp->state);
+		*dst++ = decode(*src++ & 0x0f, &tmp->state);
 	}
 	pvt->samples += f->samples;
 	pvt->datalen += 2*f->samples;

Modified: trunk/codecs/codec_alaw.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_alaw.c?rev=29018&r1=29017&r2=29018&view=diff
==============================================================================
--- trunk/codecs/codec_alaw.c (original)
+++ trunk/codecs/codec_alaw.c Sat May 20 08:37:11 2006
@@ -54,30 +54,30 @@
 /*! \brief decode frame into lin and fill output buffer. */
 static int alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
-	int i;
+	int i = f->samples;
 	unsigned char *src = f->data;
-	int16_t *dst = (int16_t *)pvt->outbuf;
+	int16_t *dst = (int16_t *)pvt->outbuf + pvt->samples;
 	int in_samples = f->samples;
-	int out_samples = pvt->samples;
 	
-	for (i = 0; i < in_samples; i++)
-		dst[out_samples++] = AST_ALAW(src[i]);
+	while (i--)
+		*dst++ = AST_ALAW(*src++);
 
-	pvt->samples = out_samples;
-	pvt->datalen += in_samples * 2;	/* 2 bytes/sample */
+	pvt->samples += f->samples;
+	pvt->datalen += f->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 i;
+	int i = f->samples;
 	char *dst = pvt->outbuf + pvt->samples;
 	int16_t *src = f->data;
 	int in_samples = f->samples;
 
-	for (i = 0; i < in_samples; i++) 
-		*dst++ = AST_LIN2A(src[i]);
+	while (i--) 
+		*dst++ = AST_LIN2A(*src++);
+
 	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=29018&r1=29017&r2=29018&view=diff
==============================================================================
--- trunk/codecs/codec_ulaw.c (original)
+++ trunk/codecs/codec_ulaw.c Sat May 20 08:37:11 2006
@@ -54,17 +54,17 @@
 /*! \brief convert and store samples in outbuf */
 static int ulawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
-	int i;
+	int i = f->samples;
 	unsigned char *src = f->data;
-	int16_t *dst = (int16_t *)pvt->outbuf;
+	int16_t *dst = (int16_t *)pvt->outbuf + pvt->samples;
 	int in_samples = f->samples;
 	int out_samples = pvt->samples;
 
 	/* convert and copy in outbuf */
-	for (i = 0; i < in_samples; i++)
-		dst[out_samples++] = AST_MULAW(src[i]);
-
-	pvt->samples = out_samples;
+	while (i--)
+		*dst++ = AST_MULAW(*src++);
+
+	pvt->samples += in_samples;
 	pvt->datalen += in_samples * 2;	/* 2 bytes/sample */
 	return 0;
 }
@@ -72,13 +72,14 @@
 /*! \brief convert and store samples in outbuf */
 static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
-	int i;
+	int i = f->samples;
 	char *dst = pvt->outbuf + pvt->samples;
 	int16_t *src = f->data;
 	int in_samples = f->samples;
 
-	for (i = 0; i < in_samples; i++) 
-		*dst++ = AST_LIN2MU(src[i]);
+	while (i--)
+		*dst++ = AST_LIN2MU(*src++);
+
 	pvt->samples += in_samples;
 	pvt->datalen += in_samples;	/* 1 byte/sample */
 	return 0;



More information about the asterisk-commits mailing list