diff options
| author | isaki <isaki@NetBSD.org> | 2017-08-02 10:10:10 +0000 |
|---|---|---|
| committer | isaki <isaki@NetBSD.org> | 2017-08-02 10:10:10 +0000 |
| commit | fd7c2cbb4543b190079c8e40dd14f2c78ad2fc3a (patch) | |
| tree | ea670c64d8344378f871e7d28ded927a9f9f8ba6 /sys/dev/ic | |
| parent | 6b99f466074d24c23cb25cc508266712f23ab875 (diff) | |
Use endian conversion macros (and some rearrange for readability).
No functional changes.
Diffstat (limited to 'sys/dev/ic')
| -rw-r--r-- | sys/dev/ic/msm6258.c | 60 |
1 files changed, 15 insertions, 45 deletions
diff --git a/sys/dev/ic/msm6258.c b/sys/dev/ic/msm6258.c index f9388d13f0c..75048903fca 100644 --- a/sys/dev/ic/msm6258.c +++ b/sys/dev/ic/msm6258.c @@ -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) |
