Module Name: src Committed By: isaki Date: Wed Aug 2 10:10:10 UTC 2017
Modified Files: src/sys/dev/ic: msm6258.c Log Message: Use endian conversion macros (and some rearrange for readability). No functional changes. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/sys/dev/ic/msm6258.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ic/msm6258.c diff -u src/sys/dev/ic/msm6258.c:1.20 src/sys/dev/ic/msm6258.c:1.21 --- src/sys/dev/ic/msm6258.c:1.20 Sun Jul 30 05:51:34 2017 +++ src/sys/dev/ic/msm6258.c Wed Aug 2 10:10:10 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: msm6258.c,v 1.20 2017/07/30 05:51:34 isaki Exp $ */ +/* $NetBSD: msm6258.c,v 1.21 2017/08/02 10:10:10 isaki Exp $ */ /* * Copyright (c) 2001 Tetsuya Isaki. All rights reserved. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: msm6258.c,v 1.20 2017/07/30 05:51:34 isaki Exp $"); +__KERNEL_RCSID(0, "$NetBSD: msm6258.c,v 1.21 2017/08/02 10:10:10 isaki Exp $"); #include <sys/systm.h> #include <sys/device.h> @@ -167,41 +167,27 @@ DEFINE_FILTER(msm6258_slinear16_to_adpcm while (dst->used < m && this->src->used >= 4) { uint8_t f; int16_t ss; -#if BYTE_ORDER == LITTLE_ENDIAN - ss = *(const int16_t*)s; - s = audio_stream_add_outp(this->src, s, 2); + ss = le16toh(*(const int16_t*)s); f = pcm2adpcm_step(mc, ss); - ss = *(const int16_t*)s; -#else - ss = (s[1] << 8) | s[0]; s = audio_stream_add_outp(this->src, s, 2); - f = pcm2adpcm_step(mc, ss); - ss = (s[1] << 8) | s[0]; -#endif + ss = le16toh(*(const int16_t*)s); f |= pcm2adpcm_step(mc, ss) << 4; + s = audio_stream_add_outp(this->src, s, 2); *d = f; d = audio_stream_add_inp(dst, d, 1); - s = audio_stream_add_outp(this->src, s, 2); } } else if (enc_src == AUDIO_ENCODING_SLINEAR_BE) { while (dst->used < m && this->src->used >= 4) { uint8_t f; int16_t ss; -#if BYTE_ORDER == BIG_ENDIAN - ss = *(const int16_t*)s; + ss = be16toh(*(const int16_t*)s); s = audio_stream_add_outp(this->src, s, 2); f = pcm2adpcm_step(mc, ss); - ss = *(const int16_t*)s; -#else - ss = (s[0] << 8) | s[1]; + ss = be16toh(*(const int16_t*)s); s = audio_stream_add_outp(this->src, s, 2); - f = pcm2adpcm_step(mc, ss); - ss = (s[0] << 8) | s[1]; -#endif f |= pcm2adpcm_step(mc, ss) << 4; *d = f; d = audio_stream_add_inp(dst, d, 1); - s = audio_stream_add_outp(this->src, s, 2); } } else { #if defined(DIAGNOSTIC) @@ -246,10 +232,10 @@ DEFINE_FILTER(msm6258_linear8_to_adpcm) s = audio_stream_add_outp(this->src, s, 1); f = pcm2adpcm_step(mc, ss); ss = ((int16_t)s[0]) * 256; + s = audio_stream_add_outp(this->src, s, 1); f |= pcm2adpcm_step(mc, ss) << 4; *d = f; d = audio_stream_add_inp(dst, d, 1); - s = audio_stream_add_outp(this->src, s, 1); } } else if (enc_src == AUDIO_ENCODING_ULINEAR_LE || enc_src == AUDIO_ENCODING_ULINEAR_BE) { @@ -260,10 +246,10 @@ DEFINE_FILTER(msm6258_linear8_to_adpcm) s = audio_stream_add_outp(this->src, s, 1); f = pcm2adpcm_step(mc, ss); ss = ((int16_t)(s[0] ^ 0x80)) * 256; + s = audio_stream_add_outp(this->src, s, 1); f |= pcm2adpcm_step(mc, ss) << 4; *d = f; d = audio_stream_add_inp(dst, d, 1); - s = audio_stream_add_outp(this->src, s, 1); } } else { #if defined(DIAGNOSTIC) @@ -328,17 +314,9 @@ DEFINE_FILTER(msm6258_adpcm_to_slinear16 a = s[0]; s1 = adpcm2pcm_step(mc, a & 0x0f); s2 = adpcm2pcm_step(mc, a >> 4); -#if BYTE_ORDER == LITTLE_ENDIAN - *(int16_t*)d = s1; + *(int16_t*)d = htole16(s1); d = audio_stream_add_inp(dst, d, 2); - *(int16_t*)d = s2; -#else - d[0] = s1; - d[1] = s1 >> 8; - d = audio_stream_add_inp(dst, d, 2); - d[0] = s2; - d[1] = s2 >> 8; -#endif + *(int16_t*)d = htole16(s2); d = audio_stream_add_inp(dst, d, 2); s = audio_stream_add_outp(this->src, s, 1); } @@ -349,17 +327,9 @@ DEFINE_FILTER(msm6258_adpcm_to_slinear16 a = s[0]; s1 = adpcm2pcm_step(mc, a & 0x0f); s2 = adpcm2pcm_step(mc, a >> 4); -#if BYTE_ORDER == BIG_ENDIAN - *(int16_t*)d = s1; - d = audio_stream_add_inp(dst, d, 2); - *(int16_t*)d = s2; -#else - d[1] = s1; - d[0] = s1 >> 8; + *(int16_t*)d = htobe16(s1); d = audio_stream_add_inp(dst, d, 2); - d[1] = s2; - d[0] = s2 >> 8; -#endif + *(int16_t*)d = htobe16(s2); d = audio_stream_add_inp(dst, d, 2); s = audio_stream_add_outp(this->src, s, 1); } @@ -404,26 +374,26 @@ DEFINE_FILTER(msm6258_adpcm_to_linear8) uint8_t a; int16_t s1, s2; a = s[0]; + s = audio_stream_add_outp(this->src, s, 1); s1 = adpcm2pcm_step(mc, a & 0x0f); s2 = adpcm2pcm_step(mc, a >> 4); d[0] = s1 / 266; d = audio_stream_add_inp(dst, d, 1); d[0] = s2 / 266; d = audio_stream_add_inp(dst, d, 1); - s = audio_stream_add_outp(this->src, s, 1); } } else if (enc_dst == AUDIO_ENCODING_ULINEAR_LE) { while (dst->used < m && this->src->used >= 1) { uint8_t a; int16_t s1, s2; a = s[0]; + s = audio_stream_add_outp(this->src, s, 1); s1 = adpcm2pcm_step(mc, a & 0x0f); s2 = adpcm2pcm_step(mc, a >> 4); d[0] = (s1 / 266) ^ 0x80; d = audio_stream_add_inp(dst, d, 1); d[0] = (s2 / 266) ^ 0x80; d = audio_stream_add_inp(dst, d, 1); - s = audio_stream_add_outp(this->src, s, 1); } } else { #if defined(DIAGNOSTIC)